Merge branch 'master' into 2.0

This commit is contained in:
Brian Ng 2017-04-20 08:13:39 -05:00
commit 2b9b69dc32
20 changed files with 259 additions and 49 deletions

View File

@ -1,3 +1,4 @@
coverage
src src
test test
node_modules node_modules
@ -8,5 +9,6 @@ codecov.yml
yarn.lock yarn.lock
.nyc_output .nyc_output
.vscode .vscode
.eslintrc
babel-preset-env-*.tgz babel-preset-env-*.tgz
flow-typed flow-typed

View File

@ -1,5 +1,33 @@
# Changelog # Changelog
## v1.4.0 (2017-04-14)
### :rocket: New Feature
- Support `spec` option ([#98](https://github.com/babel/babel-preset-env/pull/98)) (@Kovensky)
Added an option to enable more spec compliant, but potentially slower, transformations for any plugins in this preset that support them.
- Bump compat-table for Edge 15 support ([#273](https://github.com/babel/babel-preset-env/pull/273)) (@existentialism)
We updated our mappings so that you can get native support for async/await and other goodies when targeting Edge 15!
### :bug: Bug Fix
- Add Android browser to name map ([#270](https://github.com/babel/babel-preset-env/pull/270)) (@existentialism)
Fixed a bug that was ignoring Android targets in browserslist queries (for example: "Android >= 4").
### :memo: Documentation
- Clarify note about loading polyfills only once ([#282](https://github.com/babel/babel-preset-env/pull/282)) (@darahak)
- Add a reminder about include/exclude options ([#275](https://github.com/babel/babel-preset-env/pull/275)) (@existentialism)
### :house: Internal
- Chore: reduce package size. ([#281](https://github.com/babel/babel-preset-env/pull/281)) (@evilebottnawi)
- Remove deprecated comment ([#271](https://github.com/babel/babel-preset-env/pull/271)) (@yavorsky)
## v1.3.3 (2017-04-07) ## v1.3.3 (2017-04-07)
### :bug: Bug Fix ### :bug: Bug Fix

View File

@ -130,6 +130,12 @@ To prevent these errors - specify the uglify option, which will enable all plugi
> NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of ES6 support, but it is not yet stable. You can follow its progress in [UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you require an alternative minifier which _does_ support ES6 syntax, we recommend using [Babili](https://github.com/babel/babili). > NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of ES6 support, but it is not yet stable. You can follow its progress in [UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you require an alternative minifier which _does_ support ES6 syntax, we recommend using [Babili](https://github.com/babel/babili).
### `spec`
`boolean`, defaults to `false`.
Enable more spec compliant, but potentially slower, transformations for any plugins in this preset that support them.
### `loose` ### `loose`
`boolean`, defaults to `false`. `boolean`, defaults to `false`.
@ -166,6 +172,8 @@ This option is useful if there is a bug in a native implementation, or a combina
For example, Node 4 supports native classes but not spread. If `super` is used with a spread argument, then the `transform-es2015-classes` transform needs to be `include`d, as it is not possible to transpile a spread with `super` otherwise. For example, Node 4 supports native classes but not spread. If `super` is used with a spread argument, then the `transform-es2015-classes` transform needs to be `include`d, as it is not possible to transpile a spread with `super` otherwise.
> NOTE: The `include` and `exclude` options _only_ work with the [plugins included with this preset](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js); so, for example, including `transform-do-expressions` or excluding `transform-function-bind` will throw errors. To use a plugin _not_ included with this preset, add them to your [config](https://babeljs.io/docs/usage/babelrc/) directly.
### `exclude` ### `exclude`
`Array<string>`, defaults to `[]`. `Array<string>`, defaults to `[]`.
@ -228,7 +236,9 @@ var b = new Map();
#### `useBuiltIns: 'entry'` #### `useBuiltIns: 'entry'`
> NOTE: Only use `require("babel-polyfill");` once in your whole app. One option is to create a single entry file that only contains the require statement. > NOTE: Only use `require("babel-polyfill");` once in your whole app.
> Multiple imports or requires of `babel-polyfill` will throw an error since it can cause global collisions and other issues that are hard to trace.
> We recommend creating a single entry file that only contains the `require` statement.
This option enables a new plugin that replaces the statement `import "babel-polyfill"` or `require("babel-polyfill")` with individual requires for `babel-polyfill` based on environment. This option enables a new plugin that replaces the statement `import "babel-polyfill"` or `require("babel-polyfill")` with individual requires for `babel-polyfill` based on environment.

View File

@ -211,6 +211,7 @@
}, },
"transform-async-to-generator": { "transform-async-to-generator": {
"chrome": "55", "chrome": "55",
"edge": "15",
"firefox": "52", "firefox": "52",
"safari": "10.1", "safari": "10.1",
"node": "7.6", "node": "7.6",

View File

@ -67,7 +67,7 @@
"babel-register": "7.0.0-alpha.8", "babel-register": "7.0.0-alpha.8",
"chai": "^3.5.0", "chai": "^3.5.0",
"codecov": "^2.0.1", "codecov": "^2.0.1",
"compat-table": "kangax/compat-table#c38f039b8ea7fadf347d3e300fec3611645e31e9", "compat-table": "kangax/compat-table#861954b6e13d3eaa1ba9ef1a016906c0fc1072db",
"electron-to-chromium": "^1.3.2", "electron-to-chromium": "^1.3.2",
"eslint": "^3.17.1", "eslint": "^3.17.1",
"eslint-config-babel": "^6.0.0", "eslint-config-babel": "^6.0.0",

View File

@ -9,12 +9,15 @@ export const logMessage = (message, context) => {
export const logPlugin = (plugin, targets, list, context) => { export const logPlugin = (plugin, targets, list, context) => {
const envList = list[plugin] || {}; const envList = list[plugin] || {};
const filteredList = Object.keys(targets).reduce((a, b) => { const filteredList = Object.keys(targets).reduce(
if (!envList[b] || semver.lt(targets[b], semverify(envList[b]))) { (a, b) => {
a[b] = prettifyVersion(targets[b]); if (!envList[b] || semver.lt(targets[b], semverify(envList[b]))) {
} a[b] = prettifyVersion(targets[b]);
return a; }
}, {}); return a;
},
{},
);
logMessage(`${plugin} ${JSON.stringify(filteredList)}`, context); logMessage(`${plugin} ${JSON.stringify(filteredList)}`, context);
}; };

View File

@ -108,7 +108,7 @@ const filterItems = (list, includes, excludes, targets, defaultItems) => {
export default function buildPreset(context, opts = {}) { export default function buildPreset(context, opts = {}) {
const validatedOptions = normalizeOptions(opts); const validatedOptions = normalizeOptions(opts);
const { debug, loose, moduleType, useBuiltIns } = validatedOptions; const { debug, loose, moduleType, spec, useBuiltIns } = validatedOptions;
const targets = getTargets(validatedOptions.targets); const targets = getTargets(validatedOptions.targets);
const include = transformIncludesAndExcludes(validatedOptions.include); const include = transformIncludesAndExcludes(validatedOptions.include);
@ -145,9 +145,10 @@ export default function buildPreset(context, opts = {}) {
]); ]);
} }
// NOTE: not giving spec here yet to avoid compatibility issues when
// babel-plugin-transform-es2015-modules-commonjs gets its spec mode
transformations.forEach(pluginName => transformations.forEach(pluginName =>
plugins.push([require(`babel-plugin-${pluginName}`), { loose }]), plugins.push([require(`babel-plugin-${pluginName}`), { spec, loose }]));
);
const regenerator = transformations.has("transform-regenerator"); const regenerator = transformations.has("transform-regenerator");
@ -180,8 +181,7 @@ export default function buildPreset(context, opts = {}) {
regenerator, regenerator,
onDebug: (polyfills, context) => { onDebug: (polyfills, context) => {
polyfills.forEach(polyfill => polyfills.forEach(polyfill =>
logPlugin(polyfill, polyfillTargets, builtInsList, context), logPlugin(polyfill, polyfillTargets, builtInsList, context));
);
}, },
}; };

View File

@ -43,18 +43,23 @@ export const checkDuplicateIncludeExcludes = (include = [], exclude = []) => {
); );
}; };
// TODO: Allow specifying plugins as either shortened or full name export const validateBoolOption = (name, value, defaultValue) => {
// babel-plugin-transform-es2015-classes if (typeof value === "undefined") {
// transform-es2015-classes value = defaultValue;
export const validateLooseOption = (looseOpt = false) => { }
invariant(
typeof looseOpt === "boolean",
"Invalid Option: The 'loose' option must be a boolean.",
);
return looseOpt; if (typeof value !== "boolean") {
throw new Error(`Preset env: '${name}' option must be a boolean.`);
}
return value;
}; };
export const validateLooseOption = looseOpt =>
validateBoolOption("loose", looseOpt, false);
export const validateSpecOption = specOpt =>
validateBoolOption("spec", specOpt, false);
export const validateModulesOption = (modulesOpt = "commonjs") => { export const validateModulesOption = (modulesOpt = "commonjs") => {
invariant( invariant(
modulesOpt === false || modulesOpt === false ||
@ -95,6 +100,7 @@ export default function normalizeOptions(opts) {
include: validateIncludesAndExcludes(opts.include, "include"), include: validateIncludesAndExcludes(opts.include, "include"),
loose: validateLooseOption(opts.loose), loose: validateLooseOption(opts.loose),
moduleType: validateModulesOption(opts.modules), moduleType: validateModulesOption(opts.modules),
spec: validateSpecOption(opts.spec),
targets: opts.targets, targets: opts.targets,
useBuiltIns: validateUseBuiltInsOption(opts.useBuiltIns), useBuiltIns: validateUseBuiltInsOption(opts.useBuiltIns),
}; };

View File

@ -9,6 +9,7 @@ export type Targets = {
}; };
const browserNameMap = { const browserNameMap = {
android: "android",
chrome: "chrome", chrome: "chrome",
edge: "edge", edge: "edge",
firefox: "firefox", firefox: "firefox",

View File

@ -16,15 +16,13 @@ export default function({ types: t }) {
} }
function isRequire(path) { function isRequire(path) {
return ( return t.isExpressionStatement(path.node) &&
t.isExpressionStatement(path.node) &&
t.isCallExpression(path.node.expression) && t.isCallExpression(path.node.expression) &&
t.isIdentifier(path.node.expression.callee) && t.isIdentifier(path.node.expression.callee) &&
path.node.expression.callee.name === "require" && path.node.expression.callee.name === "require" &&
path.node.expression.arguments.length === 1 && path.node.expression.arguments.length === 1 &&
t.isStringLiteral(path.node.expression.arguments[0]) && t.isStringLiteral(path.node.expression.arguments[0]) &&
isPolyfillSource(path.node.expression.arguments[0].value) isPolyfillSource(path.node.expression.arguments[0].value);
);
} }
function createImport(polyfill, requireType, core) { function createImport(polyfill, requireType, core) {

View File

@ -28,9 +28,8 @@ const modulePathMap = {
}; };
const getModulePath = module => { const getModulePath = module => {
return ( return modulePathMap[module] ||
modulePathMap[module] || `babel-polyfill/lib/core-js/modules/${module}` `babel-polyfill/lib/core-js/modules/${module}`;
);
}; };
export default function({ types: t }) { export default function({ types: t }) {
@ -64,15 +63,13 @@ export default function({ types: t }) {
} }
function isRequire(path) { function isRequire(path) {
return ( return t.isExpressionStatement(path.node) &&
t.isExpressionStatement(path.node) &&
t.isCallExpression(path.node.expression) && t.isCallExpression(path.node.expression) &&
t.isIdentifier(path.node.expression.callee) && t.isIdentifier(path.node.expression.callee) &&
path.node.expression.callee.name === "require" && path.node.expression.callee.name === "require" &&
path.node.expression.arguments.length === 1 && path.node.expression.arguments.length === 1 &&
t.isStringLiteral(path.node.expression.arguments[0]) && t.isStringLiteral(path.node.expression.arguments[0]) &&
isPolyfillSource(path.node.expression.arguments[0].value) isPolyfillSource(path.node.expression.arguments[0].value);
);
} }
const addAndRemovePolyfillImports = { const addAndRemovePolyfillImports = {

View File

@ -75,6 +75,7 @@ const buildTest = opts => {
describe("debug output", () => { describe("debug output", () => {
fs.readdirSync(fixtureLoc).forEach(testName => { fs.readdirSync(fixtureLoc).forEach(testName => {
if (testName.slice(0, 1) === ".") return;
const testLoc = path.join(fixtureLoc, testName); const testLoc = path.join(fixtureLoc, testName);
const opts = { const opts = {

View File

@ -0,0 +1,11 @@
{
"presets": [
["../../lib", {
"debug": true,
"targets": {
"browsers": [ "Android >= 4" ]
},
"useBuiltIns": "entry"
}]
]
}

View File

@ -0,0 +1,124 @@
babel-preset-env: `DEBUG` option
Using targets:
{
"android": "4"
}
Modules transform: commonjs
Using plugins:
check-es2015-constants {"android":"4"}
transform-es2015-arrow-functions {"android":"4"}
transform-es2015-block-scoped-functions {"android":"4"}
transform-es2015-block-scoping {"android":"4"}
transform-es2015-classes {"android":"4"}
transform-es2015-computed-properties {"android":"4"}
transform-es2015-destructuring {"android":"4"}
transform-es2015-duplicate-keys {"android":"4"}
transform-es2015-for-of {"android":"4"}
transform-es2015-function-name {"android":"4"}
transform-es2015-literals {"android":"4"}
transform-es2015-object-super {"android":"4"}
transform-es2015-parameters {"android":"4"}
transform-es2015-shorthand-properties {"android":"4"}
transform-es2015-spread {"android":"4"}
transform-es2015-sticky-regex {"android":"4"}
transform-es2015-template-literals {"android":"4"}
transform-es2015-typeof-symbol {"android":"4"}
transform-es2015-unicode-regex {"android":"4"}
transform-regenerator {"android":"4"}
transform-exponentiation-operator {"android":"4"}
transform-async-to-generator {"android":"4"}
syntax-trailing-function-commas {"android":"4"}
Polyfills
=========
Replaced `babel-polyfill` with the following polyfills:
es6.typed.array-buffer {"android":"4"}
es6.typed.int8-array {"android":"4"}
es6.typed.uint8-array {"android":"4"}
es6.typed.uint8-clamped-array {"android":"4"}
es6.typed.int16-array {"android":"4"}
es6.typed.uint16-array {"android":"4"}
es6.typed.int32-array {"android":"4"}
es6.typed.uint32-array {"android":"4"}
es6.typed.float32-array {"android":"4"}
es6.typed.float64-array {"android":"4"}
es6.map {"android":"4"}
es6.set {"android":"4"}
es6.weak-map {"android":"4"}
es6.weak-set {"android":"4"}
es6.reflect.apply {"android":"4"}
es6.reflect.construct {"android":"4"}
es6.reflect.define-property {"android":"4"}
es6.reflect.delete-property {"android":"4"}
es6.reflect.get {"android":"4"}
es6.reflect.get-own-property-descriptor {"android":"4"}
es6.reflect.get-prototype-of {"android":"4"}
es6.reflect.has {"android":"4"}
es6.reflect.is-extensible {"android":"4"}
es6.reflect.own-keys {"android":"4"}
es6.reflect.prevent-extensions {"android":"4"}
es6.reflect.set {"android":"4"}
es6.reflect.set-prototype-of {"android":"4"}
es6.promise {"android":"4"}
es6.symbol {"android":"4"}
es6.object.assign {"android":"4"}
es6.object.is {"android":"4"}
es6.object.set-prototype-of {"android":"4"}
es6.function.name {"android":"4"}
es6.string.raw {"android":"4"}
es6.string.from-code-point {"android":"4"}
es6.string.code-point-at {"android":"4"}
es6.string.repeat {"android":"4"}
es6.string.starts-with {"android":"4"}
es6.string.ends-with {"android":"4"}
es6.string.includes {"android":"4"}
es6.regexp.flags {"android":"4"}
es6.regexp.match {"android":"4"}
es6.regexp.replace {"android":"4"}
es6.regexp.split {"android":"4"}
es6.regexp.search {"android":"4"}
es6.array.from {"android":"4"}
es6.array.of {"android":"4"}
es6.array.copy-within {"android":"4"}
es6.array.find {"android":"4"}
es6.array.find-index {"android":"4"}
es6.array.fill {"android":"4"}
es6.array.iterator {"android":"4"}
es6.number.is-finite {"android":"4"}
es6.number.is-integer {"android":"4"}
es6.number.is-safe-integer {"android":"4"}
es6.number.is-nan {"android":"4"}
es6.number.epsilon {"android":"4"}
es6.number.min-safe-integer {"android":"4"}
es6.number.max-safe-integer {"android":"4"}
es6.math.acosh {"android":"4"}
es6.math.asinh {"android":"4"}
es6.math.atanh {"android":"4"}
es6.math.cbrt {"android":"4"}
es6.math.clz32 {"android":"4"}
es6.math.cosh {"android":"4"}
es6.math.expm1 {"android":"4"}
es6.math.fround {"android":"4"}
es6.math.hypot {"android":"4"}
es6.math.imul {"android":"4"}
es6.math.log1p {"android":"4"}
es6.math.log10 {"android":"4"}
es6.math.log2 {"android":"4"}
es6.math.sign {"android":"4"}
es6.math.sinh {"android":"4"}
es6.math.tanh {"android":"4"}
es6.math.trunc {"android":"4"}
es7.array.includes {"android":"4"}
es7.object.values {"android":"4"}
es7.object.entries {"android":"4"}
es7.object.get-own-property-descriptors {"android":"4"}
es7.string.pad-start {"android":"4"}
es7.string.pad-end {"android":"4"}
web.timers {"android":"4"}
web.immediate {"android":"4"}
web.dom.iterable {"android":"4"}
src/in.js -> lib/in.js

View File

@ -0,0 +1,2 @@
const bar = "bar";
const x = () => `foo${bar}`;

View File

@ -0,0 +1,10 @@
"use strict";
function _newArrowCheck(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } }
var bar = "bar";
var x = function () {
_newArrowCheck(undefined, undefined);
return "foo" + bar;
}.bind(undefined);

View File

@ -0,0 +1,7 @@
{
"presets": [
["../../../../lib", {
"spec": true
}]
]
}

View File

@ -5,10 +5,11 @@ const assert = require("assert");
const { const {
checkDuplicateIncludeExcludes, checkDuplicateIncludeExcludes,
normalizePluginNames,
validateIncludesAndExcludes, validateIncludesAndExcludes,
validateLooseOption, validateLooseOption,
validateModulesOption, validateModulesOption,
normalizePluginNames, validateSpecOption,
} = normalizeOptions; } = normalizeOptions;
describe("normalize-options", () => { describe("normalize-options", () => {
@ -36,6 +37,7 @@ describe("normalize-options", () => {
assert.throws(normalizeWithSameIncludes, Error); assert.throws(normalizeWithSameIncludes, Error);
}); });
}); });
describe("validateLooseOption", () => { describe("validateLooseOption", () => {
it("`undefined` option returns false", () => { it("`undefined` option returns false", () => {
assert(validateLooseOption() === false); assert(validateLooseOption() === false);
@ -50,12 +52,23 @@ describe("normalize-options", () => {
}); });
it("array option is invalid", () => { it("array option is invalid", () => {
assert.throws( assert.throws(() => {
() => { validateLooseOption([]);
validateLooseOption([]); });
}, });
Error, });
);
describe("validateSpecOption", () => {
it("`undefined` option returns false", () => {
assert(validateSpecOption() === false);
});
it("`false` option returns false", () => {
assert(validateSpecOption(false) === false);
});
it("`true` option returns true", () => {
assert(validateSpecOption(true) === true);
}); });
}); });

View File

@ -3,11 +3,7 @@
const utils = require("../lib/utils"); const utils = require("../lib/utils");
const assert = require("assert"); const assert = require("assert");
const { const { prettifyTargets, prettifyVersion, semverify } = utils;
prettifyTargets,
prettifyVersion,
semverify,
} = utils;
describe("utils", () => { describe("utils", () => {
describe("semverify", () => { describe("semverify", () => {

View File

@ -1906,9 +1906,9 @@ commoner@^0.10.1:
q "^1.1.2" q "^1.1.2"
recast "^0.11.17" recast "^0.11.17"
compat-table@kangax/compat-table#c38f039b8ea7fadf347d3e300fec3611645e31e9: compat-table@kangax/compat-table#861954b6e13d3eaa1ba9ef1a016906c0fc1072db:
version "0.0.0" version "0.0.0"
resolved "https://codeload.github.com/kangax/compat-table/tar.gz/c38f039b8ea7fadf347d3e300fec3611645e31e9" resolved "https://codeload.github.com/kangax/compat-table/tar.gz/861954b6e13d3eaa1ba9ef1a016906c0fc1072db"
dependencies: dependencies:
babel-core latest babel-core latest
babel-polyfill latest babel-polyfill latest
@ -2697,7 +2697,7 @@ glob@5.0.x, glob@^5.0.15:
once "^1.3.0" once "^1.3.0"
path-is-absolute "^1.0.0" path-is-absolute "^1.0.0"
glob@7.0.5, glob@^7.0.3: glob@7.0.5:
version "7.0.5" version "7.0.5"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95"
dependencies: dependencies:
@ -2708,7 +2708,7 @@ glob@7.0.5, glob@^7.0.3:
once "^1.3.0" once "^1.3.0"
path-is-absolute "^1.0.0" path-is-absolute "^1.0.0"
glob@7.1.1, glob@^7.0.0, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1: glob@7.1.1, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
version "7.1.1" version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies: dependencies: