add useBuiltIns option

This commit is contained in:
Henry Zhu
2016-12-02 00:03:13 -05:00
parent 457131f219
commit 60efc0dd10
5 changed files with 508 additions and 15 deletions

View File

@@ -0,0 +1,72 @@
// https://github.com/zloirock/core-js
/* eslint-disable quotes */
module.exports = {
// es2015
// core-js/fn/map
// "typed": "typed arrays", ?
// "typed/array-buffer": "typed arrays / ", ?
"typed/data-view": "typed arrays / DataView",
"typed/int8-array": "typed arrays / Int8Array",
"typed/uint8-array": "typed arrays / Uint8Array",
"typed/uint8-clamped-array": "typed arrays / Uint8ClampedArray",
"typed/int16-array": "typed arrays / Int16Array",
"typed/uint16-array": "typed arrays / Uint16Array",
"typed/int32-array": "typed arrays / Int32Array",
"typed/uint32-array": "typed arrays / Uint32Array",
"typed/float32-array": "typed arrays / Float32Array",
"typed/float64-array": "typed arrays / Float64Array",
"map": "Map",
"set": "Set",
"weak-map": "WeakMap",
"weak-set": "WeakSet",
// No polyfill for proxy
"reflect": "Reflect",
"reflect/apply": "Reflect / ",
"reflect/construct": "Reflect / Reflect.construct",
"reflect/define-property": "Reflect / Reflect.defineProperty",
"reflect/delete-property": "Reflect / Reflect.deleteProperty",
"reflect/get": "Reflect / Reflect.get",
"reflect/get-own-property-descriptor": "Reflect / Reflect.getOwnPropertyDescriptor",
"reflect/get-prototype-of": "Reflect / Reflect.getPrototypeOf",
"reflect/has": "Reflect / Reflect.has",
"reflect/is-extensible": "Reflect / Reflect.isExtensible",
"reflect/own-keys": "Reflect / Reflect.ownKeys",
"reflect/prevent-extensions": "Reflect / Reflect.preventExtensions",
"reflect/set": "Reflect / Reflect.set",
"reflect/set-prototype-of": "Reflect / Reflect.setPrototypeOf",
"promise": "Promise",
"symbol": "Symbol",
"symbol/for": "Symbol / global symbol registry",
"symbol/key-for": "Symbol / global symbol registry",
"symbol/has-instance": "well-known symbols / Symbol.hasInstance",
"symbol/is-concat-spreadable": "well-known symbols / Symbol.isConcatSpreadable",
"symbol/iterator": "well-known symbols / Symbol.iterator",
"symbol/match": "well-known symbols / Symbol.match",
"symbol/replace": "well-known symbols / Symbol.replace",
"symbol/search": "well-known symbols / Symbol.search",
"symbol/species": "well-known symbols / Symbol.species",
"symbol/split": "well-known symbols / Symbol.split",
"symbol/to-primitive": "well-known symbols / Symbol.toPrimitive",
"symbol/to-string-tag": "well-known symbols / Symbol.toStringTag",
"symbol/unscopables": "well-known symbols / Symbol.unscopables",
"object/assign": "Object static methods / Object.assign",
"object/is": "Object static methods / Object.is",
"object/get-own-property-symbols": "Object static methods / Object.getOwnPropertySymbols",
"object/set-prototype-of": "Object static methods / Object.setPrototypeOf",
"function/name": 'function "name" property',
"string/raw": "String static methods / String.raw",
"string/string/from-code-point": "String static methods / String.fromCodePoint",
// String.prototype methods
};

View File

@@ -0,0 +1,385 @@
{
"typed/data-view": {},
"typed/int8-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/uint8-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/uint8-clamped-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 6,
"node": 0.12,
"ios": 10
},
"typed/int16-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/uint16-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/int32-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/uint32-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/float32-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4,
"ios": 6
},
"typed/float64-array": {
"chrome": 5,
"opera": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
"ie": 10,
"android": 4.1,
"ios": 6
},
"map": {
"chrome": 51,
"opera": 38,
"safari": 10,
"node": 6.5,
"ios": 10
},
"set": {
"chrome": 51,
"opera": 38,
"safari": 10,
"node": 6.5,
"ios": 10
},
"weak-map": {
"chrome": 51,
"opera": 38,
"safari": 9,
"ios": 10
},
"weak-set": {
"chrome": 51,
"opera": 38,
"safari": 9,
"ios": 9
},
"reflect": {
"chrome": 49,
"opera": 36,
"edge": 13,
"firefox": 45,
"safari": 10,
"ios": 10
},
"reflect/apply": {},
"reflect/construct": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/define-property": {
"chrome": 49,
"opera": 36,
"edge": 13,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/delete-property": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/get": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/get-own-property-descriptor": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/get-prototype-of": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/has": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/is-extensible": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/own-keys": {},
"reflect/prevent-extensions": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/set": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"reflect/set-prototype-of": {
"chrome": 49,
"opera": 36,
"edge": 12,
"firefox": 42,
"safari": 10,
"ios": 10
},
"promise": {
"chrome": 51,
"opera": 38,
"edge": 13,
"firefox": 45,
"safari": 10,
"node": 6.5,
"ios": 10
},
"symbol": {
"chrome": 49,
"opera": 36,
"edge": 13,
"firefox": 36,
"safari": 10,
"ios": 10
},
"symbol/for": {
"chrome": 38,
"opera": 25,
"edge": 12,
"firefox": 36,
"safari": 9,
"node": 0.12,
"ios": 9
},
"symbol/key-for": {
"chrome": 38,
"opera": 25,
"edge": 12,
"firefox": 36,
"safari": 9,
"node": 0.12,
"ios": 9
},
"symbol/has-instance": {
"chrome": 51,
"opera": 38,
"firefox": 50,
"safari": 10,
"node": 6.5,
"ios": 10
},
"symbol/is-concat-spreadable": {
"chrome": 48,
"opera": 35,
"firefox": 48,
"safari": 10,
"ios": 10
},
"symbol/iterator": {},
"symbol/match": {
"chrome": 50,
"opera": 37,
"firefox": 49,
"safari": 10,
"node": 6,
"ios": 10
},
"symbol/replace": {
"chrome": 50,
"opera": 37,
"firefox": 49,
"safari": 10,
"node": 6,
"ios": 10
},
"symbol/search": {
"chrome": 50,
"opera": 37,
"firefox": 49,
"safari": 10,
"node": 6,
"ios": 10
},
"symbol/species": {},
"symbol/split": {
"chrome": 50,
"opera": 37,
"firefox": 49,
"safari": 10,
"node": 6,
"ios": 10
},
"symbol/to-primitive": {
"chrome": 47,
"opera": 34,
"firefox": 44,
"safari": 10,
"ios": 10
},
"symbol/to-string-tag": {
"chrome": 49,
"opera": 36,
"firefox": 51,
"safari": 10,
"ios": 10
},
"symbol/unscopables": {
"chrome": 38,
"opera": 25,
"edge": 12,
"firefox": 48,
"safari": 9,
"node": 0.12,
"ios": 9
},
"object/assign": {
"chrome": 45,
"opera": 32,
"edge": 12,
"firefox": 34,
"safari": 9,
"node": 4,
"ios": 9
},
"object/is": {
"chrome": 19,
"opera": 6,
"edge": 12,
"firefox": 22,
"safari": 9,
"node": 0.12,
"android": 4.1,
"ios": 9
},
"object/get-own-property-symbols": {
"chrome": 38,
"opera": 25,
"edge": 12,
"firefox": 36,
"safari": 9,
"node": 0.12,
"ios": 9
},
"object/set-prototype-of": {
"chrome": 34,
"opera": 21,
"firefox": 31,
"safari": 9,
"node": 0.12,
"ie": 11,
"ios": 9
},
"function/name": {
"chrome": 51,
"opera": 38,
"safari": 10,
"node": 6.5,
"ios": 10
},
"string/raw": {
"chrome": 41,
"opera": 28,
"edge": 12,
"firefox": 34,
"safari": 9,
"node": 4,
"ios": 9
},
"string/string/from-code-point": {
"chrome": 41,
"opera": 28,
"edge": 12,
"firefox": 29,
"safari": 9,
"node": 4,
"ios": 9
}
}

View File

@@ -4,6 +4,7 @@ const path = require("path");
const flatten = require("lodash/flatten");
const flattenDeep = require("lodash/flattenDeep");
const pluginFeatures = require("../data/pluginFeatures");
const builtInFeatures = require("../data/builtInFeatures");
const renameTests = (tests, getName) =>
tests.map((test) => Object.assign({}, test, { name: getName(test.name) }));
@@ -98,7 +99,7 @@ const getLowestImplementedVersion = ({ features }, env) => {
});
let envFiltered = envTests.filter((t) => t);
if (envTests.length > envFiltered.length) {
if (envTests.length > envFiltered.length || envTests.length === 0) {
// envTests.forEach((test, i) => {
// if (!test) {
// // print unsupported features
@@ -115,27 +116,47 @@ const getLowestImplementedVersion = ({ features }, env) => {
.reduce((a, b) => { return (a < b) ? b : a; });
};
const data = {};
for (const pluginName in pluginFeatures) {
const options = pluginFeatures[pluginName];
const plugin = {};
environments.forEach((env) => {
if (Array.isArray(options.features)) {
function generateData(features) {
let ret = {};
Object.keys(features).forEach((pluginName) => {
let options = features[pluginName];
if (!options.features) {
options = {
features: [options]
};
}
const plugin = {};
environments.forEach((env) => {
const version = getLowestImplementedVersion(options, env);
if (version !== null) {
plugin[env] = version;
}
}
// add opera
if (plugin.chrome) {
plugin.opera = plugin.chrome - 13;
}
// add opera
if (plugin.chrome) {
plugin.opera = plugin.chrome - 13;
if (plugin.chrome === 5) {
plugin.opera = 12;
}
}
});
ret[pluginName] = plugin;
});
data[pluginName] = plugin;
return ret;
}
fs.writeFileSync(
path.join(__dirname, "../data/plugins.json"),
JSON.stringify(data, null, 2) + "\n"
JSON.stringify(generateData(pluginFeatures), null, 2) + "\n"
);
fs.writeFileSync(
path.join(__dirname, "../data/builtIns.json"),
JSON.stringify(generateData(builtInFeatures), null, 2) + "\n"
);

View File

@@ -1,5 +1,6 @@
import pluginList from "../data/plugins.json";
import browserslist from "browserslist";
import transformPolyfillRequirePlugin from "./transformPolyfillRequirePlugin";
export const MODULE_TRANSFORMATIONS = {
"amd": "transform-es2015-modules-amd",
@@ -140,6 +141,7 @@ export default function buildPreset(context, opts = {}) {
const whitelist = validateWhitelistOption(opts.whitelist);
const targets = getTargets(opts.targets);
const debug = opts.debug;
const useBuiltIns = opts.useBuiltIns;
let transformations = Object.keys(pluginList)
.filter((pluginName) => isPluginRequired(targets, pluginList[pluginName]));
@@ -179,7 +181,8 @@ export default function buildPreset(context, opts = {}) {
return {
plugins: [
...modules,
...transformations
...transformations,
// useBuiltIns && transformPolyfillRequirePlugin
]
};
}

View File

@@ -0,0 +1,12 @@
export default function (babel) {
const { types: t } = babel;
return {
name: "ast-transform", // not required
visitor: {
Identifier(path) {
}
}
};
}