Merge branch 'master' into 2.0

This commit is contained in:
Brian Ng 2017-03-10 11:35:58 -06:00
commit f521884d01
26 changed files with 1468 additions and 539 deletions

View File

@ -1,6 +1,8 @@
node_modules
coverage
lib
test/tmp
.DS_Store
*.log
.vscode
.nyc_output

View File

@ -11,18 +11,21 @@ node_js:
- '6'
- '4'
env:
- PKG_CMD="npm"
- PKG_CMD="yarn"
global:
- BABEL_ENV=test
matrix:
- PKG_CMD="npm"
- PKG_CMD="yarn"
before_install:
- nvm use $TRAVIS_NODE_VERSION
- npm set loglevel error
- npm set progress false
- 'if [ $PKG_CMD = "yarn" ]; then npm i -g yarn@0.21.3 ; fi'
- 'if [ $PKG_CMD = "yarn" ]; then npm i -g yarn@0.22.0 ; fi'
install:
- $PKG_CMD install
script:
- 'if [ -n "${LINT-}" ]; then $PKG_CMD run lint ; fi'
- 'if [ -z "${LINT-}" ]; then $PKG_CMD run ci ; fi'
- 'if [ -z "${LINT-}" ]; then $PKG_CMD run test-ci ; fi'
matrix:
fast_finish: true
include:
@ -31,3 +34,4 @@ matrix:
exclude:
- node_js: "4"
env: PKG_CMD="yarn"
after_success: 'if [ -z "${LINT-}" ]; then npm run coverage-ci ; fi'

View File

@ -1,6 +1,47 @@
# Changelog
## v.1.1.11 (2017-03-01)
## v1.2.1 (2017-03-06)
### :bug: Bug Fix
- Add transform-duplicate-keys mapping ([#192](https://github.com/babel/babel-preset-env/pull/192)) (@existentialism)
Our plugin data was missing a mapping for the `transform-duplicate-keys` plugin which caused it to never be included. (s/o to @Timer for the report!)
### :memo: Documentation
- Clarify reasons for the uglify option in README.md ([#188](https://github.com/babel/babel-preset-env/pull/188)) (@mikegreiling)
## v1.2.0 (2017-03-03)
### :rocket: New Feature
- Add uglify as a target ([#178](https://github.com/babel/babel-preset-env/pull/178)) (@yavorsky)
Support for `uglify` as a target is now available! This will enable all plugins and, as a result, fully compiles your code to ES5. Note, that useBuiltIns will work as before, and only the polyfills that your other target(s) need will be included.
```json
{
"presets": [
["env", {
"targets": {
"chrome": 55,
"uglify": true
},
"useBuiltIns": true,
"modules": false
}]
]
}
```
### :bug: Bug Fix
- Respect older versions in invert equals map ([#180](https://github.com/babel/babel-preset-env/pull/180)) (@danez)
Fixes a number of bugs that caused some incorrect and/or missing environment data when parsing `compat-table`.
## v1.1.11 (2017-03-01)
This release primarily upgrades `compat-table`, which adds support for async on Node 7.6!

View File

@ -1,22 +1,22 @@
## Contributing
# Contributing
### Adding a new plugin to support (when approved in the next ECMAScript version)
## Adding a new plugin to support (when approved in the next ECMAScript version)
#### Update [`pluginFeatures.js`](/data/plugin-features.js)
### Update [`plugin-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js)
Example:
*Example:*
In you were going to add `**` which is in ES2016:
If you were going to add `**` which is in ES2016:
Find the relevant entries on [compat-table](https://kangax.github.io/compat-table/):
Find the relevant entries on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-exponentiation_(**)_operator):
`exponentiation (**) operator`
Find the corresponding babel plugin:
Find the corresponding babel plugin:
`transform-exponentiation-operator`
Add add them in this structure:
And add them in this structure:
```js
// es2016
@ -26,16 +26,54 @@ Add add them in this structure:
],
},
```
#### Update [`plugins.json`](/data/plugins.json)
### Update [`built-in-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/built-in-features.js)
*Example:*
In case you want to add `Object.values` which is in ES2017:
Find the relevant feature and subfeature on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-Object_static_methods_Object.values)
and split it with `/`:
`Object static methods / Object.values`
Find the corresponding module on [core-js](https://github.com/zloirock/core-js/tree/master/modules):
`es7.object.values.js`
Find required ES version in [`built-in-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/built-in-features.js) and add the new feature:
```js
const es2017 = {
//...
"es7.object.values": "Object static methods / Object.values"
}
```
### Update [`plugins.json`](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json)
Until `compat-table` is a standalone npm module for data we are using the git url
`"compat-table": "github:kangax/compat-table#gh-pages",`
`"compat-table": "kangax/compat-table#[latest-commit-hash]"`,
So we update and then run `npm run build-data`. If there are no changes, then `plugins.json` will be the same.
### Writing Tests
## Tests
### Running tests locally
```bash
npm test
```
### Checking code coverage locally
```bash
npm run coverage
```
### Writing tests
#### General
@ -45,11 +83,11 @@ please read our [documentation on writing tests](https://github.com/babel/babel/
#### Testing the `debug` option
Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`,
Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`,
create a folder with a descriptive name of your test, and add the following:
* Add a `options.json` file (just as the other tests, this is essentially a
* Add a `options.json` file (just as the other tests, this is essentially a
`.babelrc`) with the desired test configuration (required)
* Add a `stdout.txt` file with the expected debug output. For added
convenience, if there is no `stdout.txt` present, the test runner will
* Add a `stdout.txt` file with the expected debug output. For added
convenience, if there is no `stdout.txt` present, the test runner will
generate one for you.

View File

@ -1,4 +1,4 @@
# 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)
# 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.
@ -44,7 +44,7 @@ Ref: [#7](https://github.com/babel/babel-preset-env/issues/7)
> Currently located at [plugin-features.js](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js).
This should be straightforward to do in most cases. There might be cases were plugins should be split up more or certain plugins aren't standalone enough (or impossible to do).
This should be straightforward to do in most cases. There might be cases where plugins should be split up more or certain plugins aren't standalone enough (or impossible to do).
### Support all plugins in Babel that are considered `latest`
@ -118,10 +118,20 @@ If you want to compile against the current node version, you can specify `"node"
`Array<string> | string`
A query to select browsers (ex: last 2 versions, > 5%) using [browserslist](https://github.com/ai/browserslist).
A query to select browsers (ex: last 2 versions, > 5%) using [browserslist](https://github.com/ai/browserslist).
Note, browsers' results are overridden by explicit items from `targets`.
### `targets.uglify`
`number | true`
UglifyJS does not currently support any ES6 syntax, so if you are using Uglify to minify your code, targeting later browsers may cause Uglify to throw syntax errors.
To prevent these errors - specify the uglify option, which will enable all plugins and, as a result, fully compile your code to ES5. However, the `useBuiltIns` option will still work as before, and only include the polyfills that your target(s) need.
> 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).
### `loose`
`boolean`, defaults to `false`.

View File

@ -0,0 +1,4 @@
coverage:
parsers:
javascript:
enable_partials: yes

View File

@ -36,6 +36,7 @@
"firefox": 4,
"safari": 6,
"node": 0.12,
"android": 4.4,
"ios": 7
},
"es6.typed.int16-array": {
@ -118,6 +119,7 @@
"chrome": 51,
"firefox": 53,
"safari": 9,
"node": 6.5,
"ios": 9,
"opera": 38
},
@ -126,6 +128,7 @@
"edge": 15,
"firefox": 53,
"safari": 9,
"node": 6.5,
"ios": 9,
"opera": 38
},
@ -134,6 +137,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -142,6 +146,7 @@
"edge": 13,
"firefox": 45,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -150,6 +155,7 @@
"edge": 13,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -158,6 +164,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -166,6 +173,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -174,6 +182,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -182,6 +191,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -190,6 +200,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -198,6 +209,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -206,6 +218,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -214,6 +227,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -222,6 +236,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -230,6 +245,7 @@
"edge": 12,
"firefox": 42,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 36
},
@ -246,6 +262,7 @@
"chrome": 51,
"firefox": 51,
"safari": 10,
"node": 6.5,
"ios": 10,
"opera": 38
},
@ -273,6 +290,7 @@
"safari": 9,
"node": 0.12,
"ie": 11,
"android": 5,
"ios": 9,
"opera": 21
},
@ -351,6 +369,7 @@
"chrome": 49,
"firefox": 37,
"safari": 9,
"node": 6,
"ios": 9,
"opera": 36
},
@ -419,7 +438,7 @@
"firefox": 25,
"safari": 8,
"node": 4,
"ios": 9,
"ios": 8,
"opera": 32
},
"es6.array.find-index": {
@ -428,7 +447,7 @@
"firefox": 25,
"safari": 8,
"node": 4,
"ios": 9,
"ios": 8,
"opera": 32
},
"es6.array.fill": {
@ -437,7 +456,7 @@
"firefox": 31,
"safari": 8,
"node": 4,
"ios": 9,
"ios": 8,
"opera": 32
},
"es6.array.iterator": {
@ -446,7 +465,8 @@
"firefox": 28,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.number.is-finite": {
@ -464,6 +484,7 @@
"firefox": 16,
"safari": 9,
"node": 0.12,
"android": 5,
"ios": 9,
"opera": 21
},
@ -473,6 +494,7 @@
"firefox": 32,
"safari": 9,
"node": 0.12,
"android": 5,
"ios": 9,
"opera": 21
},
@ -491,6 +513,7 @@
"firefox": 25,
"safari": 9,
"node": 0.12,
"android": 5,
"ios": 9,
"opera": 21
},
@ -500,6 +523,7 @@
"firefox": 31,
"safari": 9,
"node": 0.12,
"android": 5,
"ios": 9,
"opera": 21
},
@ -509,6 +533,7 @@
"firefox": 31,
"safari": 9,
"node": 0.12,
"android": 5,
"ios": 9,
"opera": 21
},
@ -518,7 +543,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.asinh": {
@ -527,7 +553,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.atanh": {
@ -536,7 +563,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.cbrt": {
@ -545,7 +573,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.clz32": {
@ -554,6 +583,7 @@
"firefox": 31,
"safari": 9,
"node": 0.12,
"android": 5.1,
"ios": 9,
"opera": 25
},
@ -563,7 +593,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.expm1": {
@ -572,7 +603,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.fround": {
@ -581,7 +613,8 @@
"firefox": 26,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.hypot": {
@ -590,7 +623,8 @@
"firefox": 27,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.imul": {
@ -609,7 +643,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.log10": {
@ -618,7 +653,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.log2": {
@ -627,7 +663,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.sign": {
@ -636,6 +673,7 @@
"firefox": 25,
"safari": 9,
"node": 0.12,
"android": 5.1,
"ios": 9,
"opera": 25
},
@ -645,7 +683,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.tanh": {
@ -654,7 +693,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es6.math.trunc": {
@ -663,7 +703,8 @@
"firefox": 25,
"safari": 8,
"node": 0.12,
"ios": 9,
"android": 5.1,
"ios": 8,
"opera": 25
},
"es7.array.includes": {
@ -671,6 +712,7 @@
"edge": 14,
"firefox": 43,
"safari": 10,
"node": 6,
"ios": 10,
"opera": 34
},
@ -678,6 +720,7 @@
"chrome": 54,
"edge": 14,
"firefox": 47,
"safari": 10.1,
"node": 7,
"opera": 41
},
@ -685,6 +728,7 @@
"chrome": 54,
"edge": 14,
"firefox": 47,
"safari": 10.1,
"node": 7,
"opera": 41
},
@ -692,7 +736,7 @@
"chrome": 54,
"edge": 15,
"firefox": 50,
"safari": 10,
"safari": 10.1,
"node": 7,
"opera": 41
},

View File

@ -39,6 +39,11 @@ module.exports = {
"destructuring, parameters",
],
},
"transform-es2015-duplicate-keys": {
features: [
"miscellaneous / duplicate property names in strict mode",
],
},
"transform-es2015-for-of": {
features: [
"for..of loops",

View File

@ -34,13 +34,22 @@
"ios": 10,
"opera": 33
},
"transform-es2015-duplicate-keys": {
"chrome": 42,
"edge": 12,
"firefox": 34,
"safari": 9,
"node": 4,
"ios": 9,
"opera": 29
},
"transform-es2015-computed-properties": {
"chrome": 44,
"edge": 12,
"firefox": 34,
"safari": 8,
"node": 4,
"ios": 9,
"ios": 8,
"opera": 31
},
"check-es2015-constants": {
@ -146,6 +155,7 @@
"firefox": 36,
"safari": 9,
"node": 0.12,
"android": 5.1,
"ios": 9,
"opera": 25
},
@ -171,11 +181,14 @@
"chrome": 52,
"edge": 14,
"firefox": 52,
"safari": 10.1,
"node": 7,
"opera": 39
},
"transform-async-to-generator": {
"chrome": 55,
"firefox": 52,
"safari": 10.1,
"node": 7.6,
"opera": 42
},

View File

@ -10,12 +10,15 @@
"scripts": {
"build": "rimraf lib && babel src -d lib",
"build-data": "node ./scripts/build-data.js",
"dev": "babel -w src -d lib",
"lint": "eslint .",
"fix": "eslint . --fix",
"ci": "npm run test",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'",
"test": "npm run build && mocha ./test --compilers js:babel-register -t 5000"
"coverage": "BABEL_ENV=test nyc npm run test",
"coverage-ci": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"dev": "babel -w src -d lib",
"fix": "eslint . --fix",
"lint": "eslint .",
"test": "npm run build && npm run test-only",
"test-ci": "nyc npm run test",
"test-only": "mocha ./test --compilers js:babel-register -t 10000"
},
"dependencies": {
"babel-plugin-check-es2015-constants": "7.0.0-alpha.1",
@ -54,17 +57,20 @@
"babel-eslint": "^7.1.1",
"babel-helper-fixtures": "7.0.0-alpha.1",
"babel-helper-plugin-test-runner": "7.0.0-alpha.1",
"babel-plugin-istanbul": "^3.1.2",
"babel-plugin-transform-flow-strip-types": "7.0.0-alpha.1",
"babel-preset-env": "2.0.0-alpha.1",
"babel-register": "7.0.0-alpha.1",
"chai": "^3.0.0",
"compat-table": "kangax/compat-table#291c758ac618fff6bf5bb2113a5aa046189f93e2",
"codecov": "^1.0.1",
"compat-table": "kangax/compat-table#c38f039b8ea7fadf347d3e300fec3611645e31e9",
"eslint": "^3.13.1",
"eslint-config-babel": "^5.0.0",
"eslint-plugin-flowtype": "^2.29.1",
"fs-extra": "^2.0.0",
"lodash": "^4.15.0",
"mocha": "^3.0.2",
"nyc": "^10.1.2",
"rimraf": "^2.5.4"
},
"babel": {
@ -80,6 +86,17 @@
],
"plugins": [
"transform-flow-strip-types"
]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
},
"nyc": {
"all": true,
"include": ["src/*.js"],
"instrument": false,
"sourceMap": false
}
}

View File

@ -16,36 +16,6 @@ const es6Data = require("compat-table/data-es6");
const es6PlusData = require("compat-table/data-es2016plus");
const envs = require("compat-table/environments");
const invertedEqualsEnv = Object.keys(envs)
.filter((b) => envs[b].equals)
.reduce((a, b) => {
if (!a[envs[b].equals]) {
a[envs[b].equals] = [b];
} else {
a[envs[b].equals].push(b);
}
return a;
}, {});
invertedEqualsEnv.safari5 = ["ios6"];
if (Array.isArray(invertedEqualsEnv.safari6)) {
invertedEqualsEnv.safari6.push("ios7");
} else {
invertedEqualsEnv.safari6 = ["ios7"];
}
invertedEqualsEnv.safari8 = ["ios9"];
const compatibilityTests = flattenDeep([
es6Data,
es6PlusData,
].map((data) =>
data.tests.map((test) => {
return test.subtests ?
[test, renameTests(test.subtests, (name) => test.name + " / " + name)] :
test;
})
));
const environments = [
"chrome",
"opera",
@ -62,6 +32,7 @@ const environments = [
const envMap = {
safari51: "safari5",
safari71_8: "safari8",
safari10_1: "safari10.1",
firefox3_5: "firefox3",
firefox3_6: "firefox3",
node010: "node0.10",
@ -80,6 +51,46 @@ const envMap = {
ios51: "ios5.1",
};
const invertedEqualsEnv = Object.keys(envs)
.filter((b) => envs[b].equals)
.reduce((a, b) => {
const checkEnv = envMap[envs[b].equals] || envs[b].equals;
environments.some((env) => {
// go through all environment names to find the the current one
// and try to get the version as integer
const version = parseFloat(checkEnv.replace(env, ""));
if (!isNaN(version)) {
Object.keys(envs).forEach((equals) => {
equals = envMap[equals] || equals;
// Go through all envs from compat-table and get int version
const equalsVersion = parseFloat(equals.replace(env, ""));
// If the current version is smaller than the version that was mentioned
// in `equals` we can add an entry, as older versions should include features
// that newer ones have
if (!isNaN(equalsVersion) && equalsVersion <= version) {
if (!a[equals]) a[equals] = [];
if (a[equals].indexOf(b) >= 0) return;
a[equals].push(b);
}
});
return true;
}
});
return a;
}, {});
const compatibilityTests = flattenDeep([
es6Data,
es6PlusData,
].map((data) =>
data.tests.map((test) => {
return test.subtests ?
[test, renameTests(test.subtests, (name) => test.name + " / " + name)] :
test;
})
));
const getLowestImplementedVersion = ({ features }, env) => {
const tests = flatten(compatibilityTests
.filter((test) => {
@ -130,7 +141,7 @@ const getLowestImplementedVersion = ({ features }, env) => {
.filter((test) => tests[i].res[test] === true || tests[i].res[test] === "strict")
// normalize some keys
.map((test) => envMap[test] || test)
.filter((test) => !isNaN(parseInt(test.replace(env, ""))))
.filter((test) => !isNaN(parseFloat(test.replace(env, ""))))
.shift();
});

View File

@ -94,29 +94,33 @@ const _extends = Object.assign || function (target) {
export const getTargets = (targets = {}) => {
const targetOps = _extends({}, targets);
const targetOpts = _extends({}, targets);
if (targetOps.node === true || targetOps.node === "current") {
targetOps.node = getCurrentNodeVersion();
if (targetOpts.node === true || targetOpts.node === "current") {
targetOpts.node = getCurrentNodeVersion();
}
if (targetOpts.hasOwnProperty("uglify") && !targetOpts.uglify) {
delete targetOpts.uglify;
}
// Replace Electron target with its Chrome equivalent
if (targetOps.electron) {
const electronChromeVersion = getElectronChromeVersion(targetOps.electron);
if (targetOpts.electron) {
const electronChromeVersion = getElectronChromeVersion(targetOpts.electron);
targetOps.chrome = targetOps.chrome
? Math.min(targetOps.chrome, electronChromeVersion)
targetOpts.chrome = targetOpts.chrome
? Math.min(targetOpts.chrome, electronChromeVersion)
: electronChromeVersion;
delete targetOps.electron;
delete targetOpts.electron;
}
const browserOpts = targetOps.browsers;
const browserOpts = targetOpts.browsers;
if (isBrowsersQueryValid(browserOpts)) {
const queryBrowsers = getLowestVersions(browserslist(browserOpts));
return mergeBrowsers(queryBrowsers, targetOps);
return mergeBrowsers(queryBrowsers, targetOpts);
}
return targetOps;
return targetOpts;
};
let hasBeenLogged = false;
@ -143,6 +147,14 @@ const filterItem = (targets, exclusions, list, item) => {
return isRequired && notExcluded;
};
const getBuiltInTargets = (targets) => {
const builtInTargets = _extends({}, targets);
if (builtInTargets.uglify != null) {
delete builtInTargets.uglify;
}
return builtInTargets;
};
export const transformIncludesAndExcludes = (opts) => ({
all: opts,
plugins: opts.filter((opt) => !opt.match(/^(es\d+|web)\./)),
@ -157,15 +169,17 @@ export default function buildPreset(context, opts = {}) {
const include = transformIncludesAndExcludes(validatedOptions.include);
const exclude = transformIncludesAndExcludes(validatedOptions.exclude);
const filterPlugins = filterItem.bind(null, targets, exclude.plugins, pluginList);
const transformations = Object.keys(pluginList)
.filter(filterPlugins)
.concat(include.plugins);
let polyfills;
let polyfillTargets;
if (useBuiltIns) {
const filterBuiltIns = filterItem.bind(null, targets, exclude.builtIns, builtInsList);
polyfillTargets = getBuiltInTargets(targets);
const filterBuiltIns = filterItem.bind(null, polyfillTargets, exclude.builtIns, builtInsList);
polyfills = Object.keys(builtInsList)
.concat(defaultInclude)
.filter(filterBuiltIns)
@ -185,7 +199,7 @@ export default function buildPreset(context, opts = {}) {
if (useBuiltIns && polyfills.length) {
console.log("\nUsing polyfills:");
polyfills.forEach((polyfill) => {
logPlugin(polyfill, targets, builtInsList);
logPlugin(polyfill, polyfillTargets, builtInsList);
});
}
}

View File

@ -0,0 +1,13 @@
{
"presets": [
["../../lib", {
"debug": true,
"targets": {
"chrome": 55,
"uglify": true
},
"useBuiltIns": true,
"modules": false
}]
]
}

View File

@ -0,0 +1,42 @@
babel-preset-env: `DEBUG` option
Using targets:
{
"chrome": 55,
"uglify": true
}
Modules transform: false
Using plugins:
transform-es2015-arrow-functions {"uglify":true}
transform-es2015-block-scoped-functions {"uglify":true}
transform-es2015-block-scoping {"uglify":true}
transform-es2015-classes {"uglify":true}
transform-es2015-duplicate-keys {"uglify":true}
transform-es2015-computed-properties {"uglify":true}
check-es2015-constants {"uglify":true}
transform-es2015-destructuring {"uglify":true}
transform-es2015-for-of {"uglify":true}
transform-es2015-function-name {"uglify":true}
transform-es2015-literals {"uglify":true}
transform-es2015-object-super {"uglify":true}
transform-es2015-parameters {"uglify":true}
transform-es2015-shorthand-properties {"uglify":true}
transform-es2015-spread {"uglify":true}
transform-es2015-sticky-regex {"uglify":true}
transform-es2015-template-literals {"uglify":true}
transform-es2015-typeof-symbol {"uglify":true}
transform-es2015-unicode-regex {"uglify":true}
transform-regenerator {"uglify":true}
transform-exponentiation-operator {"uglify":true}
transform-async-to-generator {"uglify":true}
syntax-trailing-function-commas {"chrome":55,"uglify":true}
Using polyfills:
es7.string.pad-start {"chrome":55}
es7.string.pad-end {"chrome":55}
web.timers {"chrome":55}
web.immediate {"chrome":55}
web.dom.iterable {"chrome":55}
src/in.js -> lib/in.js

View File

@ -14,6 +14,7 @@ Using plugins:
transform-es2015-block-scoped-functions {"ie":10}
transform-es2015-block-scoping {"ie":10}
transform-es2015-classes {"ie":10}
transform-es2015-duplicate-keys {"ie":10}
transform-es2015-computed-properties {"ie":10}
check-es2015-constants {"ie":10}
transform-es2015-destructuring {"ie":10,"node":6}
@ -39,19 +40,19 @@ Using polyfills:
es6.set {"ie":10,"node":6}
es6.weak-map {"ie":10,"node":6}
es6.weak-set {"ie":10,"node":6}
es6.reflect.apply {"ie":10,"node":6}
es6.reflect.construct {"ie":10,"node":6}
es6.reflect.define-property {"ie":10,"node":6}
es6.reflect.delete-property {"ie":10,"node":6}
es6.reflect.get {"ie":10,"node":6}
es6.reflect.get-own-property-descriptor {"ie":10,"node":6}
es6.reflect.get-prototype-of {"ie":10,"node":6}
es6.reflect.has {"ie":10,"node":6}
es6.reflect.is-extensible {"ie":10,"node":6}
es6.reflect.own-keys {"ie":10,"node":6}
es6.reflect.prevent-extensions {"ie":10,"node":6}
es6.reflect.set {"ie":10,"node":6}
es6.reflect.set-prototype-of {"ie":10,"node":6}
es6.reflect.apply {"ie":10}
es6.reflect.construct {"ie":10}
es6.reflect.define-property {"ie":10}
es6.reflect.delete-property {"ie":10}
es6.reflect.get {"ie":10}
es6.reflect.get-own-property-descriptor {"ie":10}
es6.reflect.get-prototype-of {"ie":10}
es6.reflect.has {"ie":10}
es6.reflect.is-extensible {"ie":10}
es6.reflect.own-keys {"ie":10}
es6.reflect.prevent-extensions {"ie":10}
es6.reflect.set {"ie":10}
es6.reflect.set-prototype-of {"ie":10}
es6.promise {"ie":10,"node":6}
es6.symbol {"ie":10,"node":6}
es6.object.assign {"ie":10}
@ -65,7 +66,7 @@ Using polyfills:
es6.string.starts-with {"ie":10}
es6.string.ends-with {"ie":10}
es6.string.includes {"ie":10}
es6.regexp.flags {"ie":10,"node":6}
es6.regexp.flags {"ie":10}
es6.regexp.match {"ie":10}
es6.regexp.replace {"ie":10}
es6.regexp.split {"ie":10}
@ -101,7 +102,7 @@ Using polyfills:
es6.math.sinh {"ie":10}
es6.math.tanh {"ie":10}
es6.math.trunc {"ie":10}
es7.array.includes {"ie":10,"node":6}
es7.array.includes {"ie":10}
es7.object.values {"ie":10,"node":6}
es7.object.entries {"ie":10,"node":6}
es7.object.get-own-property-descriptors {"ie":10,"node":6}

View File

@ -13,6 +13,5 @@ Using plugins:
transform-es2015-for-of {"firefox":52}
transform-es2015-function-name {"firefox":52}
transform-es2015-literals {"firefox":52}
transform-exponentiation-operator {"node":7.4}
syntax-trailing-function-commas {"node":7.4}
src/in.js -> lib/in.js

View File

@ -17,6 +17,7 @@ Using plugins:
transform-es2015-block-scoped-functions {"edge":13,"ie":10,"ios":9,"safari":7}
transform-es2015-block-scoping {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
transform-es2015-classes {"ie":10,"ios":9,"safari":7}
transform-es2015-duplicate-keys {"ie":10,"safari":7}
transform-es2015-computed-properties {"ie":10,"safari":7}
check-es2015-constants {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
transform-es2015-destructuring {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}

View File

@ -0,0 +1 @@
var a = { b:1, b: 2};

View File

@ -0,0 +1,3 @@
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var a = _defineProperty({ b: 1 }, "b", 2);

View File

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

View File

@ -0,0 +1,3 @@
import "babel-polyfill";
const a = 1;

View File

@ -0,0 +1,9 @@
import "core-js/modules/es7.string.pad-start";
import "core-js/modules/es7.string.pad-end";
import "core-js/modules/web.timers";
import "core-js/modules/web.immediate";
import "core-js/modules/web.dom.iterable";
import "regenerator-runtime/runtime";
var a = 1;

View File

@ -0,0 +1,12 @@
{
"presets": [
["../../../../lib", {
"targets": {
"chrome": 55,
"uglify": true
},
"modules": false,
"useBuiltIns": true
}]
]
}

View File

@ -85,6 +85,28 @@ describe("babel-preset-env", () => {
});
});
describe("getTargets + uglify", () => {
it("should work with `true`", function() {
assert.deepEqual(babelPresetEnv.getTargets({
uglify: true
}), {
uglify: true
});
});
it("should ignore `false`", function() {
assert.deepEqual(babelPresetEnv.getTargets({
uglify: false
}), {});
});
it("should ignore `null`", function() {
assert.deepEqual(babelPresetEnv.getTargets({
uglify: null
}), {});
});
});
describe("isPluginRequired", () => {
it("returns true if no targets are specified", () => {
const isRequired = babelPresetEnv.isPluginRequired({}, {});
@ -173,6 +195,18 @@ describe("babel-preset-env", () => {
assert(babelPresetEnv.isPluginRequired(targets, plugin) === true);
});
it("returns true if uglify is specified as a target", () => {
const plugin = {
chrome: 50
};
const targets = {
chrome: 55,
uglify: true
};
assert(babelPresetEnv.isPluginRequired(targets, plugin) === true);
});
it("doesn't throw when specifying a decimal for node", () => {
const plugin = {
node: 6

File diff suppressed because it is too large Load Diff