babel-preset-env
Advanced tools
Comparing version 2.0.0-beta.0 to 2.0.0-beta.1
@@ -1,3 +0,1 @@ | ||
// https://github.com/zloirock/core-js | ||
const typedArrayMethods = [ | ||
@@ -83,3 +81,14 @@ "typed arrays / %TypedArray%.from", | ||
"es6.promise": "Promise", | ||
"es6.promise": { | ||
features: [ | ||
"Promise / basic functionality", | ||
"Promise / constructor requires new", | ||
"Promise / Promise.prototype isn\'t an instance", | ||
"Promise / Promise.all", | ||
"Promise / Promise.all, generic iterables", | ||
"Promise / Promise.race", | ||
"Promise / Promise.race, generic iterables", | ||
"Promise / Promise[Symbol.species]" | ||
] | ||
}, | ||
@@ -182,2 +191,4 @@ "es6.symbol": { | ||
module.exports = Object.assign({}, es2015, es2016, es2017); | ||
const proposals = require("./shipped-proposals").builtIns; | ||
module.exports = Object.assign({}, es2015, es2016, es2017, proposals); |
@@ -167,3 +167,3 @@ { | ||
"edge": "13", | ||
"firefox": "45", | ||
"firefox": "44", | ||
"safari": "10", | ||
@@ -695,2 +695,3 @@ "node": "6", | ||
"node": "0.12", | ||
"android": "4.4", | ||
"ios": "7", | ||
@@ -829,3 +830,4 @@ "opera": "17", | ||
"electron": "1.7" | ||
} | ||
}, | ||
"es7.promise.finally": {} | ||
} |
@@ -105,2 +105,7 @@ const es2015 = { | ||
}, | ||
"transform-new-target": { | ||
features: [ | ||
"new.target", | ||
], | ||
}, | ||
"transform-regenerator": { | ||
@@ -134,2 +139,4 @@ features: [ | ||
module.exports = Object.assign({}, es2015, es2016, es2017); | ||
const proposals = require("./shipped-proposals").features; | ||
module.exports = Object.assign({}, es2015, es2016, es2017, proposals); |
@@ -65,3 +65,2 @@ { | ||
"chrome": "51", | ||
"edge": "15", | ||
"firefox": "53", | ||
@@ -193,2 +192,12 @@ "safari": "10", | ||
}, | ||
"transform-new-target": { | ||
"chrome": "46", | ||
"edge": "14", | ||
"firefox": "41", | ||
"safari": "10", | ||
"node": "5", | ||
"ios": "10", | ||
"opera": "33", | ||
"electron": "0.36" | ||
}, | ||
"transform-regenerator": { | ||
@@ -233,3 +242,12 @@ "chrome": "50", | ||
"electron": "1.7" | ||
} | ||
}, | ||
"transform-async-generator-functions": {}, | ||
"transform-object-rest-spread": { | ||
"chrome": "60", | ||
"firefox": "55", | ||
"node": "8.3", | ||
"opera": "47" | ||
}, | ||
"transform-optional-catch-binding": {}, | ||
"transform-unicode-property-regex": {} | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
"check-es2015-constants": require("babel-plugin-check-es2015-constants"), | ||
"syntax-async-generators": require("babel-plugin-syntax-async-generators"), | ||
"syntax-object-rest-spread": require("babel-plugin-syntax-object-rest-spread"), | ||
"syntax-optional-catch-binding": require("babel-plugin-syntax-optional-catch-binding"), | ||
"syntax-trailing-function-commas": require("babel-plugin-syntax-trailing-function-commas"), | ||
"transform-async-to-generator": require("babel-plugin-transform-async-to-generator"), | ||
"transform-async-generator-functions": require("babel-plugin-transform-async-generator-functions"), | ||
"transform-es2015-arrow-functions": require("babel-plugin-transform-es2015-arrow-functions"), | ||
@@ -32,3 +36,7 @@ "transform-es2015-block-scoped-functions": require("babel-plugin-transform-es2015-block-scoped-functions"), | ||
"transform-exponentiation-operator": require("babel-plugin-transform-exponentiation-operator"), | ||
"transform-regenerator": require("babel-plugin-transform-regenerator") | ||
"transform-new-target": require("babel-plugin-transform-new-target"), | ||
"transform-object-rest-spread": require("babel-plugin-transform-object-rest-spread"), | ||
"transform-optional-catch-binding": require("babel-plugin-transform-optional-catch-binding"), | ||
"transform-regenerator": require("babel-plugin-transform-regenerator"), | ||
"transform-unicode-property-regex": require("babel-plugin-transform-unicode-property-regex") | ||
}; |
@@ -31,2 +31,4 @@ "use strict"; | ||
var _shippedProposals = require("../data/shipped-proposals.js"); | ||
var _useBuiltInsEntryPlugin = require("./use-built-ins-entry-plugin"); | ||
@@ -52,2 +54,15 @@ | ||
var getPlugin = function getPlugin(pluginName) { | ||
var plugin = _availablePlugins2.default[pluginName]; | ||
if (!plugin) { | ||
throw new Error(`Could not find plugin "${pluginName}". Ensure there is an entry in ./available-plugins.js for it.`); | ||
} | ||
return plugin; | ||
}; | ||
var builtInsListWithoutProposals = (0, _utils.filterStageFromList)(_builtIns2.default, _shippedProposals.builtIns); | ||
var pluginListWithoutProposals = (0, _utils.filterStageFromList)(_plugins2.default, _shippedProposals.features); | ||
var isPluginRequired = exports.isPluginRequired = function isPluginRequired(supportedEnvironments, plugin) { | ||
@@ -118,4 +133,12 @@ var targetEnvironments = Object.keys(supportedEnvironments); | ||
if (!excluded && isPluginRequired(targets, list[item])) { | ||
result.add(item); | ||
if (!excluded) { | ||
if (isPluginRequired(targets, list[item])) { | ||
result.add(item); | ||
} else { | ||
var shippedProposalsSyntax = _shippedProposals.pluginSyntaxMap.get(item); | ||
if (shippedProposalsSyntax) { | ||
result.add(shippedProposalsSyntax); | ||
} | ||
} | ||
} | ||
@@ -150,2 +173,3 @@ } | ||
modules = _normalizeOptions.modules, | ||
shippedProposals = _normalizeOptions.shippedProposals, | ||
spec = _normalizeOptions.spec, | ||
@@ -174,3 +198,3 @@ optionsTargets = _normalizeOptions.targets, | ||
var transformTargets = forceAllTransforms || hasUglifyTarget ? {} : targets; | ||
var transformations = filterItems(_plugins2.default, include.plugins, exclude.plugins, transformTargets); | ||
var transformations = filterItems(shippedProposals ? _plugins2.default : pluginListWithoutProposals, include.plugins, exclude.plugins, transformTargets); | ||
var polyfills = void 0; | ||
@@ -181,19 +205,20 @@ var polyfillTargets = void 0; | ||
polyfillTargets = getBuiltInTargets(targets); | ||
polyfills = filterItems(_builtIns2.default, include.builtIns, exclude.builtIns, polyfillTargets, getPlatformSpecificDefaultFor(polyfillTargets)); | ||
polyfills = filterItems(shippedProposals ? _builtIns2.default : builtInsListWithoutProposals, include.builtIns, exclude.builtIns, polyfillTargets, getPlatformSpecificDefaultFor(polyfillTargets)); | ||
} | ||
var plugins = []; | ||
var pluginUseBuiltIns = useBuiltIns !== false; // NOTE: not giving spec here yet to avoid compatibility issues when | ||
// babel-plugin-transform-es2015-modules-commonjs gets its spec mode | ||
if (modules !== false && _moduleTransformations2.default[modules]) { | ||
plugins.push([_availablePlugins2.default[_moduleTransformations2.default[modules]], { | ||
plugins.push([getPlugin(_moduleTransformations2.default[modules]), { | ||
loose | ||
}]); | ||
} // NOTE: not giving spec here yet to avoid compatibility issues when | ||
// babel-plugin-transform-es2015-modules-commonjs gets its spec mode | ||
} | ||
transformations.forEach(function (pluginName) { | ||
return plugins.push([_availablePlugins2.default[pluginName], { | ||
return plugins.push([getPlugin(pluginName), { | ||
spec, | ||
loose | ||
loose, | ||
useBuiltIns: pluginUseBuiltIns | ||
}]); | ||
@@ -200,0 +225,0 @@ }); |
"use strict"; | ||
exports.__esModule = true; | ||
exports.validateUseBuiltInsOption = exports.objectToBrowserslist = exports.validateModulesOption = exports.validateIgnoreBrowserslistConfig = exports.validateForceAllTransformsOption = exports.validateSpecOption = exports.validateLooseOption = exports.validateBoolOption = exports.validateConfigPathOption = exports.checkDuplicateIncludeExcludes = exports.normalizePluginNames = exports.normalizePluginName = exports.validateIncludesAndExcludes = undefined; | ||
exports.validateUseBuiltInsOption = exports.objectToBrowserslist = exports.validateModulesOption = exports.validateIgnoreBrowserslistConfig = exports.validateBoolOption = exports.validateConfigPathOption = exports.checkDuplicateIncludeExcludes = exports.normalizePluginNames = exports.normalizePluginName = exports.validateIncludesAndExcludes = undefined; | ||
exports.default = normalizeOptions; | ||
@@ -96,14 +96,2 @@ | ||
var validateLooseOption = exports.validateLooseOption = function validateLooseOption(looseOpt) { | ||
return validateBoolOption("loose", looseOpt, false); | ||
}; | ||
var validateSpecOption = exports.validateSpecOption = function validateSpecOption(specOpt) { | ||
return validateBoolOption("spec", specOpt, false); | ||
}; | ||
var validateForceAllTransformsOption = exports.validateForceAllTransformsOption = function validateForceAllTransformsOption(forceAllTransforms) { | ||
return validateBoolOption("forceAllTransforms", forceAllTransforms, false); | ||
}; | ||
var validateIgnoreBrowserslistConfig = exports.validateIgnoreBrowserslistConfig = function validateIgnoreBrowserslistConfig(ignoreBrowserslistConfig) { | ||
@@ -160,8 +148,9 @@ return validateBoolOption("ignoreBrowserslistConfig", ignoreBrowserslistConfig, false); | ||
exclude: validateIncludesAndExcludes(opts.exclude, "exclude"), | ||
forceAllTransforms: validateForceAllTransformsOption(opts.forceAllTransforms), | ||
forceAllTransforms: validateBoolOption("forceAllTransforms", opts.forceAllTransforms, false), | ||
ignoreBrowserslistConfig: validateIgnoreBrowserslistConfig(opts.ignoreBrowserslistConfig), | ||
include: validateIncludesAndExcludes(opts.include, "include"), | ||
loose: validateLooseOption(opts.loose), | ||
loose: validateBoolOption("loose", opts.loose, false), | ||
modules: validateModulesOption(opts.modules), | ||
spec: validateSpecOption(opts.spec), | ||
shippedProposals: validateBoolOption("shippedProposals", opts.shippedProposals, false), | ||
spec: validateBoolOption("loose", opts.spec, false), | ||
targets: opts.targets, | ||
@@ -168,0 +157,0 @@ useBuiltIns: validateUseBuiltInsOption(opts.useBuiltIns) |
"use strict"; | ||
exports.__esModule = true; | ||
exports.prettifyTargets = exports.prettifyVersion = exports.semverify = undefined; | ||
exports.filterStageFromList = exports.prettifyTargets = exports.prettifyVersion = exports.semverify = undefined; | ||
@@ -61,2 +61,12 @@ var _semver = require("semver"); | ||
}, {}); | ||
}; | ||
var filterStageFromList = exports.filterStageFromList = function filterStageFromList(list, stageList) { | ||
return Object.keys(list).reduce(function (result, item) { | ||
if (!stageList[item]) { | ||
result[item] = list[item]; | ||
} | ||
return result; | ||
}, {}); | ||
}; |
{ | ||
"name": "babel-preset-env", | ||
"version": "2.0.0-beta.0", | ||
"version": "2.0.0-beta.1", | ||
"description": "A Babel preset for each environment.", | ||
@@ -29,4 +29,8 @@ "author": "Henry Zhu <hi@henryzoo.com>", | ||
"babel-plugin-check-es2015-constants": "7.0.0-beta.0", | ||
"babel-plugin-syntax-async-generators": "7.0.0-beta.0", | ||
"babel-plugin-syntax-object-rest-spread": "7.0.0-beta.0", | ||
"babel-plugin-syntax-optional-catch-binding": "7.0.0-beta.0", | ||
"babel-plugin-syntax-trailing-function-commas": "7.0.0-beta.0", | ||
"babel-plugin-transform-async-to-generator": "7.0.0-beta.0", | ||
"babel-plugin-transform-async-generator-functions": "7.0.0-beta.0", | ||
"babel-plugin-transform-es2015-arrow-functions": "7.0.0-beta.0", | ||
@@ -55,3 +59,7 @@ "babel-plugin-transform-es2015-block-scoped-functions": "7.0.0-beta.0", | ||
"babel-plugin-transform-exponentiation-operator": "7.0.0-beta.0", | ||
"babel-plugin-transform-new-target": "7.0.0-beta.0", | ||
"babel-plugin-transform-regenerator": "7.0.0-beta.0", | ||
"babel-plugin-transform-object-rest-spread": "7.0.0-beta.0", | ||
"babel-plugin-transform-optional-catch-binding": "7.0.0-beta.0", | ||
"babel-plugin-transform-unicode-property-regex": "^2.0.5", | ||
"browserslist": "^2.4.0", | ||
@@ -72,3 +80,3 @@ "invariant": "^2.2.2", | ||
"codecov": "^2.2.0", | ||
"compat-table": "kangax/compat-table#d88c80ea6dcbc7064112eb46bb020718107892f7", | ||
"compat-table": "kangax/compat-table#b8477cc0f6d65c000c46213e654d19f350de9fa8", | ||
"eslint": "^3.17.1", | ||
@@ -75,0 +83,0 @@ "eslint-config-babel": "^6.0.0", |
# babel-preset-env [![npm](https://img.shields.io/npm/v/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![travis](https://img.shields.io/travis/babel/babel-preset-env/master.svg)](https://travis-ci.org/babel/babel-preset-env) [![npm-downloads](https://img.shields.io/npm/dm/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![codecov](https://img.shields.io/codecov/c/github/babel/babel-preset-env/master.svg?maxAge=43200)](https://codecov.io/github/babel/babel-preset-env) | ||
> A Babel preset that can automatically determine the Babel plugins and polyfills you need based on your supported environments. | ||
> A Babel preset that compiles [ES2015+](https://github.com/tc39/proposals/blob/master/finished-proposals.md) down to ES5 by automatically determining the Babel plugins and polyfills you need based on your targeted browser or runtime environments. | ||
@@ -9,4 +9,16 @@ ```sh | ||
Without any configuration options, babel-preset-env behaves exactly the same as babel-preset-latest (or babel-preset-es2015, babel-preset-es2016, and babel-preset-es2017 together). | ||
```json | ||
{ | ||
"presets": ["env"] | ||
} | ||
``` | ||
You can also configure it to only include the polyfills and transforms needed for the browsers you support. Compiling only what's needed can make your bundles smaller and your life easier. | ||
This example only includes the polyfills and code transforms needed for the last two versions of each browser, and versions of Safari greater than or equal to 7. We use [browserslist](https://github.com/ai/browserslist) to parse this information, so you can use [any valid query format supported by browserslist](https://github.com/ai/browserslist#queries). | ||
```json | ||
{ | ||
"presets": [ | ||
@@ -22,2 +34,30 @@ ["env", { | ||
Similarly, if you're targeting Node.js instead of the browser, you can configure babel-preset-env to only include the polyfills and transforms necessary for a particular version: | ||
```json | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": "6.10" | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
For convenience, you can use `"node": "current"` to only include the necessary polyfills and transforms for the Node.js version that you use to run Babel: | ||
```json | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": "current" | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
- [How it Works](#how-it-works) | ||
@@ -63,3 +103,3 @@ - [Install](#install) | ||
For example, if you are building on Node 4, arrow functions won't be converted, but they will if you build on Node 0.12. | ||
For example, if you are building on Node 6, arrow functions won't be converted, but they will if you build on Node 0.12. | ||
@@ -350,2 +390,21 @@ ### Support a `browsers` option like autoprefixer. | ||
### `shippedProposals` | ||
`boolean`, defaults to `false` | ||
Toggles enabling support for builtin/feature proposals that have shipped in browsers. If your target environments have native support for a feature proposal, its matching parser syntax plugin is enabled instead of performing any transform. Note that this _does not_ enable the same transformations as [`babel-preset-stage3`](https://babeljs.io/docs/plugins/preset-stage-3/), since proposals can continue to change before landing in browsers. | ||
The following are currently supported: | ||
**Builtins** | ||
- [Promise.prototype.finally](https://github.com/tc39/proposal-promise-finally) | ||
**Features** | ||
- [Asynchronous Iterators](https://github.com/tc39/proposal-async-iteration) | ||
- [Object rest/spread properties](https://github.com/tc39/proposal-object-rest-spread) | ||
- [Optional catch binding](https://github.com/tc39/proposal-optional-catch-binding) | ||
- [Unicode property escapes in regular expressions](https://github.com/tc39/proposal-regexp-unicode-property-escapes) | ||
--- | ||
@@ -352,0 +411,0 @@ |
Sorry, the diff of this file is not supported yet
352698
2397
574
38
+ Addedbabel-plugin-syntax-optional-catch-binding@7.0.0-beta.0
+ Addedbabel-plugin-transform-async-generator-functions@7.0.0-beta.0
+ Addedbabel-plugin-transform-object-rest-spread@7.0.0-beta.0
+ Addedbabel-plugin-transform-optional-catch-binding@7.0.0-beta.0
+ Addedbabel-helper-regex@6.26.0(transitive)
+ Addedbabel-plugin-syntax-async-generators@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-syntax-object-rest-spread@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-syntax-optional-catch-binding@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-transform-async-generator-functions@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-transform-new-target@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-transform-object-rest-spread@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-transform-optional-catch-binding@7.0.0-beta.0(transitive)
+ Addedbabel-plugin-transform-unicode-property-regex@2.0.5(transitive)