├── .eslintignore ├── .eslintrc ├── .github └── stale.yml ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── codecov.yml ├── data ├── built-in-features.js ├── built-ins.json ├── plugin-features.js └── plugins.json ├── package.json ├── scripts ├── build-data.js └── smoke-test.js ├── src ├── default-includes.js ├── index.js ├── module-transformations.js ├── normalize-options.js ├── targets-parser.js ├── transform-polyfill-require-plugin.js └── utils.js ├── test ├── .eslintrc ├── debug-fixtures.js ├── debug-fixtures │ ├── android │ │ ├── options.json │ │ └── stdout.txt │ ├── builtins-uglify │ │ ├── options.json │ │ └── stdout.txt │ ├── builtins │ │ ├── options.json │ │ └── stdout.txt │ ├── electron │ │ ├── options.json │ │ └── stdout.txt │ ├── plugins-only │ │ ├── options.json │ │ └── stdout.txt │ ├── specific-targets │ │ ├── options.json │ │ └── stdout.txt │ ├── versions-decimals │ │ ├── options.json │ │ └── stdout.txt │ └── versions-strings │ │ ├── options.json │ │ └── stdout.txt ├── fixtures.js ├── fixtures │ ├── plugin-options │ │ ├── filters-duplicates │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── regenerator-false │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ └── regenerator-true │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ ├── preset-options │ │ ├── core-js │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── electron │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── empty-options │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── exclude-built-ins │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── exclude-include │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── exclude-regenerator │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── exclude │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── ie-11-built-ins │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── include-built-ins │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── include │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── ios-10 │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── ios-6 │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── modules-false │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── no-options │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── no-transform │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── spec │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── uglify │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-all-exec │ │ │ ├── exec.js │ │ │ └── options.json │ │ ├── use-builtins-all │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-chrome-48 │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-chrome-49 │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-chromeandroid │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-ie-9 │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-import │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-multiple-imports │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-node-web │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ ├── use-builtins-node │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ │ └── use-builtins-require │ │ │ ├── actual.js │ │ │ ├── expected.js │ │ │ └── options.json │ └── sanity │ │ ├── check-es2015-constants │ │ ├── exec.js │ │ └── options.json │ │ └── transform-duplicate-keys │ │ ├── actual.js │ │ ├── expected.js │ │ └── options.json ├── index.spec.js ├── normalize-options.spec.js ├── targets-parser.spec.js └── utils.spec.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | fixtures 3 | debug-fixtures 4 | test/tmp 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "babel", 3 | "parserOptions": { 4 | "ecmaVersion": 7, 5 | "sourceType": "module" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Number of days of inactivity before an Issue or Pull Request becomes stale 4 | daysUntilStale: 60 5 | # Number of days of inactivity before a stale Issue or Pull Request is closed 6 | daysUntilClose: 7 7 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 8 | exemptLabels: 9 | - has pr 10 | - pinned 11 | - security 12 | # Label to use when marking as stale 13 | staleLabel: stale 14 | # Comment to post when marking as stale. Set to `false` to disable 15 | markComment: > 16 | This issue has been automatically marked as `stale` because it has not had 17 | recent activity 😴. It will be closed if no further activity occurs. Thank you 18 | for your contributions 👌! 19 | # Comment to post when removing the stale label. Set to `false` to disable 20 | unmarkComment: false 21 | # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable 22 | closeComment: false 23 | # Limit to only `issues` or `pulls` 24 | # only: issues 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | lib 4 | test/tmp 5 | .DS_Store 6 | *.log 7 | .vscode 8 | .nyc_output 9 | tmp 10 | babel-preset-env-*.tgz 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | coverage 2 | src 3 | test 4 | node_modules 5 | scripts 6 | .eslintignore 7 | .travis.yml 8 | codecov.yml 9 | yarn.lock 10 | .nyc_output 11 | .vscode 12 | .eslintrc 13 | babel-preset-env-*.tgz 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | git: 2 | depth: 3 3 | sudo: false 4 | language: node_js 5 | cache: 6 | yarn: true 7 | directories: 8 | - node_modules 9 | node_js: 10 | - "8" 11 | - '6' 12 | - '4' 13 | - '0.12' 14 | - '0.10' 15 | env: 16 | global: 17 | - BABEL_ENV=test 18 | matrix: 19 | - PKG_CMD="npm" 20 | - PKG_CMD="yarn" 21 | before_install: 22 | - nvm use $TRAVIS_NODE_VERSION 23 | - npm set loglevel error 24 | - npm set progress false 25 | - 'if [ $PKG_CMD = "yarn" ]; then curl -o- -L https://yarnpkg.com/install.sh | bash && PATH=$HOME/.yarn/bin:$PATH ; fi' 26 | install: 27 | - $PKG_CMD install 28 | script: 29 | - 'if [ -n "${LINT-}" ]; then $PKG_CMD run lint ; fi' 30 | - 'if [ -n "${SMOKE_TEST-}" ]; then node scripts/smoke-test.js ; fi' 31 | - 'if [ -z "${LINT-}" ] && [ -z "${SMOKE_TEST-}" ]; then $PKG_CMD run test-ci ; fi' 32 | matrix: 33 | fast_finish: true 34 | exclude: 35 | - node_js: "0.10" 36 | env: PKG_CMD="yarn" 37 | - node_js: "0.12" 38 | env: PKG_CMD="yarn" 39 | include: 40 | - node_js: "node" 41 | env: LINT=true PKG_CMD="npm" 42 | - node_js: "node" 43 | env: SMOKE_TEST=true PKG_CMD="npm" 44 | 45 | after_success: 'if [ -z "${LINT-}" ] && [ -z "${SMOKE_TEST-}" ]; then npm run coverage-ci ; fi' 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Adding a new plugin to support (when approved in the next ECMAScript version) 4 | 5 | ### Update [`plugin-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js) 6 | 7 | *Example:* 8 | 9 | If you were going to add `**` which is in ES2016: 10 | 11 | Find the relevant entries on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-exponentiation_(**)_operator): 12 | 13 | `exponentiation (**) operator` 14 | 15 | Find the corresponding babel plugin: 16 | 17 | `transform-exponentiation-operator` 18 | 19 | And add them in this structure: 20 | 21 | ```js 22 | // es2016 23 | "transform-exponentiation-operator": { 24 | features: [ 25 | "exponentiation (**) operator", 26 | ], 27 | }, 28 | ``` 29 | 30 | ### Update [`built-in-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/built-in-features.js) 31 | 32 | *Example:* 33 | 34 | In case you want to add `Object.values` which is in ES2017: 35 | 36 | Find the relevant feature and subfeature on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-Object_static_methods_Object.values) 37 | and split it with `/`: 38 | 39 | `Object static methods / Object.values` 40 | 41 | Find the corresponding module on [core-js](https://github.com/zloirock/core-js/tree/master/modules): 42 | 43 | `es7.object.values.js` 44 | 45 | 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: 46 | 47 | ```js 48 | const es2017 = { 49 | //... 50 | "es7.object.values": "Object static methods / Object.values" 51 | } 52 | ``` 53 | 54 | ### Update [`plugins.json`](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json) 55 | 56 | Until `compat-table` is a standalone npm module for data we are using the git url 57 | 58 | `"compat-table": "kangax/compat-table#[latest-commit-hash]"`, 59 | 60 | So we update and then run `npm run build-data`. If there are no changes, then `plugins.json` will be the same. 61 | 62 | ## Tests 63 | 64 | ### Running tests locally 65 | 66 | ```bash 67 | npm test 68 | ``` 69 | 70 | ### Checking code coverage locally 71 | 72 | ```bash 73 | npm run coverage 74 | ``` 75 | 76 | ### Writing tests 77 | 78 | #### General 79 | 80 | All the tests for `babel-preset-env` exist in the `test/fixtures` folder. The 81 | test setup and conventions are exactly the same as testing a Babel plugin, so 82 | please read our [documentation on writing tests](https://github.com/babel/babel/blob/master/CONTRIBUTING.md#babel-plugin-x). 83 | 84 | #### Testing the `debug` option 85 | 86 | Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`, 87 | create a folder with a descriptive name of your test, and add the following: 88 | 89 | * Add a `options.json` file (just as the other tests, this is essentially a 90 | `.babelrc`) with the desired test configuration (required) 91 | * Add a `stdout.txt` file with the expected debug output. For added 92 | convenience, if there is no `stdout.txt` present, the test runner will 93 | generate one for you. 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2017 Babel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Now that `babel-preset-env` has stabilized, it has been [moved into the main Babel mono-repo](https://github.com/babel/babel/tree/master/packages/babel-preset-env) and this repo has been archived. 2 | 3 | The move makes it much easier to release and develop in sync with the rest of Babel! 4 | 5 | This repo will be made read-only, as all of the issues/labels have been moved over as well. Please report any bugs and open pull requests over on the [main mono-repo](https://github.com/babel/babel). 6 | 7 | --- 8 | 9 | # 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) 10 | 11 | > 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. 12 | 13 | ```sh 14 | npm install babel-preset-env --save-dev 15 | ``` 16 | 17 | 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). 18 | 19 | > However, we don't recommend using `preset-env` this way because it doesn't take advantage of it's greater capabilities of targeting specific browsers. 20 | 21 | ```json 22 | { 23 | "presets": ["env"] 24 | } 25 | ``` 26 | 27 | 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. 28 | 29 | This example only includes the polyfills and code transforms needed for coverage of users > 0.25%, ignoring Internet Explorer 11 and Opera Mini.. 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). 30 | 31 | ```js 32 | { 33 | "presets": [ 34 | ["env", { 35 | "targets": { 36 | // The % refers to the global coverage of users from browserslist 37 | "browsers": [ ">0.25%", "not ie 11", "not op_mini all"] 38 | } 39 | }] 40 | ] 41 | } 42 | ``` 43 | 44 | > You can also target individual versions of browsers instead of using a query with `"targets": { "chrome": "52" }`. 45 | 46 | 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: 47 | 48 | ```json 49 | { 50 | "presets": [ 51 | ["env", { 52 | "targets": { 53 | "node": "6.10" 54 | } 55 | }] 56 | ] 57 | } 58 | ``` 59 | 60 | 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: 61 | 62 | ```json 63 | { 64 | "presets": [ 65 | ["env", { 66 | "targets": { 67 | "node": "current" 68 | } 69 | }] 70 | ] 71 | } 72 | ``` 73 | 74 | Check out the many options (especially `useBuiltIns` to polyfill less)! 75 | 76 | - [How it Works](#how-it-works) 77 | - [Install](#install) 78 | - [Usage](#usage) 79 | - [Options](#options) 80 | - [Examples](#examples) 81 | - [Caveats](#caveats) 82 | - [Other Cool Projects](#other-cool-projects) 83 | 84 | ## How it Works 85 | 86 | ### Determine environment support for ECMAScript features 87 | 88 | Use external data such as [`compat-table`](https://github.com/kangax/compat-table) to determine browser support. (We should create PRs there when necessary) 89 | 90 | ![](https://cloud.githubusercontent.com/assets/588473/19214029/58deebce-8d48-11e6-9004-ee3fbcb75d8b.png) 91 | 92 | We can periodically run [build-data.js](https://github.com/babel/babel-preset-env/blob/master/scripts/build-data.js) which generates [plugins.json](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json). 93 | 94 | Ref: [#7](https://github.com/babel/babel-preset-env/issues/7) 95 | 96 | ### Maintain a mapping between JavaScript features and Babel plugins 97 | 98 | > Currently located at [plugin-features.js](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js). 99 | 100 | 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). 101 | 102 | ### Support all plugins in Babel that are considered `latest` 103 | 104 | > Default behavior without options is the same as `babel-preset-latest`. 105 | 106 | It won't include `stage-x` plugins. env will support all plugins in what we consider the latest version of JavaScript (by matching what we do in [`babel-preset-latest`](http://babeljs.io/docs/plugins/preset-latest/)). 107 | 108 | Ref: [#14](https://github.com/babel/babel-preset-env/issues/14) 109 | 110 | ### Determine the lowest common denominator of plugins to be included in the preset 111 | 112 | If you are targeting IE 8 and Chrome 55 it will include all plugins required by IE 8 since you would need to support both still. 113 | 114 | ### Support a target option `"node": "current"` to compile for the currently running node version. 115 | 116 | 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. 117 | 118 | ### Support a `browsers` option like autoprefixer 119 | 120 | Use [browserslist](https://github.com/ai/browserslist) to declare supported environments by performing queries like `> 1%, last 2 versions`. 121 | 122 | Ref: [#19](https://github.com/babel/babel-preset-env/pull/19) 123 | 124 | ## Install 125 | 126 | With [npm](https://www.npmjs.com): 127 | 128 | ```sh 129 | npm install --save-dev babel-preset-env 130 | ``` 131 | 132 | Or [yarn](https://yarnpkg.com): 133 | 134 | ```sh 135 | yarn add babel-preset-env --dev 136 | ``` 137 | 138 | ## Usage 139 | 140 | The default behavior without options runs all transforms (behaves the same as [babel-preset-latest](https://babeljs.io/docs/plugins/preset-latest/)). 141 | 142 | ```json 143 | { 144 | "presets": ["env"] 145 | } 146 | ``` 147 | 148 | ## Options 149 | 150 | For more information on setting options for a preset, refer to the [plugin/preset options](http://babeljs.io/docs/plugins/#plugin-preset-options) documentation. 151 | 152 | ### `targets` 153 | 154 | `{ [string]: number | string }`, defaults to `{}`. 155 | 156 | Takes an object of environment versions to support. 157 | 158 | Each target environment takes a number or a string (we recommend using a string when specifying minor versions like `node: "6.10"`). 159 | 160 | Example environments: `chrome`, `opera`, `edge`, `firefox`, `safari`, `ie`, `ios`, `android`, `node`, `electron`. 161 | 162 | The [data](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json) for this is generated by running the [build-data script](https://github.com/babel/babel-preset-env/blob/master/scripts/build-data.js) which pulls in data from [compat-table](https://kangax.github.io/compat-table). 163 | 164 | ### `targets.node` 165 | 166 | `number | string | "current" | true` 167 | 168 | If you want to compile against the current node version, you can specify `"node": true` or `"node": "current"`, which would be the same as `"node": process.versions.node`. 169 | 170 | ### `targets.browsers` 171 | 172 | `Array | string` 173 | 174 | A query to select browsers (ex: last 2 versions, > 5%) using [browserslist](https://github.com/ai/browserslist). 175 | 176 | Note, browsers' results are overridden by explicit items from `targets`. 177 | 178 | ### `targets.uglify` 179 | 180 | `true` 181 | 182 | When using `uglify-js` to minify your code, you may run into syntax errors when targeting later browsers since `uglify-js` does not support any ES2015+ syntax. 183 | 184 | To prevent these errors - set the `uglify` option to `true`, which enables all transformation plugins and as a result, your code is fully compiled to ES5. However, the `useBuiltIns` option will still work as before and only include the polyfills that your target(s) need. 185 | 186 | > Uglify has support for ES2015 syntax via [uglify-es](https://github.com/mishoo/UglifyJS2/tree/harmony). If you are using syntax unsupported by `uglify-es`, we recommend using [babel-minify](https://github.com/babel/minify). 187 | 188 | > Note: This option is deprecated in 2.x and replaced with a [`forceAllTransforms` option](https://github.com/babel/babel-preset-env/pull/264). 189 | 190 | ### `spec` 191 | 192 | `boolean`, defaults to `false`. 193 | 194 | Enable more spec compliant, but potentially slower, transformations for any plugins in this preset that support them. 195 | 196 | ### `loose` 197 | 198 | `boolean`, defaults to `false`. 199 | 200 | Enable "loose" transformations for any plugins in this preset that allow them. 201 | 202 | ### `modules` 203 | 204 | `"amd" | "umd" | "systemjs" | "commonjs" | false`, defaults to `"commonjs"`. 205 | 206 | Enable transformation of ES6 module syntax to another module type. 207 | 208 | Setting this to `false` will not transform modules. 209 | 210 | ### `debug` 211 | 212 | `boolean`, defaults to `false`. 213 | 214 | Outputs the targets/plugins used and the version specified in [plugin data version](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json) to `console.log`. 215 | 216 | ### `include` 217 | 218 | `Array`, defaults to `[]`. 219 | 220 | > NOTE: `whitelist` is deprecated and will be removed in the next major in favor of this. 221 | 222 | An array of plugins to always include. 223 | 224 | Valid options include any: 225 | 226 | - [Babel plugins](https://github.com/babel/babel-preset-env/blob/master/data/plugin-features.js) - both with (`babel-plugin-transform-es2015-spread`) and without prefix (`transform-es2015-spread`) are supported. 227 | 228 | - [Built-ins](https://github.com/babel/babel-preset-env/blob/master/data/built-in-features.js), such as `map`, `set`, or `object.assign`. 229 | 230 | This option is useful if there is a bug in a native implementation, or a combination of a non-supported feature + a supported one doesn't work. 231 | 232 | 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. 233 | 234 | > 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. 235 | 236 | ### `exclude` 237 | 238 | `Array`, defaults to `[]`. 239 | 240 | An array of plugins to always exclude/remove. 241 | 242 | The possible options are the same as the `include` option. 243 | 244 | This option is useful for "blacklisting" a transform like `transform-regenerator` if you don't use generators and don't want to include `regeneratorRuntime` (when using `useBuiltIns`) or for using another plugin like [fast-async](https://github.com/MatAtBread/fast-async) instead of [Babel's async-to-gen](http://babeljs.io/docs/plugins/transform-async-generator-functions/). 245 | 246 | ### `useBuiltIns` 247 | 248 | `boolean`, defaults to `false`. 249 | 250 | A way to apply `babel-preset-env` for polyfills (via "babel-polyfill"). 251 | 252 | > NOTE: This does not currently polyfill experimental/stage-x built-ins like the regular "babel-polyfill" does. 253 | > This will only work with npm >= 3 (which should be used with Babel 6 anyway) 254 | 255 | ``` 256 | npm install babel-polyfill --save 257 | ``` 258 | 259 | 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. 260 | 261 | > NOTE: Only use `require("babel-polyfill");` once in your whole app. 262 | > 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. 263 | > We recommend creating a single entry file that only contains the `require` statement. 264 | 265 | **In** 266 | 267 | ```js 268 | import "babel-polyfill"; 269 | ``` 270 | 271 | **Out (different based on environment)** 272 | 273 | ```js 274 | import "core-js/modules/es7.string.pad-start"; 275 | import "core-js/modules/es7.string.pad-end"; 276 | import "core-js/modules/web.timers"; 277 | import "core-js/modules/web.immediate"; 278 | import "core-js/modules/web.dom.iterable"; 279 | ``` 280 | 281 | This will also work for `core-js` directly (`import "core-js";`) 282 | 283 | ``` 284 | npm install core-js --save 285 | ``` 286 | 287 | --- 288 | 289 | ## Examples 290 | 291 | ### Export with various targets 292 | 293 | ```js 294 | export class A {} 295 | ``` 296 | 297 | #### Target only Chrome 52 298 | 299 | **.babelrc** 300 | 301 | ```json 302 | { 303 | "presets": [ 304 | ["env", { 305 | "targets": { 306 | "chrome": 52 307 | } 308 | }] 309 | ] 310 | } 311 | ``` 312 | 313 | **Out** 314 | 315 | ```js 316 | class A {} 317 | exports.A = A; 318 | ``` 319 | 320 | #### Target Chrome 52 with webpack 2/rollup and loose mode 321 | 322 | **.babelrc** 323 | 324 | ```json 325 | { 326 | "presets": [ 327 | ["env", { 328 | "targets": { 329 | "chrome": 52 330 | }, 331 | "modules": false, 332 | "loose": true 333 | }] 334 | ] 335 | } 336 | ``` 337 | 338 | **Out** 339 | 340 | ```js 341 | export class A {} 342 | ``` 343 | 344 | #### Target specific browsers via browserslist 345 | 346 | **.babelrc** 347 | 348 | ```json 349 | { 350 | "presets": [ 351 | ["env", { 352 | "targets": { 353 | "chrome": 52, 354 | "browsers": ["last 2 versions", "safari 7"] 355 | } 356 | }] 357 | ] 358 | } 359 | ``` 360 | 361 | **Out** 362 | 363 | ```js 364 | export var A = function A() { 365 | _classCallCheck(this, A); 366 | }; 367 | ``` 368 | 369 | #### Target latest node via `node: true` or `node: "current"` 370 | 371 | **.babelrc** 372 | 373 | ```json 374 | { 375 | "presets": [ 376 | ["env", { 377 | "targets": { 378 | "node": "current" 379 | } 380 | }] 381 | ] 382 | } 383 | ``` 384 | 385 | **Out** 386 | 387 | ```js 388 | class A {} 389 | exports.A = A; 390 | ``` 391 | 392 | ### Show debug output 393 | 394 | **.babelrc** 395 | 396 | ```json 397 | { 398 | "presets": [ 399 | [ "env", { 400 | "targets": { 401 | "safari": 10 402 | }, 403 | "modules": false, 404 | "useBuiltIns": true, 405 | "debug": true 406 | }] 407 | ] 408 | } 409 | ``` 410 | 411 | **stdout** 412 | 413 | ```sh 414 | Using targets: 415 | { 416 | "safari": 10 417 | } 418 | 419 | Modules transform: false 420 | 421 | Using plugins: 422 | transform-exponentiation-operator {} 423 | transform-async-to-generator {} 424 | 425 | Using polyfills: 426 | es7.object.values {} 427 | es7.object.entries {} 428 | es7.object.get-own-property-descriptors {} 429 | web.timers {} 430 | web.immediate {} 431 | web.dom.iterable {} 432 | ``` 433 | 434 | ### Include and exclude specific plugins/built-ins 435 | 436 | > always include arrow functions, explicitly exclude generators 437 | 438 | ```json 439 | { 440 | "presets": [ 441 | ["env", { 442 | "targets": { 443 | "browsers": ["last 2 versions", "safari >= 7"] 444 | }, 445 | "include": ["transform-es2015-arrow-functions", "es6.map"], 446 | "exclude": ["transform-regenerator", "es6.set"] 447 | }] 448 | ] 449 | } 450 | ``` 451 | 452 | ## Caveats 453 | 454 | If you get a `SyntaxError: Unexpected token ...` error when using the [object-rest-spread](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread) transform then make sure the plugin has been updated to, at least, `v6.19.0`. 455 | 456 | ## Other Cool Projects 457 | 458 | - [babel-preset-modern-browsers](https://github.com/christophehurpeau/babel-preset-modern-browsers) 459 | - ? 460 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | parsers: 3 | javascript: 4 | enable_partials: yes 5 | -------------------------------------------------------------------------------- /data/built-in-features.js: -------------------------------------------------------------------------------- 1 | // https://github.com/zloirock/core-js 2 | 3 | const typedArrayMethods = [ 4 | "typed arrays / %TypedArray%.from", 5 | "typed arrays / %TypedArray%.of", 6 | "typed arrays / %TypedArray%.prototype.subarray", 7 | "typed arrays / %TypedArray%.prototype.join", 8 | "typed arrays / %TypedArray%.prototype.indexOf", 9 | "typed arrays / %TypedArray%.prototype.lastIndexOf", 10 | "typed arrays / %TypedArray%.prototype.slice", 11 | "typed arrays / %TypedArray%.prototype.every", 12 | "typed arrays / %TypedArray%.prototype.filter", 13 | "typed arrays / %TypedArray%.prototype.forEach", 14 | "typed arrays / %TypedArray%.prototype.map", 15 | "typed arrays / %TypedArray%.prototype.reduce", 16 | "typed arrays / %TypedArray%.prototype.reduceRight", 17 | "typed arrays / %TypedArray%.prototype.reverse", 18 | "typed arrays / %TypedArray%.prototype.some", 19 | "typed arrays / %TypedArray%.prototype.sort", 20 | "typed arrays / %TypedArray%.prototype.copyWithin", 21 | "typed arrays / %TypedArray%.prototype.find", 22 | "typed arrays / %TypedArray%.prototype.findIndex", 23 | "typed arrays / %TypedArray%.prototype.fill", 24 | "typed arrays / %TypedArray%.prototype.keys", 25 | "typed arrays / %TypedArray%.prototype.values", 26 | "typed arrays / %TypedArray%.prototype.entries", 27 | "typed arrays / %TypedArray%.prototype[Symbol.iterator]", 28 | "typed arrays / %TypedArray%[Symbol.species]", 29 | ]; 30 | 31 | const es2015 = { 32 | "es6.typed.array-buffer": "typed arrays / ArrayBuffer[Symbol.species]", 33 | "es6.typed.data-view": "typed arrays / DataView", 34 | "es6.typed.int8-array": { 35 | features: ["typed arrays / Int8Array"].concat(typedArrayMethods) 36 | }, 37 | "es6.typed.uint8-array": { 38 | features: ["typed arrays / Uint8Array"].concat(typedArrayMethods) 39 | }, 40 | "es6.typed.uint8-clamped-array": { 41 | features: ["typed arrays / Uint8ClampedArray"].concat(typedArrayMethods) 42 | }, 43 | "es6.typed.int16-array": { 44 | features: ["typed arrays / Int16Array"].concat(typedArrayMethods) 45 | }, 46 | "es6.typed.uint16-array": { 47 | features: ["typed arrays / Uint16Array"].concat(typedArrayMethods) 48 | }, 49 | "es6.typed.int32-array": { 50 | features: ["typed arrays / Int32Array"].concat(typedArrayMethods) 51 | }, 52 | "es6.typed.uint32-array": { 53 | features: ["typed arrays / Uint32Array"].concat(typedArrayMethods) 54 | }, 55 | "es6.typed.float32-array": { 56 | features: ["typed arrays / Float32Array"].concat(typedArrayMethods) 57 | }, 58 | "es6.typed.float64-array": { 59 | features: ["typed arrays / Float64Array"].concat(typedArrayMethods) 60 | }, 61 | 62 | "es6.map": "Map", 63 | "es6.set": "Set", 64 | "es6.weak-map": "WeakMap", 65 | "es6.weak-set": "WeakSet", 66 | 67 | // Proxy not implementable 68 | 69 | "es6.reflect.apply": "Reflect / Reflect.apply", 70 | "es6.reflect.construct": "Reflect / Reflect.construct", 71 | "es6.reflect.define-property": "Reflect / Reflect.defineProperty", 72 | "es6.reflect.delete-property": "Reflect / Reflect.deleteProperty", 73 | "es6.reflect.get": "Reflect / Reflect.get", 74 | "es6.reflect.get-own-property-descriptor": "Reflect / Reflect.getOwnPropertyDescriptor", 75 | "es6.reflect.get-prototype-of": "Reflect / Reflect.getPrototypeOf", 76 | "es6.reflect.has": "Reflect / Reflect.has", 77 | "es6.reflect.is-extensible": "Reflect / Reflect.isExtensible", 78 | "es6.reflect.own-keys": "Reflect / Reflect.ownKeys", 79 | "es6.reflect.prevent-extensions": "Reflect / Reflect.preventExtensions", 80 | "es6.reflect.set": "Reflect / Reflect.set", 81 | "es6.reflect.set-prototype-of": "Reflect / Reflect.setPrototypeOf", 82 | 83 | "es6.promise": "Promise", 84 | 85 | "es6.symbol": { 86 | features: [ 87 | "Symbol", 88 | "Object static methods / Object.getOwnPropertySymbols", 89 | "well-known symbols / Symbol.hasInstance", 90 | "well-known symbols / Symbol.isConcatSpreadable", 91 | "well-known symbols / Symbol.iterator", 92 | "well-known symbols / Symbol.match", 93 | "well-known symbols / Symbol.replace", 94 | "well-known symbols / Symbol.search", 95 | "well-known symbols / Symbol.species", 96 | "well-known symbols / Symbol.split", 97 | "well-known symbols / Symbol.toPrimitive", 98 | "well-known symbols / Symbol.toStringTag", 99 | "well-known symbols / Symbol.unscopables", 100 | ] 101 | }, 102 | 103 | "es6.object.freeze": "Object static methods accept primitives / Object.freeze", 104 | "es6.object.seal": "Object static methods accept primitives / Object.seal", 105 | "es6.object.prevent-extensions": "Object static methods accept primitives / Object.preventExtensions", 106 | "es6.object.is-frozen": "Object static methods accept primitives / Object.isFrozen", 107 | "es6.object.is-sealed": "Object static methods accept primitives / Object.isSealed", 108 | "es6.object.is-extensible": "Object static methods accept primitives / Object.isExtensible", 109 | "es6.object.get-own-property-descriptor": 110 | "Object static methods accept primitives / Object.getOwnPropertyDescriptor", 111 | "es6.object.get-prototype-of": "Object static methods accept primitives / Object.getPrototypeOf", 112 | "es6.object.keys": "Object static methods accept primitives / Object.keys", 113 | "es6.object.get-own-property-names": "Object static methods accept primitives / Object.getOwnPropertyNames", 114 | 115 | "es6.object.assign": "Object static methods / Object.assign", 116 | "es6.object.is": "Object static methods / Object.is", 117 | "es6.object.set-prototype-of": "Object static methods / Object.setPrototypeOf", 118 | 119 | "es6.function.name": "function \"name\" property", 120 | 121 | "es6.string.raw": "String static methods / String.raw", 122 | "es6.string.from-code-point": "String static methods / String.fromCodePoint", 123 | 124 | "es6.string.code-point-at": "String.prototype methods / String.prototype.codePointAt", 125 | // "String.prototype methods / String.prototype.normalize" not implemented 126 | "es6.string.repeat": "String.prototype methods / String.prototype.repeat", 127 | "es6.string.starts-with": "String.prototype methods / String.prototype.startsWith", 128 | "es6.string.ends-with": "String.prototype methods / String.prototype.endsWith", 129 | "es6.string.includes": "String.prototype methods / String.prototype.includes", 130 | 131 | "es6.regexp.flags": "RegExp.prototype properties / RegExp.prototype.flags", 132 | "es6.regexp.match": "RegExp.prototype properties / RegExp.prototype[Symbol.match]", 133 | "es6.regexp.replace": "RegExp.prototype properties / RegExp.prototype[Symbol.replace]", 134 | "es6.regexp.split": "RegExp.prototype properties / RegExp.prototype[Symbol.split]", 135 | "es6.regexp.search": "RegExp.prototype properties / RegExp.prototype[Symbol.search]", 136 | 137 | "es6.array.from": "Array static methods / Array.from", 138 | "es6.array.of": "Array static methods / Array.of", 139 | 140 | "es6.array.copy-within": "Array.prototype methods / Array.prototype.copyWithin", 141 | "es6.array.find": "Array.prototype methods / Array.prototype.find", 142 | "es6.array.find-index": "Array.prototype methods / Array.prototype.findIndex", 143 | "es6.array.fill": "Array.prototype methods / Array.prototype.fill", 144 | 145 | "es6.array.iterator": { 146 | features: [ 147 | "Array.prototype methods / Array.prototype.keys", 148 | // can use Symbol.iterator, not implemented in many environments 149 | // "Array.prototype methods / Array.prototype.values", 150 | "Array.prototype methods / Array.prototype.entries", 151 | ] 152 | }, 153 | 154 | "es6.number.is-finite": "Number properties / Number.isFinite", 155 | "es6.number.is-integer": "Number properties / Number.isInteger", 156 | "es6.number.is-safe-integer": "Number properties / Number.isSafeInteger", 157 | "es6.number.is-nan": "Number properties / Number.isNaN", 158 | "es6.number.epsilon": "Number properties / Number.EPSILON", 159 | "es6.number.min-safe-integer": "Number properties / Number.MIN_SAFE_INTEGER", 160 | "es6.number.max-safe-integer": "Number properties / Number.MAX_SAFE_INTEGER", 161 | 162 | "es6.math.acosh": "Math methods / Math.acosh", 163 | "es6.math.asinh": "Math methods / Math.asinh", 164 | "es6.math.atanh": "Math methods / Math.atanh", 165 | "es6.math.cbrt": "Math methods / Math.cbrt", 166 | "es6.math.clz32": "Math methods / Math.clz32", 167 | "es6.math.cosh": "Math methods / Math.cosh", 168 | "es6.math.expm1": "Math methods / Math.expm1", 169 | "es6.math.fround": "Math methods / Math.fround", 170 | "es6.math.hypot": "Math methods / Math.hypot", 171 | "es6.math.imul": "Math methods / Math.imul", 172 | "es6.math.log1p": "Math methods / Math.log1p", 173 | "es6.math.log10": "Math methods / Math.log10", 174 | "es6.math.log2": "Math methods / Math.log2", 175 | "es6.math.sign": "Math methods / Math.sign", 176 | "es6.math.sinh": "Math methods / Math.sinh", 177 | "es6.math.tanh": "Math methods / Math.tanh", 178 | "es6.math.trunc": "Math methods / Math.trunc", 179 | }; 180 | 181 | const es2016 = { 182 | "es7.array.includes": "Array.prototype.includes", 183 | }; 184 | 185 | const es2017 = { 186 | "es7.object.values": "Object static methods / Object.values", 187 | "es7.object.entries": "Object static methods / Object.entries", 188 | "es7.object.get-own-property-descriptors": "Object static methods / Object.getOwnPropertyDescriptors", 189 | "es7.string.pad-start": "String padding / String.prototype.padStart", 190 | "es7.string.pad-end": "String padding / String.prototype.padEnd", 191 | }; 192 | 193 | module.exports = Object.assign({}, es2015, es2016, es2017); 194 | -------------------------------------------------------------------------------- /data/built-ins.json: -------------------------------------------------------------------------------- 1 | { 2 | "es6.typed.array-buffer": { 3 | "chrome": "51", 4 | "edge": "13", 5 | "firefox": "48", 6 | "safari": "10", 7 | "node": "6.5", 8 | "ios": "10", 9 | "opera": "38", 10 | "electron": "1.2" 11 | }, 12 | "es6.typed.data-view": { 13 | "chrome": "5", 14 | "opera": "12", 15 | "edge": "12", 16 | "firefox": "15", 17 | "safari": "5.1", 18 | "node": "0.12", 19 | "ie": "10", 20 | "android": "4", 21 | "ios": "6", 22 | "electron": "1.1" 23 | }, 24 | "es6.typed.int8-array": { 25 | "chrome": "51", 26 | "edge": "13", 27 | "firefox": "48", 28 | "safari": "10", 29 | "node": "6.5", 30 | "ios": "10", 31 | "opera": "38", 32 | "electron": "1.2" 33 | }, 34 | "es6.typed.uint8-array": { 35 | "chrome": "51", 36 | "edge": "13", 37 | "firefox": "48", 38 | "safari": "10", 39 | "node": "6.5", 40 | "ios": "10", 41 | "opera": "38", 42 | "electron": "1.2" 43 | }, 44 | "es6.typed.uint8-clamped-array": { 45 | "chrome": "51", 46 | "edge": "13", 47 | "firefox": "48", 48 | "safari": "10", 49 | "node": "6.5", 50 | "ios": "10", 51 | "opera": "38", 52 | "electron": "1.2" 53 | }, 54 | "es6.typed.int16-array": { 55 | "chrome": "51", 56 | "edge": "13", 57 | "firefox": "48", 58 | "safari": "10", 59 | "node": "6.5", 60 | "ios": "10", 61 | "opera": "38", 62 | "electron": "1.2" 63 | }, 64 | "es6.typed.uint16-array": { 65 | "chrome": "51", 66 | "edge": "13", 67 | "firefox": "48", 68 | "safari": "10", 69 | "node": "6.5", 70 | "ios": "10", 71 | "opera": "38", 72 | "electron": "1.2" 73 | }, 74 | "es6.typed.int32-array": { 75 | "chrome": "51", 76 | "edge": "13", 77 | "firefox": "48", 78 | "safari": "10", 79 | "node": "6.5", 80 | "ios": "10", 81 | "opera": "38", 82 | "electron": "1.2" 83 | }, 84 | "es6.typed.uint32-array": { 85 | "chrome": "51", 86 | "edge": "13", 87 | "firefox": "48", 88 | "safari": "10", 89 | "node": "6.5", 90 | "ios": "10", 91 | "opera": "38", 92 | "electron": "1.2" 93 | }, 94 | "es6.typed.float32-array": { 95 | "chrome": "51", 96 | "edge": "13", 97 | "firefox": "48", 98 | "safari": "10", 99 | "node": "6.5", 100 | "ios": "10", 101 | "opera": "38", 102 | "electron": "1.2" 103 | }, 104 | "es6.typed.float64-array": { 105 | "chrome": "51", 106 | "edge": "13", 107 | "firefox": "48", 108 | "safari": "10", 109 | "node": "6.5", 110 | "ios": "10", 111 | "opera": "38", 112 | "electron": "1.2" 113 | }, 114 | "es6.map": { 115 | "chrome": "51", 116 | "edge": "15", 117 | "firefox": "53", 118 | "safari": "10", 119 | "node": "6.5", 120 | "ios": "10", 121 | "opera": "38", 122 | "electron": "1.2" 123 | }, 124 | "es6.set": { 125 | "chrome": "51", 126 | "edge": "15", 127 | "firefox": "53", 128 | "safari": "10", 129 | "node": "6.5", 130 | "ios": "10", 131 | "opera": "38", 132 | "electron": "1.2" 133 | }, 134 | "es6.weak-map": { 135 | "chrome": "51", 136 | "edge": "15", 137 | "firefox": "53", 138 | "safari": "9", 139 | "node": "6.5", 140 | "ios": "9", 141 | "opera": "38", 142 | "electron": "1.2" 143 | }, 144 | "es6.weak-set": { 145 | "chrome": "51", 146 | "edge": "15", 147 | "firefox": "53", 148 | "safari": "9", 149 | "node": "6.5", 150 | "ios": "9", 151 | "opera": "38", 152 | "electron": "1.2" 153 | }, 154 | "es6.reflect.apply": { 155 | "chrome": "49", 156 | "edge": "12", 157 | "firefox": "42", 158 | "safari": "10", 159 | "node": "6", 160 | "ios": "10", 161 | "opera": "36", 162 | "electron": "1" 163 | }, 164 | "es6.reflect.construct": { 165 | "chrome": "49", 166 | "edge": "13", 167 | "firefox": "45", 168 | "safari": "10", 169 | "node": "6", 170 | "ios": "10", 171 | "opera": "36", 172 | "electron": "1" 173 | }, 174 | "es6.reflect.define-property": { 175 | "chrome": "49", 176 | "edge": "13", 177 | "firefox": "42", 178 | "safari": "10", 179 | "node": "6", 180 | "ios": "10", 181 | "opera": "36", 182 | "electron": "1" 183 | }, 184 | "es6.reflect.delete-property": { 185 | "chrome": "49", 186 | "edge": "12", 187 | "firefox": "42", 188 | "safari": "10", 189 | "node": "6", 190 | "ios": "10", 191 | "opera": "36", 192 | "electron": "1" 193 | }, 194 | "es6.reflect.get": { 195 | "chrome": "49", 196 | "edge": "12", 197 | "firefox": "42", 198 | "safari": "10", 199 | "node": "6", 200 | "ios": "10", 201 | "opera": "36", 202 | "electron": "1" 203 | }, 204 | "es6.reflect.get-own-property-descriptor": { 205 | "chrome": "49", 206 | "edge": "12", 207 | "firefox": "42", 208 | "safari": "10", 209 | "node": "6", 210 | "ios": "10", 211 | "opera": "36", 212 | "electron": "1" 213 | }, 214 | "es6.reflect.get-prototype-of": { 215 | "chrome": "49", 216 | "edge": "12", 217 | "firefox": "42", 218 | "safari": "10", 219 | "node": "6", 220 | "ios": "10", 221 | "opera": "36", 222 | "electron": "1" 223 | }, 224 | "es6.reflect.has": { 225 | "chrome": "49", 226 | "edge": "12", 227 | "firefox": "42", 228 | "safari": "10", 229 | "node": "6", 230 | "ios": "10", 231 | "opera": "36", 232 | "electron": "1" 233 | }, 234 | "es6.reflect.is-extensible": { 235 | "chrome": "49", 236 | "edge": "12", 237 | "firefox": "42", 238 | "safari": "10", 239 | "node": "6", 240 | "ios": "10", 241 | "opera": "36", 242 | "electron": "1" 243 | }, 244 | "es6.reflect.own-keys": { 245 | "chrome": "49", 246 | "edge": "12", 247 | "firefox": "42", 248 | "safari": "10", 249 | "node": "6", 250 | "ios": "10", 251 | "opera": "36", 252 | "electron": "1" 253 | }, 254 | "es6.reflect.prevent-extensions": { 255 | "chrome": "49", 256 | "edge": "12", 257 | "firefox": "42", 258 | "safari": "10", 259 | "node": "6", 260 | "ios": "10", 261 | "opera": "36", 262 | "electron": "1" 263 | }, 264 | "es6.reflect.set": { 265 | "chrome": "49", 266 | "edge": "12", 267 | "firefox": "42", 268 | "safari": "10", 269 | "node": "6", 270 | "ios": "10", 271 | "opera": "36", 272 | "electron": "1" 273 | }, 274 | "es6.reflect.set-prototype-of": { 275 | "chrome": "49", 276 | "edge": "12", 277 | "firefox": "42", 278 | "safari": "10", 279 | "node": "6", 280 | "ios": "10", 281 | "opera": "36", 282 | "electron": "1" 283 | }, 284 | "es6.promise": { 285 | "chrome": "51", 286 | "edge": "13", 287 | "firefox": "45", 288 | "safari": "10", 289 | "node": "6.5", 290 | "ios": "10", 291 | "opera": "38", 292 | "electron": "1.2" 293 | }, 294 | "es6.symbol": { 295 | "chrome": "51", 296 | "firefox": "51", 297 | "safari": "10", 298 | "node": "6.5", 299 | "ios": "10", 300 | "opera": "38", 301 | "electron": "1.2" 302 | }, 303 | "es6.object.freeze": { 304 | "chrome": "44", 305 | "edge": "12", 306 | "firefox": "35", 307 | "safari": "9", 308 | "node": "4", 309 | "ios": "9", 310 | "opera": "31", 311 | "electron": "0.31" 312 | }, 313 | "es6.object.seal": { 314 | "chrome": "44", 315 | "edge": "12", 316 | "firefox": "35", 317 | "safari": "9", 318 | "node": "4", 319 | "ios": "9", 320 | "opera": "31", 321 | "electron": "0.31" 322 | }, 323 | "es6.object.prevent-extensions": { 324 | "chrome": "44", 325 | "edge": "12", 326 | "firefox": "35", 327 | "safari": "9", 328 | "node": "4", 329 | "ios": "9", 330 | "opera": "31", 331 | "electron": "0.31" 332 | }, 333 | "es6.object.is-frozen": { 334 | "chrome": "44", 335 | "edge": "12", 336 | "firefox": "35", 337 | "safari": "9", 338 | "node": "4", 339 | "ios": "9", 340 | "opera": "31", 341 | "electron": "0.31" 342 | }, 343 | "es6.object.is-sealed": { 344 | "chrome": "44", 345 | "edge": "12", 346 | "firefox": "35", 347 | "safari": "9", 348 | "node": "4", 349 | "ios": "9", 350 | "opera": "31", 351 | "electron": "0.31" 352 | }, 353 | "es6.object.is-extensible": { 354 | "chrome": "44", 355 | "edge": "12", 356 | "firefox": "35", 357 | "safari": "9", 358 | "node": "4", 359 | "ios": "9", 360 | "opera": "31", 361 | "electron": "0.31" 362 | }, 363 | "es6.object.get-own-property-descriptor": { 364 | "chrome": "44", 365 | "edge": "12", 366 | "firefox": "35", 367 | "safari": "9", 368 | "node": "4", 369 | "ios": "9", 370 | "opera": "31", 371 | "electron": "0.31" 372 | }, 373 | "es6.object.get-prototype-of": { 374 | "chrome": "44", 375 | "edge": "12", 376 | "firefox": "3.5", 377 | "safari": "9", 378 | "node": "4", 379 | "ios": "9", 380 | "opera": "31", 381 | "electron": "0.31" 382 | }, 383 | "es6.object.keys": { 384 | "chrome": "40", 385 | "edge": "12", 386 | "firefox": "35", 387 | "safari": "9", 388 | "node": "4", 389 | "ios": "9", 390 | "opera": "27", 391 | "electron": "0.21" 392 | }, 393 | "es6.object.get-own-property-names": { 394 | "chrome": "40", 395 | "edge": "12", 396 | "firefox": "33", 397 | "safari": "9", 398 | "node": "4", 399 | "ios": "9", 400 | "opera": "27", 401 | "electron": "0.21" 402 | }, 403 | "es6.object.assign": { 404 | "chrome": "45", 405 | "edge": "12", 406 | "firefox": "34", 407 | "safari": "9", 408 | "node": "4", 409 | "ios": "9", 410 | "opera": "32", 411 | "electron": "0.35" 412 | }, 413 | "es6.object.is": { 414 | "chrome": "19", 415 | "edge": "12", 416 | "firefox": "22", 417 | "safari": "9", 418 | "node": "0.12", 419 | "android": "4.1", 420 | "ios": "9", 421 | "electron": "0.2" 422 | }, 423 | "es6.object.set-prototype-of": { 424 | "chrome": "34", 425 | "edge": "12", 426 | "firefox": "31", 427 | "safari": "9", 428 | "node": "0.12", 429 | "ie": "11", 430 | "ios": "9", 431 | "opera": "21", 432 | "electron": "0.2" 433 | }, 434 | "es6.function.name": { 435 | "chrome": "51", 436 | "firefox": "53", 437 | "safari": "10", 438 | "node": "6.5", 439 | "ios": "10", 440 | "opera": "38", 441 | "electron": "1.2" 442 | }, 443 | "es6.string.raw": { 444 | "chrome": "41", 445 | "edge": "12", 446 | "firefox": "34", 447 | "safari": "9", 448 | "node": "4", 449 | "ios": "9", 450 | "opera": "28", 451 | "electron": "0.24" 452 | }, 453 | "es6.string.from-code-point": { 454 | "chrome": "41", 455 | "edge": "12", 456 | "firefox": "29", 457 | "safari": "9", 458 | "node": "4", 459 | "ios": "9", 460 | "opera": "28", 461 | "electron": "0.24" 462 | }, 463 | "es6.string.code-point-at": { 464 | "chrome": "41", 465 | "edge": "12", 466 | "firefox": "29", 467 | "safari": "9", 468 | "node": "4", 469 | "ios": "9", 470 | "opera": "28", 471 | "electron": "0.24" 472 | }, 473 | "es6.string.repeat": { 474 | "chrome": "41", 475 | "edge": "12", 476 | "firefox": "24", 477 | "safari": "9", 478 | "node": "4", 479 | "ios": "9", 480 | "opera": "28", 481 | "electron": "0.24" 482 | }, 483 | "es6.string.starts-with": { 484 | "chrome": "41", 485 | "edge": "12", 486 | "firefox": "29", 487 | "safari": "9", 488 | "node": "4", 489 | "ios": "9", 490 | "opera": "28", 491 | "electron": "0.24" 492 | }, 493 | "es6.string.ends-with": { 494 | "chrome": "41", 495 | "edge": "12", 496 | "firefox": "29", 497 | "safari": "9", 498 | "node": "4", 499 | "ios": "9", 500 | "opera": "28", 501 | "electron": "0.24" 502 | }, 503 | "es6.string.includes": { 504 | "chrome": "41", 505 | "edge": "12", 506 | "firefox": "40", 507 | "safari": "9", 508 | "node": "4", 509 | "ios": "9", 510 | "opera": "28", 511 | "electron": "0.24" 512 | }, 513 | "es6.regexp.flags": { 514 | "chrome": "49", 515 | "firefox": "37", 516 | "safari": "9", 517 | "node": "6", 518 | "ios": "9", 519 | "opera": "36", 520 | "electron": "1" 521 | }, 522 | "es6.regexp.match": { 523 | "chrome": "50", 524 | "firefox": "49", 525 | "safari": "10", 526 | "node": "6", 527 | "ios": "10", 528 | "opera": "37", 529 | "electron": "1.1" 530 | }, 531 | "es6.regexp.replace": { 532 | "chrome": "50", 533 | "firefox": "49", 534 | "safari": "10", 535 | "node": "6", 536 | "ios": "10", 537 | "opera": "37", 538 | "electron": "1.1" 539 | }, 540 | "es6.regexp.split": { 541 | "chrome": "50", 542 | "firefox": "49", 543 | "safari": "10", 544 | "node": "6", 545 | "ios": "10", 546 | "opera": "37", 547 | "electron": "1.1" 548 | }, 549 | "es6.regexp.search": { 550 | "chrome": "50", 551 | "firefox": "49", 552 | "safari": "10", 553 | "node": "6", 554 | "ios": "10", 555 | "opera": "37", 556 | "electron": "1.1" 557 | }, 558 | "es6.array.from": { 559 | "chrome": "51", 560 | "edge": "15", 561 | "firefox": "36", 562 | "safari": "10", 563 | "node": "6.5", 564 | "ios": "10", 565 | "opera": "38", 566 | "electron": "1.2" 567 | }, 568 | "es6.array.of": { 569 | "chrome": "45", 570 | "edge": "12", 571 | "firefox": "25", 572 | "safari": "9", 573 | "node": "4", 574 | "ios": "9", 575 | "opera": "32", 576 | "electron": "0.35" 577 | }, 578 | "es6.array.copy-within": { 579 | "chrome": "45", 580 | "edge": "12", 581 | "firefox": "32", 582 | "safari": "9", 583 | "node": "4", 584 | "ios": "9", 585 | "opera": "32", 586 | "electron": "0.35" 587 | }, 588 | "es6.array.find": { 589 | "chrome": "45", 590 | "edge": "12", 591 | "firefox": "25", 592 | "safari": "7.1", 593 | "node": "4", 594 | "ios": "8", 595 | "opera": "32", 596 | "electron": "0.35" 597 | }, 598 | "es6.array.find-index": { 599 | "chrome": "45", 600 | "edge": "12", 601 | "firefox": "25", 602 | "safari": "7.1", 603 | "node": "4", 604 | "ios": "8", 605 | "opera": "32", 606 | "electron": "0.35" 607 | }, 608 | "es6.array.fill": { 609 | "chrome": "45", 610 | "edge": "12", 611 | "firefox": "31", 612 | "safari": "7.1", 613 | "node": "4", 614 | "ios": "8", 615 | "opera": "32", 616 | "electron": "0.35" 617 | }, 618 | "es6.array.iterator": { 619 | "chrome": "38", 620 | "edge": "12", 621 | "firefox": "28", 622 | "safari": "7.1", 623 | "node": "0.12", 624 | "ios": "8", 625 | "opera": "25", 626 | "electron": "0.2" 627 | }, 628 | "es6.number.is-finite": { 629 | "chrome": "19", 630 | "edge": "12", 631 | "firefox": "16", 632 | "safari": "9", 633 | "node": "0.12", 634 | "android": "4.1", 635 | "ios": "9", 636 | "electron": "0.2" 637 | }, 638 | "es6.number.is-integer": { 639 | "chrome": "34", 640 | "edge": "12", 641 | "firefox": "16", 642 | "safari": "9", 643 | "node": "0.12", 644 | "ios": "9", 645 | "opera": "21", 646 | "electron": "0.2" 647 | }, 648 | "es6.number.is-safe-integer": { 649 | "chrome": "34", 650 | "edge": "12", 651 | "firefox": "32", 652 | "safari": "9", 653 | "node": "0.12", 654 | "ios": "9", 655 | "opera": "21", 656 | "electron": "0.2" 657 | }, 658 | "es6.number.is-nan": { 659 | "chrome": "19", 660 | "edge": "12", 661 | "firefox": "15", 662 | "safari": "9", 663 | "node": "0.12", 664 | "android": "4.1", 665 | "ios": "9", 666 | "electron": "0.2" 667 | }, 668 | "es6.number.epsilon": { 669 | "chrome": "34", 670 | "edge": "12", 671 | "firefox": "25", 672 | "safari": "9", 673 | "node": "0.12", 674 | "ios": "9", 675 | "opera": "21", 676 | "electron": "0.2" 677 | }, 678 | "es6.number.min-safe-integer": { 679 | "chrome": "34", 680 | "edge": "12", 681 | "firefox": "31", 682 | "safari": "9", 683 | "node": "0.12", 684 | "ios": "9", 685 | "opera": "21", 686 | "electron": "0.2" 687 | }, 688 | "es6.number.max-safe-integer": { 689 | "chrome": "34", 690 | "edge": "12", 691 | "firefox": "31", 692 | "safari": "9", 693 | "node": "0.12", 694 | "ios": "9", 695 | "opera": "21", 696 | "electron": "0.2" 697 | }, 698 | "es6.math.acosh": { 699 | "chrome": "38", 700 | "edge": "12", 701 | "firefox": "25", 702 | "safari": "7.1", 703 | "node": "0.12", 704 | "ios": "8", 705 | "opera": "25", 706 | "electron": "0.2" 707 | }, 708 | "es6.math.asinh": { 709 | "chrome": "38", 710 | "edge": "12", 711 | "firefox": "25", 712 | "safari": "7.1", 713 | "node": "0.12", 714 | "ios": "8", 715 | "opera": "25", 716 | "electron": "0.2" 717 | }, 718 | "es6.math.atanh": { 719 | "chrome": "38", 720 | "edge": "12", 721 | "firefox": "25", 722 | "safari": "7.1", 723 | "node": "0.12", 724 | "ios": "8", 725 | "opera": "25", 726 | "electron": "0.2" 727 | }, 728 | "es6.math.cbrt": { 729 | "chrome": "38", 730 | "edge": "12", 731 | "firefox": "25", 732 | "safari": "7.1", 733 | "node": "0.12", 734 | "ios": "8", 735 | "opera": "25", 736 | "electron": "0.2" 737 | }, 738 | "es6.math.clz32": { 739 | "chrome": "38", 740 | "edge": "12", 741 | "firefox": "31", 742 | "safari": "9", 743 | "node": "0.12", 744 | "ios": "9", 745 | "opera": "25", 746 | "electron": "0.2" 747 | }, 748 | "es6.math.cosh": { 749 | "chrome": "38", 750 | "edge": "12", 751 | "firefox": "25", 752 | "safari": "7.1", 753 | "node": "0.12", 754 | "ios": "8", 755 | "opera": "25", 756 | "electron": "0.2" 757 | }, 758 | "es6.math.expm1": { 759 | "chrome": "38", 760 | "edge": "12", 761 | "firefox": "25", 762 | "safari": "7.1", 763 | "node": "0.12", 764 | "ios": "8", 765 | "opera": "25", 766 | "electron": "0.2" 767 | }, 768 | "es6.math.fround": { 769 | "chrome": "38", 770 | "edge": "12", 771 | "firefox": "26", 772 | "safari": "7.1", 773 | "node": "0.12", 774 | "ios": "8", 775 | "opera": "25", 776 | "electron": "0.2" 777 | }, 778 | "es6.math.hypot": { 779 | "chrome": "38", 780 | "edge": "12", 781 | "firefox": "27", 782 | "safari": "7.1", 783 | "node": "0.12", 784 | "ios": "8", 785 | "opera": "25", 786 | "electron": "0.2" 787 | }, 788 | "es6.math.imul": { 789 | "chrome": "30", 790 | "edge": "12", 791 | "firefox": "23", 792 | "safari": "7", 793 | "node": "0.12", 794 | "android": "4.4", 795 | "ios": "7", 796 | "opera": "17", 797 | "electron": "0.2" 798 | }, 799 | "es6.math.log1p": { 800 | "chrome": "38", 801 | "edge": "12", 802 | "firefox": "25", 803 | "safari": "7.1", 804 | "node": "0.12", 805 | "ios": "8", 806 | "opera": "25", 807 | "electron": "0.2" 808 | }, 809 | "es6.math.log10": { 810 | "chrome": "38", 811 | "edge": "12", 812 | "firefox": "25", 813 | "safari": "7.1", 814 | "node": "0.12", 815 | "ios": "8", 816 | "opera": "25", 817 | "electron": "0.2" 818 | }, 819 | "es6.math.log2": { 820 | "chrome": "38", 821 | "edge": "12", 822 | "firefox": "25", 823 | "safari": "7.1", 824 | "node": "0.12", 825 | "ios": "8", 826 | "opera": "25", 827 | "electron": "0.2" 828 | }, 829 | "es6.math.sign": { 830 | "chrome": "38", 831 | "edge": "12", 832 | "firefox": "25", 833 | "safari": "9", 834 | "node": "0.12", 835 | "ios": "9", 836 | "opera": "25", 837 | "electron": "0.2" 838 | }, 839 | "es6.math.sinh": { 840 | "chrome": "38", 841 | "edge": "12", 842 | "firefox": "25", 843 | "safari": "7.1", 844 | "node": "0.12", 845 | "ios": "8", 846 | "opera": "25", 847 | "electron": "0.2" 848 | }, 849 | "es6.math.tanh": { 850 | "chrome": "38", 851 | "edge": "12", 852 | "firefox": "25", 853 | "safari": "7.1", 854 | "node": "0.12", 855 | "ios": "8", 856 | "opera": "25", 857 | "electron": "0.2" 858 | }, 859 | "es6.math.trunc": { 860 | "chrome": "38", 861 | "edge": "12", 862 | "firefox": "25", 863 | "safari": "7.1", 864 | "node": "0.12", 865 | "ios": "8", 866 | "opera": "25", 867 | "electron": "0.2" 868 | }, 869 | "es7.array.includes": { 870 | "chrome": "47", 871 | "edge": "14", 872 | "firefox": "43", 873 | "safari": "10", 874 | "node": "6", 875 | "ios": "10", 876 | "opera": "34", 877 | "electron": "0.36" 878 | }, 879 | "es7.object.values": { 880 | "chrome": "54", 881 | "edge": "14", 882 | "firefox": "47", 883 | "safari": "10.1", 884 | "node": "7", 885 | "ios": "10.3", 886 | "opera": "41", 887 | "electron": "1.5" 888 | }, 889 | "es7.object.entries": { 890 | "chrome": "54", 891 | "edge": "14", 892 | "firefox": "47", 893 | "safari": "10.1", 894 | "node": "7", 895 | "ios": "10.3", 896 | "opera": "41", 897 | "electron": "1.5" 898 | }, 899 | "es7.object.get-own-property-descriptors": { 900 | "chrome": "54", 901 | "edge": "15", 902 | "firefox": "50", 903 | "safari": "10.1", 904 | "node": "7", 905 | "ios": "10.3", 906 | "opera": "41", 907 | "electron": "1.5" 908 | }, 909 | "es7.string.pad-start": { 910 | "chrome": "57", 911 | "edge": "15", 912 | "firefox": "48", 913 | "safari": "10", 914 | "node": "8", 915 | "ios": "10", 916 | "opera": "44", 917 | "electron": "1.7" 918 | }, 919 | "es7.string.pad-end": { 920 | "chrome": "57", 921 | "edge": "15", 922 | "firefox": "48", 923 | "safari": "10", 924 | "node": "8", 925 | "ios": "10", 926 | "opera": "44", 927 | "electron": "1.7" 928 | } 929 | } 930 | -------------------------------------------------------------------------------- /data/plugin-features.js: -------------------------------------------------------------------------------- 1 | const es2015 = { 2 | "check-es2015-constants": { 3 | features: [ 4 | "const", 5 | ], 6 | }, 7 | "transform-es2015-arrow-functions": { 8 | features: [ 9 | "arrow functions", 10 | ], 11 | }, 12 | "transform-es2015-block-scoped-functions": { 13 | features: [ 14 | "block-level function declaration" 15 | ], 16 | }, 17 | "transform-es2015-block-scoping": { 18 | features: [ 19 | "const", 20 | "let", 21 | ], 22 | }, 23 | "transform-es2015-classes": { 24 | features: [ 25 | "class", 26 | "super", 27 | ], 28 | }, 29 | "transform-es2015-computed-properties": { 30 | features: [ 31 | "object literal extensions / computed properties", 32 | ], 33 | }, 34 | "transform-es2015-destructuring": { 35 | features: [ 36 | "destructuring, assignment", 37 | "destructuring, declarations", 38 | "destructuring, parameters", 39 | ], 40 | }, 41 | "transform-es2015-duplicate-keys": { 42 | features: [ 43 | "miscellaneous / duplicate property names in strict mode", 44 | ], 45 | }, 46 | "transform-es2015-for-of": { 47 | features: [ 48 | "for..of loops", 49 | ], 50 | }, 51 | "transform-es2015-function-name": { 52 | features: [ 53 | "function \"name\" property", 54 | ] 55 | }, 56 | "transform-es2015-literals": { 57 | features: [ 58 | "Unicode code point escapes", 59 | ], 60 | }, 61 | "transform-es2015-object-super": { 62 | features: [ 63 | "super", 64 | ], 65 | }, 66 | "transform-es2015-parameters": { 67 | features: [ 68 | "default function parameters", 69 | "rest parameters", 70 | ], 71 | }, 72 | "transform-es2015-shorthand-properties": { 73 | features: [ 74 | "object literal extensions / shorthand properties", 75 | ], 76 | }, 77 | "transform-es2015-spread": { 78 | features: [ 79 | "spread (...) operator", 80 | ], 81 | }, 82 | "transform-es2015-sticky-regex": { 83 | features: [ 84 | "RegExp \"y\" and \"u\" flags / \"y\" flag, lastIndex", 85 | "RegExp \"y\" and \"u\" flags / \"y\" flag", 86 | ], 87 | }, 88 | "transform-es2015-template-literals": { 89 | features: [ 90 | "template literals", 91 | ], 92 | }, 93 | "transform-es2015-typeof-symbol": { 94 | features: [ 95 | "Symbol / typeof support" 96 | ], 97 | }, 98 | "transform-es2015-unicode-regex": { 99 | features: [ 100 | "RegExp \"y\" and \"u\" flags / \"u\" flag, case folding", 101 | "RegExp \"y\" and \"u\" flags / \"u\" flag, Unicode code point escapes", 102 | "RegExp \"y\" and \"u\" flags / \"u\" flag", 103 | ], 104 | }, 105 | "transform-regenerator": { 106 | features: [ 107 | "generators", 108 | ], 109 | } 110 | }; 111 | 112 | const es2016 = { 113 | "transform-exponentiation-operator": { 114 | features: [ 115 | "exponentiation (**) operator", 116 | ], 117 | } 118 | }; 119 | 120 | const es2017 = { 121 | "transform-async-to-generator": { 122 | features: [ 123 | "async functions", 124 | ], 125 | }, 126 | "syntax-trailing-function-commas": { 127 | features: [ 128 | "trailing commas in function syntax", 129 | ], 130 | } 131 | }; 132 | 133 | module.exports = Object.assign({}, es2015, es2016, es2017); 134 | -------------------------------------------------------------------------------- /data/plugins.json: -------------------------------------------------------------------------------- 1 | { 2 | "check-es2015-constants": { 3 | "chrome": "49", 4 | "edge": "14", 5 | "firefox": "51", 6 | "safari": "10", 7 | "node": "6", 8 | "ios": "10", 9 | "opera": "36", 10 | "electron": "1" 11 | }, 12 | "transform-es2015-arrow-functions": { 13 | "chrome": "47", 14 | "edge": "13", 15 | "firefox": "45", 16 | "safari": "10", 17 | "node": "6", 18 | "ios": "10", 19 | "opera": "34", 20 | "electron": "0.36" 21 | }, 22 | "transform-es2015-block-scoped-functions": { 23 | "chrome": "41", 24 | "edge": "12", 25 | "firefox": "46", 26 | "safari": "10", 27 | "node": "4", 28 | "ie": "11", 29 | "ios": "10", 30 | "opera": "28", 31 | "electron": "0.24" 32 | }, 33 | "transform-es2015-block-scoping": { 34 | "chrome": "49", 35 | "edge": "14", 36 | "firefox": "51", 37 | "safari": "10", 38 | "node": "6", 39 | "ios": "10", 40 | "opera": "36", 41 | "electron": "1" 42 | }, 43 | "transform-es2015-classes": { 44 | "chrome": "46", 45 | "edge": "13", 46 | "firefox": "45", 47 | "safari": "10", 48 | "node": "5", 49 | "ios": "10", 50 | "opera": "33", 51 | "electron": "0.36" 52 | }, 53 | "transform-es2015-computed-properties": { 54 | "chrome": "44", 55 | "edge": "12", 56 | "firefox": "34", 57 | "safari": "7.1", 58 | "node": "4", 59 | "ios": "8", 60 | "opera": "31", 61 | "electron": "0.31" 62 | }, 63 | "transform-es2015-destructuring": { 64 | "chrome": "51", 65 | "firefox": "53", 66 | "safari": "10", 67 | "node": "6.5", 68 | "ios": "10", 69 | "opera": "38", 70 | "electron": "1.2" 71 | }, 72 | "transform-es2015-duplicate-keys": { 73 | "chrome": "42", 74 | "edge": "12", 75 | "firefox": "34", 76 | "safari": "9", 77 | "node": "4", 78 | "ios": "9", 79 | "opera": "29", 80 | "electron": "0.27" 81 | }, 82 | "transform-es2015-for-of": { 83 | "chrome": "51", 84 | "edge": "15", 85 | "firefox": "53", 86 | "safari": "10", 87 | "node": "6.5", 88 | "ios": "10", 89 | "opera": "38", 90 | "electron": "1.2" 91 | }, 92 | "transform-es2015-function-name": { 93 | "chrome": "51", 94 | "firefox": "53", 95 | "safari": "10", 96 | "node": "6.5", 97 | "ios": "10", 98 | "opera": "38", 99 | "electron": "1.2" 100 | }, 101 | "transform-es2015-literals": { 102 | "chrome": "44", 103 | "edge": "12", 104 | "firefox": "53", 105 | "safari": "9", 106 | "node": "4", 107 | "ios": "9", 108 | "opera": "31", 109 | "electron": "0.31" 110 | }, 111 | "transform-es2015-object-super": { 112 | "chrome": "46", 113 | "edge": "13", 114 | "firefox": "45", 115 | "safari": "10", 116 | "node": "5", 117 | "ios": "10", 118 | "opera": "33", 119 | "electron": "0.36" 120 | }, 121 | "transform-es2015-parameters": { 122 | "chrome": "49", 123 | "edge": "14", 124 | "firefox": "53", 125 | "safari": "10", 126 | "node": "6", 127 | "ios": "10", 128 | "opera": "36", 129 | "electron": "1" 130 | }, 131 | "transform-es2015-shorthand-properties": { 132 | "chrome": "43", 133 | "edge": "12", 134 | "firefox": "33", 135 | "safari": "9", 136 | "node": "4", 137 | "ios": "9", 138 | "opera": "30", 139 | "electron": "0.29" 140 | }, 141 | "transform-es2015-spread": { 142 | "chrome": "46", 143 | "edge": "13", 144 | "firefox": "36", 145 | "safari": "10", 146 | "node": "5", 147 | "ios": "10", 148 | "opera": "33", 149 | "electron": "0.36" 150 | }, 151 | "transform-es2015-sticky-regex": { 152 | "chrome": "49", 153 | "edge": "13", 154 | "firefox": "3", 155 | "safari": "10", 156 | "node": "6", 157 | "ios": "10", 158 | "opera": "36", 159 | "electron": "1" 160 | }, 161 | "transform-es2015-template-literals": { 162 | "chrome": "41", 163 | "edge": "13", 164 | "firefox": "34", 165 | "safari": "9", 166 | "node": "4", 167 | "ios": "9", 168 | "opera": "28", 169 | "electron": "0.24" 170 | }, 171 | "transform-es2015-typeof-symbol": { 172 | "chrome": "38", 173 | "edge": "12", 174 | "firefox": "36", 175 | "safari": "9", 176 | "node": "0.12", 177 | "ios": "9", 178 | "opera": "25", 179 | "electron": "0.2" 180 | }, 181 | "transform-es2015-unicode-regex": { 182 | "chrome": "50", 183 | "edge": "13", 184 | "firefox": "46", 185 | "safari": "10", 186 | "node": "6", 187 | "ios": "10", 188 | "opera": "37", 189 | "electron": "1.1" 190 | }, 191 | "transform-regenerator": { 192 | "chrome": "50", 193 | "edge": "13", 194 | "firefox": "53", 195 | "safari": "10", 196 | "node": "6", 197 | "ios": "10", 198 | "opera": "37", 199 | "electron": "1.1" 200 | }, 201 | "transform-exponentiation-operator": { 202 | "chrome": "52", 203 | "edge": "14", 204 | "firefox": "52", 205 | "safari": "10.1", 206 | "node": "7", 207 | "ios": "10.3", 208 | "opera": "39", 209 | "electron": "1.3" 210 | }, 211 | "transform-async-to-generator": { 212 | "chrome": "55", 213 | "edge": "15", 214 | "firefox": "52", 215 | "safari": "10.1", 216 | "node": "7.6", 217 | "ios": "10.3", 218 | "opera": "42", 219 | "electron": "1.6" 220 | }, 221 | "syntax-trailing-function-commas": { 222 | "chrome": "58", 223 | "edge": "14", 224 | "firefox": "52", 225 | "safari": "10", 226 | "node": "8", 227 | "ios": "10", 228 | "opera": "45", 229 | "electron": "1.7" 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-preset-env", 3 | "version": "1.7.0", 4 | "description": "A Babel preset for each environment.", 5 | "author": "Henry Zhu ", 6 | "homepage": "https://babeljs.io/", 7 | "license": "MIT", 8 | "repository": "https://github.com/babel/babel-preset-env", 9 | "main": "lib/index.js", 10 | "scripts": { 11 | "build": "rimraf lib && babel src -d lib", 12 | "build-data": "node ./scripts/build-data.js", 13 | "changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'", 14 | "coverage": "BABEL_ENV=test nyc npm run test", 15 | "coverage-ci": "nyc report --reporter=json && codecov -f coverage/coverage-final.json", 16 | "dev": "babel -w src -d lib", 17 | "fix": "eslint . --fix", 18 | "lint": "eslint .", 19 | "prepublish": "npm run build", 20 | "test": "npm run build && npm run test-only", 21 | "test-ci": "nyc npm run test", 22 | "test-only": "mocha ./test --compilers js:babel-register -t 10000" 23 | }, 24 | "dependencies": { 25 | "babel-plugin-check-es2015-constants": "^6.22.0", 26 | "babel-plugin-syntax-trailing-function-commas": "^6.22.0", 27 | "babel-plugin-transform-async-to-generator": "^6.22.0", 28 | "babel-plugin-transform-es2015-arrow-functions": "^6.22.0", 29 | "babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0", 30 | "babel-plugin-transform-es2015-block-scoping": "^6.23.0", 31 | "babel-plugin-transform-es2015-classes": "^6.23.0", 32 | "babel-plugin-transform-es2015-computed-properties": "^6.22.0", 33 | "babel-plugin-transform-es2015-destructuring": "^6.23.0", 34 | "babel-plugin-transform-es2015-duplicate-keys": "^6.22.0", 35 | "babel-plugin-transform-es2015-for-of": "^6.23.0", 36 | "babel-plugin-transform-es2015-function-name": "^6.22.0", 37 | "babel-plugin-transform-es2015-literals": "^6.22.0", 38 | "babel-plugin-transform-es2015-modules-amd": "^6.22.0", 39 | "babel-plugin-transform-es2015-modules-commonjs": "^6.23.0", 40 | "babel-plugin-transform-es2015-modules-systemjs": "^6.23.0", 41 | "babel-plugin-transform-es2015-modules-umd": "^6.23.0", 42 | "babel-plugin-transform-es2015-object-super": "^6.22.0", 43 | "babel-plugin-transform-es2015-parameters": "^6.23.0", 44 | "babel-plugin-transform-es2015-shorthand-properties": "^6.22.0", 45 | "babel-plugin-transform-es2015-spread": "^6.22.0", 46 | "babel-plugin-transform-es2015-sticky-regex": "^6.22.0", 47 | "babel-plugin-transform-es2015-template-literals": "^6.22.0", 48 | "babel-plugin-transform-es2015-typeof-symbol": "^6.23.0", 49 | "babel-plugin-transform-es2015-unicode-regex": "^6.22.0", 50 | "babel-plugin-transform-exponentiation-operator": "^6.22.0", 51 | "babel-plugin-transform-regenerator": "^6.22.0", 52 | "browserslist": "^3.2.6", 53 | "invariant": "^2.2.2", 54 | "semver": "^5.3.0" 55 | }, 56 | "devDependencies": { 57 | "babel-cli": "^6.23.0", 58 | "babel-eslint": "^7.1.1", 59 | "babel-helper-fixtures": "^6.22.0", 60 | "babel-helper-plugin-test-runner": "^6.22.0", 61 | "babel-plugin-istanbul": "^3.1.2", 62 | "babel-preset-env": "^1.4.0", 63 | "babel-register": "^6.23.0", 64 | "chai": "^3.5.0", 65 | "codecov": "^1.0.1", 66 | "compat-table": "kangax/compat-table#957f1ff15972e8fb2892a172f985e9af27bf1c75", 67 | "eslint": "^3.17.1", 68 | "eslint-config-babel": "^6.0.0", 69 | "eslint-plugin-flowtype": "^2.29.1", 70 | "fs-extra": "~2.0.0", 71 | "lodash": "^4.17.4", 72 | "mocha": "^3.2.0", 73 | "nyc": "^10.1.2", 74 | "electron-to-chromium": "^1.3.11", 75 | "rimraf": "^2.6.1" 76 | }, 77 | "babel": { 78 | "presets": [ 79 | [ 80 | "env", 81 | { 82 | "loose": true 83 | } 84 | ] 85 | ], 86 | "env": { 87 | "test": { 88 | "plugins": [ 89 | "istanbul" 90 | ] 91 | } 92 | } 93 | }, 94 | "nyc": { 95 | "all": true, 96 | "include": [ 97 | "src/*.js" 98 | ], 99 | "instrument": false, 100 | "sourceMap": false 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /scripts/build-data.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const fs = require("fs"); 4 | const path = require("path"); 5 | 6 | const flatten = require("lodash/flatten"); 7 | const flattenDeep = require("lodash/flattenDeep"); 8 | const mapValues = require("lodash/mapValues"); 9 | const pickBy = require("lodash/pickBy"); 10 | const electronToChromiumVersions = require("electron-to-chromium").versions; 11 | const pluginFeatures = require("../data/plugin-features"); 12 | const builtInFeatures = require("../data/built-in-features"); 13 | 14 | const electronToChromiumKeys = Object.keys(electronToChromiumVersions).reverse(); 15 | 16 | const chromiumToElectronMap = electronToChromiumKeys.reduce( 17 | (all, electron) => { 18 | all[electronToChromiumVersions[electron]] = +electron; 19 | return all; 20 | } 21 | , {}); 22 | const chromiumToElectronVersions = Object.keys(chromiumToElectronMap); 23 | 24 | const findClosestElectronVersion = (targetVersion) => { 25 | const chromiumVersionsLength = chromiumToElectronVersions.length; 26 | const maxChromium = +chromiumToElectronVersions[chromiumVersionsLength - 1]; 27 | if (targetVersion > maxChromium) return null; 28 | 29 | const closestChrome = chromiumToElectronVersions.find( 30 | (version) => targetVersion <= version 31 | ); 32 | return chromiumToElectronMap[closestChrome]; 33 | }; 34 | 35 | const chromiumToElectron = (chromium) => 36 | chromiumToElectronMap[chromium] || findClosestElectronVersion(chromium); 37 | 38 | const renameTests = (tests, getName) => 39 | tests.map((test) => Object.assign({}, test, { name: getName(test.name) })); 40 | 41 | // The following is adapted from compat-table: 42 | // https://github.com/kangax/compat-table/blob/gh-pages/build.js 43 | // 44 | // It parses and interpolates data so environments that "equal" other 45 | // environments (node4 and chrome45), as well as familial relationships (edge 46 | // and ie11) can be handled properly. 47 | 48 | const envs = require("compat-table/environments"); 49 | 50 | const byTestSuite = (suite) => (browser) => { 51 | return Array.isArray(browser.test_suites) 52 | ? browser.test_suites.indexOf(suite) > -1 53 | : true; 54 | }; 55 | 56 | const es6 = require("compat-table/data-es6"); 57 | es6.browsers = pickBy(envs, byTestSuite("es6")); 58 | 59 | const es2016plus = require("compat-table/data-es2016plus"); 60 | es2016plus.browsers = pickBy(envs, byTestSuite("es2016plus")); 61 | 62 | const interpolateAllResults = (rawBrowsers, tests) => { 63 | const interpolateResults = (res) => { 64 | let browser; 65 | let prevBrowser; 66 | let result; 67 | let prevResult; 68 | let prevBid; 69 | 70 | for (const bid in rawBrowsers) { 71 | // For browsers that are essentially equal to other browsers, 72 | // copy over the results. 73 | browser = rawBrowsers[bid]; 74 | if (browser.equals && res[bid] === undefined) { 75 | result = res[browser.equals]; 76 | res[bid] = browser.ignore_flagged && result === "flagged" ? false : result; 77 | // For each browser, check if the previous browser has the same 78 | // browser full name (e.g. Firefox) or family name (e.g. Chakra) as this one. 79 | } else if ( 80 | prevBrowser && 81 | (prevBrowser.full.replace(/,.+$/, "") === browser.full.replace(/,.+$/, "") || 82 | (browser.family !== undefined && prevBrowser.family === browser.family)) 83 | ) { 84 | // For each test, check if the previous browser has a result 85 | // that this browser lacks. 86 | result = res[bid]; 87 | prevResult = res[prevBid]; 88 | if (prevResult !== undefined && result === undefined) { 89 | res[bid] = prevResult; 90 | } 91 | } 92 | prevBrowser = browser; 93 | prevBid = bid; 94 | } 95 | }; 96 | 97 | // Now print the results. 98 | tests.forEach(function(t) { 99 | // Calculate the result totals for tests which consist solely of subtests. 100 | if ("subtests" in t) { 101 | t.subtests.forEach(function(e) { 102 | interpolateResults(e.res); 103 | }); 104 | } else { 105 | interpolateResults(t.res); 106 | } 107 | }); 108 | }; 109 | 110 | interpolateAllResults(es6.browsers, es6.tests); 111 | interpolateAllResults(es2016plus.browsers, es2016plus.tests); 112 | 113 | // End of compat-table code adaptation 114 | 115 | const environments = [ 116 | "chrome", 117 | "opera", 118 | "edge", 119 | "firefox", 120 | "safari", 121 | "node", 122 | "ie", 123 | "android", 124 | "ios", 125 | "phantom" 126 | ]; 127 | 128 | const compatibilityTests = flattenDeep([ 129 | es6, 130 | es2016plus, 131 | ].map((data) => 132 | data.tests.map((test) => { 133 | return test.subtests ? 134 | [test, renameTests(test.subtests, (name) => test.name + " / " + name)] : 135 | test; 136 | }) 137 | )); 138 | 139 | const getLowestImplementedVersion = ({ features }, env) => { 140 | const tests = flatten(compatibilityTests 141 | .filter((test) => { 142 | return features.indexOf(test.name) >= 0 || 143 | // for features === ["DataView"] 144 | // it covers "DataView (Int8)" and "DataView (UInt8)" 145 | features.length === 1 && test.name.indexOf(features[0]) === 0; 146 | }) 147 | .map((test) => { 148 | const isBuiltIn = test.category === "built-ins" || test.category === "built-in extensions"; 149 | 150 | return test.subtests ? 151 | test.subtests.map((subtest) => ({ 152 | name: `${test.name}/${subtest.name}`, 153 | res: subtest.res, 154 | isBuiltIn 155 | })) : 156 | { 157 | name: test.name, 158 | res: test.res, 159 | isBuiltIn 160 | }; 161 | }) 162 | ); 163 | 164 | const envTests = tests 165 | .map(({ res: test, name, isBuiltIn }, i) => { 166 | // Babel itself doesn't implement the feature correctly, 167 | // don't count against it 168 | // only doing this for built-ins atm 169 | if (!test.babel && isBuiltIn) { 170 | return "-1"; 171 | } 172 | 173 | return Object.keys(test) 174 | .filter((t) => t.startsWith(env)) 175 | // Babel assumes strict mode 176 | .filter((test) => tests[i].res[test] === true || tests[i].res[test] === "strict") 177 | // normalize some keys 178 | .map((test) => test.replace("_", ".")) 179 | .filter((test) => !isNaN(parseFloat(test.replace(env, "")))) 180 | .shift(); 181 | }); 182 | 183 | const envFiltered = envTests.filter((t) => t); 184 | if (envTests.length > envFiltered.length || envTests.length === 0) { 185 | // envTests.forEach((test, i) => { 186 | // if (!test) { 187 | // // print unsupported features 188 | // if (env === 'node') { 189 | // console.log(`ENV(${env}): ${tests[i].name}`); 190 | // } 191 | // } 192 | // }); 193 | return null; 194 | } 195 | 196 | return envTests 197 | .map((str) => Number(str.replace(env, ""))) 198 | .reduce((a, b) => { return (a < b) ? b : a; }); 199 | }; 200 | 201 | const generateData = (environments, features) => { 202 | return mapValues(features, (options) => { 203 | if (!options.features) { 204 | options = { 205 | features: [options] 206 | }; 207 | } 208 | 209 | const plugin = {}; 210 | 211 | environments.forEach((env) => { 212 | const version = getLowestImplementedVersion(options, env); 213 | if (version !== null) { 214 | plugin[env] = version.toString(); 215 | } 216 | }); 217 | 218 | if (plugin.chrome) { 219 | // add opera 220 | if (plugin.chrome >= 28) { 221 | plugin.opera = (plugin.chrome - 13).toString(); 222 | } else if (plugin.chrome === 5) { 223 | plugin.opera = "12"; 224 | } 225 | 226 | // add electron 227 | const electronVersion = chromiumToElectron(plugin.chrome); 228 | if (electronVersion) { 229 | plugin.electron = electronVersion.toString(); 230 | } 231 | } 232 | 233 | return plugin; 234 | }); 235 | }; 236 | 237 | fs.writeFileSync( 238 | path.join(__dirname, "../data/plugins.json"), 239 | JSON.stringify(generateData(environments, pluginFeatures), null, 2) + "\n" 240 | ); 241 | 242 | fs.writeFileSync( 243 | path.join(__dirname, "../data/built-ins.json"), 244 | JSON.stringify(generateData(environments, builtInFeatures), null, 2) + "\n" 245 | ); 246 | -------------------------------------------------------------------------------- /scripts/smoke-test.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs-extra"); 2 | const execSync = require("child_process").execSync; 3 | const path = require("path"); 4 | const pkg = require("../package.json"); 5 | 6 | let errorOccurred = false; 7 | 8 | const tempFolderPath = path.join(__dirname, "../tmp"); 9 | const packPath = path.join(__dirname, `../babel-preset-env-${pkg.version}.tgz`); 10 | 11 | try { 12 | console.log("Creating package"); 13 | execSync("npm pack"); 14 | 15 | console.log("Setting up smoke test"); 16 | fs.ensureDirSync(tempFolderPath); 17 | 18 | fs.writeFileSync( 19 | path.join(tempFolderPath, "package.json"), 20 | ` 21 | { 22 | "name": "babel-preset-env-smoke-test", 23 | "private": true, 24 | "version": "1.0.0", 25 | "scripts": { 26 | "build": "babel index.js --out-file index.es6" 27 | }, 28 | "dependencies": { 29 | "babel-cli": "*", 30 | "babel-preset-env": "${packPath}" 31 | } 32 | } 33 | `); 34 | 35 | fs.writeFileSync( 36 | path.join(tempFolderPath, ".babelrc"), 37 | ` 38 | { 39 | "presets": [ 40 | ["env", { 41 | modules: false, 42 | useBuiltIns: true 43 | }] 44 | ] 45 | } 46 | ` 47 | ); 48 | 49 | fs.writeFileSync( 50 | path.join(tempFolderPath, "index.js"), 51 | ` 52 | import "babel-polyfill"; 53 | 1 ** 2; 54 | ` 55 | ); 56 | 57 | process.chdir(tempFolderPath); 58 | 59 | console.log("Running smoke test"); 60 | execSync("npm install && npm run build"); 61 | } catch (e) { 62 | errorOccurred = true; 63 | } 64 | 65 | console.log("Cleaning up"); 66 | fs.removeSync(tempFolderPath); 67 | fs.removeSync(packPath); 68 | 69 | process.exit(errorOccurred ? 1 : 0); 70 | -------------------------------------------------------------------------------- /src/default-includes.js: -------------------------------------------------------------------------------- 1 | export const defaultWebIncludes = [ 2 | "web.timers", 3 | "web.immediate", 4 | "web.dom.iterable" 5 | ]; 6 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import semver from "semver"; 2 | import builtInsList from "../data/built-ins.json"; 3 | import { defaultWebIncludes } from "./default-includes"; 4 | import moduleTransformations from "./module-transformations"; 5 | import normalizeOptions from "./normalize-options.js"; 6 | import pluginList from "../data/plugins.json"; 7 | import transformPolyfillRequirePlugin from "./transform-polyfill-require-plugin"; 8 | import getTargets from "./targets-parser"; 9 | import { _extends, prettifyTargets, prettifyVersion, semverify } from "./utils"; 10 | 11 | /** 12 | * Determine if a transformation is required 13 | * 14 | * NOTE: This assumes `supportedEnvironments` has already been parsed by `getTargets` 15 | * 16 | * @param {Object} supportedEnvironments An Object containing environment keys and the lowest 17 | * supported version as a value 18 | * @param {Object} plugin An Object containing environment keys and the lowest 19 | * version the feature was implemented in as a value 20 | * @return {Boolean} Whether or not the transformation is required 21 | */ 22 | export const isPluginRequired = (supportedEnvironments, plugin) => { 23 | const targetEnvironments = Object.keys(supportedEnvironments); 24 | 25 | if (targetEnvironments.length === 0) { return true; } 26 | 27 | const isRequiredForEnvironments = targetEnvironments 28 | .filter((environment) => { 29 | // Feature is not implemented in that environment 30 | if (!plugin[environment]) { return true; } 31 | 32 | const lowestImplementedVersion = plugin[environment]; 33 | const lowestTargetedVersion = supportedEnvironments[environment]; 34 | 35 | if (!semver.valid(lowestTargetedVersion)) { 36 | throw new Error( 37 | // eslint-disable-next-line max-len 38 | `Invalid version passed for target "${environment}": "${lowestTargetedVersion}". Versions must be in semver format (major.minor.patch)`, 39 | ); 40 | } 41 | 42 | return semver.gt( 43 | semverify(lowestImplementedVersion), 44 | lowestTargetedVersion, 45 | ); 46 | }); 47 | 48 | return isRequiredForEnvironments.length > 0; 49 | }; 50 | 51 | let hasBeenLogged = false; 52 | 53 | const logPlugin = (plugin, targets, list) => { 54 | const envList = list[plugin] || {}; 55 | const filteredList = Object.keys(targets) 56 | .reduce((a, b) => { 57 | if (!envList[b] || semver.lt(targets[b], semverify(envList[b]))) { 58 | a[b] = prettifyVersion(targets[b]); 59 | } 60 | return a; 61 | }, {}); 62 | const logStr = ` ${plugin} ${JSON.stringify(filteredList)}`; 63 | console.log(logStr); 64 | }; 65 | 66 | const filterItem = (targets, exclusions, list, item) => { 67 | const isDefault = defaultWebIncludes.indexOf(item) >= 0; 68 | const notExcluded = exclusions.indexOf(item) === -1; 69 | 70 | if (isDefault) return notExcluded; 71 | const isRequired = isPluginRequired(targets, list[item]); 72 | return isRequired && notExcluded; 73 | }; 74 | 75 | const getBuiltInTargets = (targets) => { 76 | const builtInTargets = _extends({}, targets); 77 | if (builtInTargets.uglify != null) { 78 | delete builtInTargets.uglify; 79 | } 80 | return builtInTargets; 81 | }; 82 | 83 | export const transformIncludesAndExcludes = (opts) => ({ 84 | all: opts, 85 | plugins: opts.filter((opt) => !opt.match(/^(es\d+|web)\./)), 86 | builtIns: opts.filter((opt) => opt.match(/^(es\d+|web)\./)) 87 | }); 88 | 89 | function getPlatformSpecificDefaultFor(targets) { 90 | const targetNames = Object.keys(targets); 91 | const isAnyTarget = !targetNames.length; 92 | const isWebTarget = targetNames.some((name) => name !== "node"); 93 | 94 | return (isAnyTarget || isWebTarget) ? defaultWebIncludes : []; 95 | } 96 | 97 | export default function buildPreset(context, opts = {}) { 98 | const validatedOptions = normalizeOptions(opts); 99 | const { debug, loose, moduleType, spec, useBuiltIns } = validatedOptions; 100 | 101 | const targets = getTargets(validatedOptions.targets); 102 | const include = transformIncludesAndExcludes(validatedOptions.include); 103 | const exclude = transformIncludesAndExcludes(validatedOptions.exclude); 104 | 105 | const filterPlugins = filterItem.bind(null, targets, exclude.plugins, pluginList); 106 | const transformations = Object.keys(pluginList) 107 | .filter(filterPlugins) 108 | .concat(include.plugins); 109 | 110 | let polyfills; 111 | let polyfillTargets; 112 | if (useBuiltIns) { 113 | polyfillTargets = getBuiltInTargets(targets); 114 | const filterBuiltIns = filterItem.bind(null, polyfillTargets, exclude.builtIns, builtInsList); 115 | polyfills = Object.keys(builtInsList) 116 | .concat(getPlatformSpecificDefaultFor(polyfillTargets)) 117 | .filter(filterBuiltIns) 118 | .concat(include.builtIns); 119 | } 120 | 121 | if (debug && !hasBeenLogged) { 122 | hasBeenLogged = true; 123 | console.log("babel-preset-env: `DEBUG` option"); 124 | console.log("\nUsing targets:"); 125 | console.log(JSON.stringify(prettifyTargets(targets), null, 2)); 126 | console.log(`\nModules transform: ${moduleType}`); 127 | console.log("\nUsing plugins:"); 128 | transformations.forEach((transform) => { 129 | logPlugin(transform, targets, pluginList); 130 | }); 131 | if (useBuiltIns && polyfills.length) { 132 | console.log("\nUsing polyfills:"); 133 | polyfills.forEach((polyfill) => { 134 | logPlugin(polyfill, polyfillTargets, builtInsList); 135 | }); 136 | } 137 | } 138 | 139 | const regenerator = transformations.indexOf("transform-regenerator") >= 0; 140 | const modulePlugin = moduleType !== false && moduleTransformations[moduleType]; 141 | const plugins = []; 142 | 143 | // NOTE: not giving spec here yet to avoid compatibility issues when 144 | // babel-plugin-transform-es2015-modules-commonjs gets its spec mode 145 | modulePlugin && 146 | plugins.push([require(`babel-plugin-${modulePlugin}`), { loose }]); 147 | 148 | plugins.push(...transformations.map((pluginName) => 149 | [require(`babel-plugin-${pluginName}`), { spec, loose }] 150 | )); 151 | 152 | useBuiltIns && 153 | plugins.push([transformPolyfillRequirePlugin, { polyfills, regenerator }]); 154 | 155 | return { 156 | plugins 157 | }; 158 | } 159 | -------------------------------------------------------------------------------- /src/module-transformations.js: -------------------------------------------------------------------------------- 1 | export default { 2 | "amd": "transform-es2015-modules-amd", 3 | "commonjs": "transform-es2015-modules-commonjs", 4 | "systemjs": "transform-es2015-modules-systemjs", 5 | "umd": "transform-es2015-modules-umd" 6 | }; 7 | -------------------------------------------------------------------------------- /src/normalize-options.js: -------------------------------------------------------------------------------- 1 | import invariant from "invariant"; 2 | import builtInsList from "../data/built-ins.json"; 3 | import { defaultWebIncludes } from "./default-includes"; 4 | import moduleTransformations from "./module-transformations"; 5 | import pluginsList from "../data/plugins.json"; 6 | 7 | const validIncludesAndExcludes = [ 8 | ...Object.keys(pluginsList), 9 | ...Object.keys(moduleTransformations).map((m) => moduleTransformations[m]), 10 | ...Object.keys(builtInsList), 11 | ...defaultWebIncludes, 12 | ]; 13 | 14 | let hasBeenWarned = false; 15 | 16 | export const validateIncludesAndExcludes = (opts = [], type) => { 17 | invariant( 18 | Array.isArray(opts), 19 | `Invalid Option: The '${type}' option must be an Array of plugins/built-ins` 20 | ); 21 | 22 | const unknownOpts = []; 23 | opts.forEach((opt) => { 24 | if (validIncludesAndExcludes.indexOf(opt) === -1) { 25 | unknownOpts.push(opt); 26 | } 27 | }); 28 | 29 | invariant( 30 | unknownOpts.length === 0, 31 | `Invalid Option: The plugins/built-ins '${unknownOpts}' passed to the '${type}' option are not 32 | valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env` 33 | ); 34 | 35 | return opts; 36 | }; 37 | 38 | export const normalizePluginName = (plugin) => 39 | plugin.replace(/^babel-plugin-/, ""); 40 | 41 | export const normalizePluginNames = (plugins) => 42 | plugins.map(normalizePluginName); 43 | 44 | export const checkDuplicateIncludeExcludes = (include = [], exclude = []) => { 45 | const duplicates = include.filter( 46 | (opt) => exclude.indexOf(opt) >= 0 47 | ); 48 | 49 | invariant( 50 | duplicates.length === 0, 51 | `Invalid Option: The plugins/built-ins '${duplicates}' were found in both the "include" and 52 | "exclude" options.` 53 | ); 54 | }; 55 | 56 | export const validateBoolOption = (name, value, defaultValue) => { 57 | if (typeof value === "undefined") { 58 | value = defaultValue; 59 | } 60 | 61 | if (typeof value !== "boolean") { 62 | throw new Error(`Preset env: '${name}' option must be a boolean.`); 63 | } 64 | 65 | return value; 66 | }; 67 | 68 | export const validateLooseOption = (looseOpt) => validateBoolOption("loose", looseOpt, false); 69 | export const validateSpecOption = (specOpt) => validateBoolOption("spec", specOpt, false); 70 | 71 | export const validateModulesOption = (modulesOpt = "commonjs") => { 72 | invariant( 73 | modulesOpt === false || Object.keys(moduleTransformations).indexOf(modulesOpt) > -1, 74 | `Invalid Option: The 'modules' option must be either 'false' to indicate no modules, or a 75 | module type which can be be one of: 'commonjs' (default), 'amd', 'umd', 'systemjs'.` 76 | ); 77 | 78 | return modulesOpt; 79 | }; 80 | 81 | export default function normalizeOptions(opts) { 82 | // TODO: remove whitelist in favor of include in next major 83 | if (opts.whitelist && !hasBeenWarned) { 84 | console.warn( 85 | `Deprecation Warning: The "whitelist" option has been deprecated in favor of "include" to 86 | match the newly added "exclude" option (instead of "blacklist").` 87 | ); 88 | hasBeenWarned = true; 89 | } 90 | 91 | invariant( 92 | !(opts.whitelist && opts.include), 93 | `Invalid Option: The "whitelist" and the "include" option are the same and one can be used at 94 | a time` 95 | ); 96 | 97 | if (opts.exclude) { 98 | opts.exclude = normalizePluginNames(opts.exclude); 99 | } 100 | 101 | if (opts.whitelist || opts.include) { 102 | opts.include = normalizePluginNames(opts.whitelist || opts.include); 103 | } 104 | 105 | checkDuplicateIncludeExcludes(opts.include, opts.exclude); 106 | 107 | return { 108 | debug: opts.debug, 109 | exclude: validateIncludesAndExcludes(opts.exclude, "exclude"), 110 | include: validateIncludesAndExcludes(opts.include, "include"), 111 | loose: validateLooseOption(opts.loose), 112 | moduleType: validateModulesOption(opts.modules), 113 | spec: validateSpecOption(opts.spec), 114 | targets: opts.targets, 115 | useBuiltIns: opts.useBuiltIns 116 | }; 117 | } 118 | -------------------------------------------------------------------------------- /src/targets-parser.js: -------------------------------------------------------------------------------- 1 | import browserslist from "browserslist"; 2 | import semver from "semver"; 3 | import { semverify } from "./utils"; 4 | 5 | const browserNameMap = { 6 | android: "android", 7 | chrome: "chrome", 8 | and_chr: "chrome", 9 | edge: "edge", 10 | firefox: "firefox", 11 | ie: "ie", 12 | ios_saf: "ios", 13 | safari: "safari", 14 | }; 15 | 16 | const isBrowsersQueryValid = (browsers) => 17 | typeof browsers === "string" || Array.isArray(browsers); 18 | 19 | const semverMin = (first, second) => { 20 | return first && semver.lt(first, second) ? first : second; 21 | }; 22 | 23 | const getLowestVersions = (browsers) => { 24 | return browsers.reduce( 25 | (all, browser) => { 26 | const [browserName, browserVersion] = browser.split(" "); 27 | const normalizedBrowserName = browserNameMap[browserName]; 28 | 29 | if (!normalizedBrowserName) { 30 | return all; 31 | } 32 | 33 | try { 34 | // Browser version can return as "10.0-10.2" 35 | const splitVersion = browserVersion.split("-")[0]; 36 | const parsedBrowserVersion = semverify(splitVersion); 37 | 38 | all[normalizedBrowserName] = semverMin( 39 | all[normalizedBrowserName], 40 | parsedBrowserVersion, 41 | ); 42 | } catch (e) {} 43 | 44 | return all; 45 | }, 46 | {}, 47 | ); 48 | }; 49 | 50 | const outputDecimalWarning = (decimalTargets) => { 51 | if (!decimalTargets || !decimalTargets.length) { 52 | return; 53 | } 54 | 55 | console.log("Warning, the following targets are using a decimal version:"); 56 | console.log(""); 57 | decimalTargets.forEach(({ target, value }) => 58 | console.log(` ${target}: ${value}`)); 59 | console.log(""); 60 | console.log( 61 | "We recommend using a string for minor/patch versions to avoid numbers like 6.10", 62 | ); 63 | console.log("getting parsed as 6.1, which can lead to unexpected behavior."); 64 | console.log(""); 65 | }; 66 | 67 | const targetParserMap = { 68 | __default: (target, value) => [target, semverify(value)], 69 | 70 | // Parse `node: true` and `node: "current"` to version 71 | node: (target, value) => { 72 | const parsed = value === true || value === "current" 73 | ? process.versions.node 74 | : semverify(value); 75 | 76 | return [target, parsed]; 77 | }, 78 | 79 | // Only valid value for Uglify is `true` 80 | uglify: (target, value) => [target, value === true], 81 | }; 82 | 83 | const getTargets = (targets = {}) => { 84 | let targetOpts = {}; 85 | 86 | // Parse browsers target via browserslist 87 | if (isBrowsersQueryValid(targets.browsers)) { 88 | targetOpts = getLowestVersions(browserslist(targets.browsers)); 89 | } 90 | 91 | // Parse remaining targets 92 | const parsed = Object.keys(targets).reduce( 93 | (results, target) => { 94 | if (target !== "browsers") { 95 | const value = targets[target]; 96 | 97 | // Warn when specifying minor/patch as a decimal 98 | if (typeof value === "number" && value % 1 !== 0) { 99 | results.decimalWarnings.push({ target, value }); 100 | } 101 | 102 | // Check if we have a target parser? 103 | const parser = targetParserMap[target] || targetParserMap.__default; 104 | const [parsedTarget, parsedValue] = parser(target, value); 105 | 106 | if (parsedValue) { 107 | results.targets[parsedTarget] = parsedValue; 108 | } 109 | } 110 | 111 | return results; 112 | }, 113 | { 114 | targets: targetOpts, 115 | decimalWarnings: [], 116 | }, 117 | ); 118 | 119 | outputDecimalWarning(parsed.decimalWarnings); 120 | 121 | return parsed.targets; 122 | }; 123 | 124 | export default getTargets; 125 | -------------------------------------------------------------------------------- /src/transform-polyfill-require-plugin.js: -------------------------------------------------------------------------------- 1 | function isPolyfillSource(value) { 2 | return value === "babel-polyfill" || value === "core-js"; 3 | } 4 | 5 | export default function ({ types: t }) { 6 | function createImportDeclaration(polyfill) { 7 | const declar = t.importDeclaration([], t.stringLiteral(polyfill)); 8 | declar._blockHoist = 3; 9 | return declar; 10 | } 11 | 12 | function createRequireStatement(polyfill) { 13 | return t.expressionStatement( 14 | t.callExpression( 15 | t.identifier("require"), 16 | [ 17 | t.stringLiteral(polyfill) 18 | ] 19 | ) 20 | ); 21 | } 22 | 23 | function isRequire(path) { 24 | return t.isExpressionStatement(path.node) && 25 | t.isCallExpression(path.node.expression) && 26 | t.isIdentifier(path.node.expression.callee) && 27 | path.node.expression.callee.name === "require" && 28 | path.node.expression.arguments.length === 1 && 29 | t.isStringLiteral(path.node.expression.arguments[0]) && 30 | isPolyfillSource(path.node.expression.arguments[0].value); 31 | } 32 | 33 | function createImport(polyfill, requireType, core) { 34 | if (core) { 35 | polyfill = `core-js/modules/${polyfill}`; 36 | } 37 | 38 | if (requireType === "import") { 39 | return createImportDeclaration(polyfill); 40 | } else { 41 | return createRequireStatement(polyfill); 42 | } 43 | } 44 | 45 | function createImports(polyfills, requireType, regenerator) { 46 | const imports = polyfills 47 | .filter((el, i, arr) => arr.indexOf(el) === i) 48 | .map((polyfill) => createImport(polyfill, requireType, true)); 49 | 50 | return [ 51 | ...imports, 52 | regenerator && createImport("regenerator-runtime/runtime", requireType) 53 | ].filter(Boolean); 54 | } 55 | 56 | const isPolyfillImport = { 57 | ImportDeclaration(path, state) { 58 | if (path.node.specifiers.length === 0 && 59 | isPolyfillSource(path.node.source.value)) { 60 | this.numPolyfillImports++; 61 | if (this.numPolyfillImports > 1) { 62 | path.remove(); 63 | return; 64 | } 65 | 66 | path.replaceWithMultiple( 67 | createImports(state.opts.polyfills, "import", state.opts.regenerator) 68 | ); 69 | } 70 | }, 71 | Program(path, state) { 72 | if (!state.opts.polyfills) { 73 | throw path.buildCodeFrameError(` 74 | There was an issue in "babel-preset-env" such that 75 | the "polyfills" option was not correctly passed 76 | to the "transform-polyfill-require" plugin 77 | `); 78 | } 79 | path.get("body").forEach((bodyPath) => { 80 | if (isRequire(bodyPath)) { 81 | this.numPolyfillImports++; 82 | if (this.numPolyfillImports > 1) { 83 | path.remove(); 84 | return; 85 | } 86 | 87 | bodyPath.replaceWithMultiple( 88 | createImports(state.opts.polyfills, "require", state.opts.regenerator) 89 | ); 90 | } 91 | }); 92 | } 93 | }; 94 | 95 | return { 96 | name: "transform-polyfill-require", 97 | visitor: isPolyfillImport, 98 | pre() { 99 | this.numPolyfillImports = 0; 100 | } 101 | }; 102 | } 103 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import semver from "semver"; 3 | 4 | export const _extends = Object.assign || 5 | function(target) { 6 | for (let i = 1; i < arguments.length; i++) { 7 | const source = arguments[i]; 8 | for (const key in source) { 9 | if (Object.prototype.hasOwnProperty.call(source, key)) { 10 | target[key] = source[key]; 11 | } 12 | } 13 | } 14 | return target; 15 | }; 16 | 17 | // Convert version to a semver value. 18 | // 2.5 -> 2.5.0; 1 -> 1.0.0; 19 | export const semverify = (version) => { 20 | if (typeof version === "string" && semver.valid(version)) { 21 | return version; 22 | } 23 | 24 | const split = version.toString().split("."); 25 | 26 | while (split.length < 3) { 27 | split.push(0); 28 | } 29 | 30 | return split.join("."); 31 | }; 32 | 33 | export const prettifyVersion = (version) => { 34 | if (typeof version !== "string") { 35 | return version; 36 | } 37 | 38 | const parts = [semver.major(version)]; 39 | const minor = semver.minor(version); 40 | const patch = semver.patch(version); 41 | 42 | if (minor || patch) { 43 | parts.push(minor); 44 | } 45 | 46 | if (patch) { 47 | parts.push(patch); 48 | } 49 | 50 | return parts.join("."); 51 | }; 52 | 53 | export const prettifyTargets = (targets = {}) => { 54 | return Object.keys(targets).reduce( 55 | (results, target) => { 56 | let value = targets[target]; 57 | 58 | if (typeof value === "string") { 59 | value = prettifyVersion(value); 60 | } 61 | 62 | results[target] = value; 63 | return results; 64 | }, 65 | {}, 66 | ); 67 | }; 68 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "rules": { 6 | "max-len": 0 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/debug-fixtures.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const child = require("child_process"); 3 | const fs = require("fs-extra"); 4 | const helper = require("babel-helper-fixtures"); 5 | const path = require("path"); 6 | 7 | const fixtureLoc = path.join(__dirname, "debug-fixtures"); 8 | const tmpLoc = path.join(__dirname, "tmp"); 9 | 10 | const clear = () => { 11 | process.chdir(__dirname); 12 | if (fs.existsSync(tmpLoc)) fs.removeSync(tmpLoc); 13 | fs.mkdirSync(tmpLoc); 14 | process.chdir(tmpLoc); 15 | }; 16 | 17 | const saveInFiles = (files) => { 18 | Object.keys(files).forEach((filename) => { 19 | const content = files[filename]; 20 | fs.outputFileSync(filename, content); 21 | }); 22 | }; 23 | 24 | const assertTest = (stdout, stderr, opts) => { 25 | stderr = stderr.trim(); 26 | 27 | if (stderr) { 28 | throw new Error("stderr:\n" + stderr); 29 | } 30 | 31 | stdout = stdout.trim(); 32 | stdout = stdout.replace(/\\/g, "/"); 33 | 34 | if (opts.stdout) { 35 | const expectStdout = opts.stdout.trim(); 36 | chai.expect(stdout).to.equal(expectStdout, "stdout didn't match"); 37 | } else { 38 | const file = path.join(opts.testLoc, "stdout.txt"); 39 | console.log(`New test file created: ${file}`); 40 | fs.outputFileSync(file, stdout); 41 | } 42 | }; 43 | 44 | const buildTest = (opts) => { 45 | const binLoc = path.join(process.cwd(), "node_modules/.bin/babel"); 46 | 47 | return (callback) => { 48 | clear(); 49 | saveInFiles(opts.inFiles); 50 | 51 | let args = [binLoc]; 52 | args = args.concat(opts.args); 53 | 54 | const spawn = child.spawn(process.execPath, args); 55 | 56 | let stdout = ""; 57 | let stderr = ""; 58 | 59 | spawn.stdout.on("data", (chunk) => stdout += chunk); 60 | spawn.stderr.on("data", (chunk) => stderr += chunk); 61 | 62 | spawn.on("close", () => { 63 | let err; 64 | 65 | try { 66 | assertTest(stdout, stderr, opts); 67 | } catch (e) { 68 | err = e; 69 | } 70 | 71 | callback(err); 72 | }); 73 | }; 74 | }; 75 | 76 | describe("debug output", () => { 77 | fs.readdirSync(fixtureLoc).forEach((testName) => { 78 | if (testName.slice(0, 1) === ".") return; 79 | const testLoc = path.join(fixtureLoc, testName); 80 | 81 | const opts = { 82 | args: ["src", "--out-dir", "lib"], 83 | testLoc: testLoc, 84 | }; 85 | 86 | const stdoutLoc = path.join(testLoc, "stdout.txt"); 87 | 88 | if (fs.existsSync(stdoutLoc)) { 89 | opts.stdout = helper.readFile(stdoutLoc); 90 | } 91 | 92 | const optionsLoc = path.join(testLoc, "options.json"); 93 | 94 | if (!fs.existsSync(optionsLoc)) { 95 | throw new Error(`Debug test '${testName}' is missing an options.json file`); 96 | } 97 | 98 | opts.inFiles = { 99 | "src/in.js": "", 100 | ".babelrc": helper.readFile(optionsLoc), 101 | }; 102 | 103 | it(testName, buildTest(opts)); 104 | }); 105 | }); 106 | -------------------------------------------------------------------------------- /test/debug-fixtures/android/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "browsers": [ "Android >= 4" ] 7 | }, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/debug-fixtures/android/stdout.txt: -------------------------------------------------------------------------------- 1 | babel-preset-env: `DEBUG` option 2 | 3 | Using targets: 4 | { 5 | "android": "4" 6 | } 7 | 8 | Modules transform: commonjs 9 | 10 | Using plugins: 11 | check-es2015-constants {"android":"4"} 12 | transform-es2015-arrow-functions {"android":"4"} 13 | transform-es2015-block-scoped-functions {"android":"4"} 14 | transform-es2015-block-scoping {"android":"4"} 15 | transform-es2015-classes {"android":"4"} 16 | transform-es2015-computed-properties {"android":"4"} 17 | transform-es2015-destructuring {"android":"4"} 18 | transform-es2015-duplicate-keys {"android":"4"} 19 | transform-es2015-for-of {"android":"4"} 20 | transform-es2015-function-name {"android":"4"} 21 | transform-es2015-literals {"android":"4"} 22 | transform-es2015-object-super {"android":"4"} 23 | transform-es2015-parameters {"android":"4"} 24 | transform-es2015-shorthand-properties {"android":"4"} 25 | transform-es2015-spread {"android":"4"} 26 | transform-es2015-sticky-regex {"android":"4"} 27 | transform-es2015-template-literals {"android":"4"} 28 | transform-es2015-typeof-symbol {"android":"4"} 29 | transform-es2015-unicode-regex {"android":"4"} 30 | transform-regenerator {"android":"4"} 31 | transform-exponentiation-operator {"android":"4"} 32 | transform-async-to-generator {"android":"4"} 33 | syntax-trailing-function-commas {"android":"4"} 34 | 35 | Using polyfills: 36 | es6.typed.array-buffer {"android":"4"} 37 | es6.typed.int8-array {"android":"4"} 38 | es6.typed.uint8-array {"android":"4"} 39 | es6.typed.uint8-clamped-array {"android":"4"} 40 | es6.typed.int16-array {"android":"4"} 41 | es6.typed.uint16-array {"android":"4"} 42 | es6.typed.int32-array {"android":"4"} 43 | es6.typed.uint32-array {"android":"4"} 44 | es6.typed.float32-array {"android":"4"} 45 | es6.typed.float64-array {"android":"4"} 46 | es6.map {"android":"4"} 47 | es6.set {"android":"4"} 48 | es6.weak-map {"android":"4"} 49 | es6.weak-set {"android":"4"} 50 | es6.reflect.apply {"android":"4"} 51 | es6.reflect.construct {"android":"4"} 52 | es6.reflect.define-property {"android":"4"} 53 | es6.reflect.delete-property {"android":"4"} 54 | es6.reflect.get {"android":"4"} 55 | es6.reflect.get-own-property-descriptor {"android":"4"} 56 | es6.reflect.get-prototype-of {"android":"4"} 57 | es6.reflect.has {"android":"4"} 58 | es6.reflect.is-extensible {"android":"4"} 59 | es6.reflect.own-keys {"android":"4"} 60 | es6.reflect.prevent-extensions {"android":"4"} 61 | es6.reflect.set {"android":"4"} 62 | es6.reflect.set-prototype-of {"android":"4"} 63 | es6.promise {"android":"4"} 64 | es6.symbol {"android":"4"} 65 | es6.object.freeze {"android":"4"} 66 | es6.object.seal {"android":"4"} 67 | es6.object.prevent-extensions {"android":"4"} 68 | es6.object.is-frozen {"android":"4"} 69 | es6.object.is-sealed {"android":"4"} 70 | es6.object.is-extensible {"android":"4"} 71 | es6.object.get-own-property-descriptor {"android":"4"} 72 | es6.object.get-prototype-of {"android":"4"} 73 | es6.object.keys {"android":"4"} 74 | es6.object.get-own-property-names {"android":"4"} 75 | es6.object.assign {"android":"4"} 76 | es6.object.is {"android":"4"} 77 | es6.object.set-prototype-of {"android":"4"} 78 | es6.function.name {"android":"4"} 79 | es6.string.raw {"android":"4"} 80 | es6.string.from-code-point {"android":"4"} 81 | es6.string.code-point-at {"android":"4"} 82 | es6.string.repeat {"android":"4"} 83 | es6.string.starts-with {"android":"4"} 84 | es6.string.ends-with {"android":"4"} 85 | es6.string.includes {"android":"4"} 86 | es6.regexp.flags {"android":"4"} 87 | es6.regexp.match {"android":"4"} 88 | es6.regexp.replace {"android":"4"} 89 | es6.regexp.split {"android":"4"} 90 | es6.regexp.search {"android":"4"} 91 | es6.array.from {"android":"4"} 92 | es6.array.of {"android":"4"} 93 | es6.array.copy-within {"android":"4"} 94 | es6.array.find {"android":"4"} 95 | es6.array.find-index {"android":"4"} 96 | es6.array.fill {"android":"4"} 97 | es6.array.iterator {"android":"4"} 98 | es6.number.is-finite {"android":"4"} 99 | es6.number.is-integer {"android":"4"} 100 | es6.number.is-safe-integer {"android":"4"} 101 | es6.number.is-nan {"android":"4"} 102 | es6.number.epsilon {"android":"4"} 103 | es6.number.min-safe-integer {"android":"4"} 104 | es6.number.max-safe-integer {"android":"4"} 105 | es6.math.acosh {"android":"4"} 106 | es6.math.asinh {"android":"4"} 107 | es6.math.atanh {"android":"4"} 108 | es6.math.cbrt {"android":"4"} 109 | es6.math.clz32 {"android":"4"} 110 | es6.math.cosh {"android":"4"} 111 | es6.math.expm1 {"android":"4"} 112 | es6.math.fround {"android":"4"} 113 | es6.math.hypot {"android":"4"} 114 | es6.math.imul {"android":"4"} 115 | es6.math.log1p {"android":"4"} 116 | es6.math.log10 {"android":"4"} 117 | es6.math.log2 {"android":"4"} 118 | es6.math.sign {"android":"4"} 119 | es6.math.sinh {"android":"4"} 120 | es6.math.tanh {"android":"4"} 121 | es6.math.trunc {"android":"4"} 122 | es7.array.includes {"android":"4"} 123 | es7.object.values {"android":"4"} 124 | es7.object.entries {"android":"4"} 125 | es7.object.get-own-property-descriptors {"android":"4"} 126 | es7.string.pad-start {"android":"4"} 127 | es7.string.pad-end {"android":"4"} 128 | web.timers {"android":"4"} 129 | web.immediate {"android":"4"} 130 | web.dom.iterable {"android":"4"} 131 | src/in.js -> lib/in.js 132 | -------------------------------------------------------------------------------- /test/debug-fixtures/builtins-uglify/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "chrome": 55, 7 | "uglify": true 8 | }, 9 | "useBuiltIns": true, 10 | "modules": false 11 | }] 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /test/debug-fixtures/builtins-uglify/stdout.txt: -------------------------------------------------------------------------------- 1 | babel-preset-env: `DEBUG` option 2 | 3 | Using targets: 4 | { 5 | "chrome": "55", 6 | "uglify": true 7 | } 8 | 9 | Modules transform: false 10 | 11 | Using plugins: 12 | check-es2015-constants {"uglify":true} 13 | transform-es2015-arrow-functions {"uglify":true} 14 | transform-es2015-block-scoped-functions {"uglify":true} 15 | transform-es2015-block-scoping {"uglify":true} 16 | transform-es2015-classes {"uglify":true} 17 | transform-es2015-computed-properties {"uglify":true} 18 | transform-es2015-destructuring {"uglify":true} 19 | transform-es2015-duplicate-keys {"uglify":true} 20 | transform-es2015-for-of {"uglify":true} 21 | transform-es2015-function-name {"uglify":true} 22 | transform-es2015-literals {"uglify":true} 23 | transform-es2015-object-super {"uglify":true} 24 | transform-es2015-parameters {"uglify":true} 25 | transform-es2015-shorthand-properties {"uglify":true} 26 | transform-es2015-spread {"uglify":true} 27 | transform-es2015-sticky-regex {"uglify":true} 28 | transform-es2015-template-literals {"uglify":true} 29 | transform-es2015-typeof-symbol {"uglify":true} 30 | transform-es2015-unicode-regex {"uglify":true} 31 | transform-regenerator {"uglify":true} 32 | transform-exponentiation-operator {"uglify":true} 33 | transform-async-to-generator {"uglify":true} 34 | syntax-trailing-function-commas {"chrome":"55","uglify":true} 35 | 36 | Using polyfills: 37 | es7.string.pad-start {"chrome":"55"} 38 | es7.string.pad-end {"chrome":"55"} 39 | web.timers {"chrome":"55"} 40 | web.immediate {"chrome":"55"} 41 | web.dom.iterable {"chrome":"55"} 42 | src/in.js -> lib/in.js -------------------------------------------------------------------------------- /test/debug-fixtures/builtins/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "browsers": "chrome >= 54, ie 10", 7 | "node": 6 8 | }, 9 | "useBuiltIns": true 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/debug-fixtures/builtins/stdout.txt: -------------------------------------------------------------------------------- 1 | babel-preset-env: `DEBUG` option 2 | 3 | Using targets: 4 | { 5 | "chrome": "54", 6 | "ie": "10", 7 | "node": "6" 8 | } 9 | 10 | Modules transform: commonjs 11 | 12 | Using plugins: 13 | check-es2015-constants {"ie":"10"} 14 | transform-es2015-arrow-functions {"ie":"10"} 15 | transform-es2015-block-scoped-functions {"ie":"10"} 16 | transform-es2015-block-scoping {"ie":"10"} 17 | transform-es2015-classes {"ie":"10"} 18 | transform-es2015-computed-properties {"ie":"10"} 19 | transform-es2015-destructuring {"ie":"10","node":"6"} 20 | transform-es2015-duplicate-keys {"ie":"10"} 21 | transform-es2015-for-of {"ie":"10","node":"6"} 22 | transform-es2015-function-name {"ie":"10","node":"6"} 23 | transform-es2015-literals {"ie":"10"} 24 | transform-es2015-object-super {"ie":"10"} 25 | transform-es2015-parameters {"ie":"10"} 26 | transform-es2015-shorthand-properties {"ie":"10"} 27 | transform-es2015-spread {"ie":"10"} 28 | transform-es2015-sticky-regex {"ie":"10"} 29 | transform-es2015-template-literals {"ie":"10"} 30 | transform-es2015-typeof-symbol {"ie":"10"} 31 | transform-es2015-unicode-regex {"ie":"10"} 32 | transform-regenerator {"ie":"10"} 33 | transform-exponentiation-operator {"ie":"10","node":"6"} 34 | transform-async-to-generator {"chrome":"54","ie":"10","node":"6"} 35 | syntax-trailing-function-commas {"chrome":"54","ie":"10","node":"6"} 36 | 37 | Using polyfills: 38 | es6.typed.array-buffer {"ie":"10","node":"6"} 39 | es6.typed.int8-array {"ie":"10","node":"6"} 40 | es6.typed.uint8-array {"ie":"10","node":"6"} 41 | es6.typed.uint8-clamped-array {"ie":"10","node":"6"} 42 | es6.typed.int16-array {"ie":"10","node":"6"} 43 | es6.typed.uint16-array {"ie":"10","node":"6"} 44 | es6.typed.int32-array {"ie":"10","node":"6"} 45 | es6.typed.uint32-array {"ie":"10","node":"6"} 46 | es6.typed.float32-array {"ie":"10","node":"6"} 47 | es6.typed.float64-array {"ie":"10","node":"6"} 48 | es6.map {"ie":"10","node":"6"} 49 | es6.set {"ie":"10","node":"6"} 50 | es6.weak-map {"ie":"10","node":"6"} 51 | es6.weak-set {"ie":"10","node":"6"} 52 | es6.reflect.apply {"ie":"10"} 53 | es6.reflect.construct {"ie":"10"} 54 | es6.reflect.define-property {"ie":"10"} 55 | es6.reflect.delete-property {"ie":"10"} 56 | es6.reflect.get {"ie":"10"} 57 | es6.reflect.get-own-property-descriptor {"ie":"10"} 58 | es6.reflect.get-prototype-of {"ie":"10"} 59 | es6.reflect.has {"ie":"10"} 60 | es6.reflect.is-extensible {"ie":"10"} 61 | es6.reflect.own-keys {"ie":"10"} 62 | es6.reflect.prevent-extensions {"ie":"10"} 63 | es6.reflect.set {"ie":"10"} 64 | es6.reflect.set-prototype-of {"ie":"10"} 65 | es6.promise {"ie":"10","node":"6"} 66 | es6.symbol {"ie":"10","node":"6"} 67 | es6.object.freeze {"ie":"10"} 68 | es6.object.seal {"ie":"10"} 69 | es6.object.prevent-extensions {"ie":"10"} 70 | es6.object.is-frozen {"ie":"10"} 71 | es6.object.is-sealed {"ie":"10"} 72 | es6.object.is-extensible {"ie":"10"} 73 | es6.object.get-own-property-descriptor {"ie":"10"} 74 | es6.object.get-prototype-of {"ie":"10"} 75 | es6.object.keys {"ie":"10"} 76 | es6.object.get-own-property-names {"ie":"10"} 77 | es6.object.assign {"ie":"10"} 78 | es6.object.is {"ie":"10"} 79 | es6.object.set-prototype-of {"ie":"10"} 80 | es6.function.name {"ie":"10","node":"6"} 81 | es6.string.raw {"ie":"10"} 82 | es6.string.from-code-point {"ie":"10"} 83 | es6.string.code-point-at {"ie":"10"} 84 | es6.string.repeat {"ie":"10"} 85 | es6.string.starts-with {"ie":"10"} 86 | es6.string.ends-with {"ie":"10"} 87 | es6.string.includes {"ie":"10"} 88 | es6.regexp.flags {"ie":"10"} 89 | es6.regexp.match {"ie":"10"} 90 | es6.regexp.replace {"ie":"10"} 91 | es6.regexp.split {"ie":"10"} 92 | es6.regexp.search {"ie":"10"} 93 | es6.array.from {"ie":"10","node":"6"} 94 | es6.array.of {"ie":"10"} 95 | es6.array.copy-within {"ie":"10"} 96 | es6.array.find {"ie":"10"} 97 | es6.array.find-index {"ie":"10"} 98 | es6.array.fill {"ie":"10"} 99 | es6.array.iterator {"ie":"10"} 100 | es6.number.is-finite {"ie":"10"} 101 | es6.number.is-integer {"ie":"10"} 102 | es6.number.is-safe-integer {"ie":"10"} 103 | es6.number.is-nan {"ie":"10"} 104 | es6.number.epsilon {"ie":"10"} 105 | es6.number.min-safe-integer {"ie":"10"} 106 | es6.number.max-safe-integer {"ie":"10"} 107 | es6.math.acosh {"ie":"10"} 108 | es6.math.asinh {"ie":"10"} 109 | es6.math.atanh {"ie":"10"} 110 | es6.math.cbrt {"ie":"10"} 111 | es6.math.clz32 {"ie":"10"} 112 | es6.math.cosh {"ie":"10"} 113 | es6.math.expm1 {"ie":"10"} 114 | es6.math.fround {"ie":"10"} 115 | es6.math.hypot {"ie":"10"} 116 | es6.math.imul {"ie":"10"} 117 | es6.math.log1p {"ie":"10"} 118 | es6.math.log10 {"ie":"10"} 119 | es6.math.log2 {"ie":"10"} 120 | es6.math.sign {"ie":"10"} 121 | es6.math.sinh {"ie":"10"} 122 | es6.math.tanh {"ie":"10"} 123 | es6.math.trunc {"ie":"10"} 124 | es7.array.includes {"ie":"10"} 125 | es7.object.values {"ie":"10","node":"6"} 126 | es7.object.entries {"ie":"10","node":"6"} 127 | es7.object.get-own-property-descriptors {"ie":"10","node":"6"} 128 | es7.string.pad-start {"chrome":"54","ie":"10","node":"6"} 129 | es7.string.pad-end {"chrome":"54","ie":"10","node":"6"} 130 | web.timers {"chrome":"54","ie":"10","node":"6"} 131 | web.immediate {"chrome":"54","ie":"10","node":"6"} 132 | web.dom.iterable {"chrome":"54","ie":"10","node":"6"} 133 | src/in.js -> lib/in.js 134 | -------------------------------------------------------------------------------- /test/debug-fixtures/electron/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "electron": 0.36 7 | }, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/debug-fixtures/electron/stdout.txt: -------------------------------------------------------------------------------- 1 | Warning, the following targets are using a decimal version: 2 | 3 | electron: 0.36 4 | 5 | We recommend using a string for minor/patch versions to avoid numbers like 6.10 6 | getting parsed as 6.1, which can lead to unexpected behavior. 7 | 8 | babel-preset-env: `DEBUG` option 9 | 10 | Using targets: 11 | { 12 | "electron": "0.36" 13 | } 14 | 15 | Modules transform: commonjs 16 | 17 | Using plugins: 18 | check-es2015-constants {"electron":"0.36"} 19 | transform-es2015-block-scoping {"electron":"0.36"} 20 | transform-es2015-destructuring {"electron":"0.36"} 21 | transform-es2015-for-of {"electron":"0.36"} 22 | transform-es2015-function-name {"electron":"0.36"} 23 | transform-es2015-parameters {"electron":"0.36"} 24 | transform-es2015-sticky-regex {"electron":"0.36"} 25 | transform-es2015-unicode-regex {"electron":"0.36"} 26 | transform-regenerator {"electron":"0.36"} 27 | transform-exponentiation-operator {"electron":"0.36"} 28 | transform-async-to-generator {"electron":"0.36"} 29 | syntax-trailing-function-commas {"electron":"0.36"} 30 | 31 | Using polyfills: 32 | es6.typed.array-buffer {"electron":"0.36"} 33 | es6.typed.data-view {"electron":"0.36"} 34 | es6.typed.int8-array {"electron":"0.36"} 35 | es6.typed.uint8-array {"electron":"0.36"} 36 | es6.typed.uint8-clamped-array {"electron":"0.36"} 37 | es6.typed.int16-array {"electron":"0.36"} 38 | es6.typed.uint16-array {"electron":"0.36"} 39 | es6.typed.int32-array {"electron":"0.36"} 40 | es6.typed.uint32-array {"electron":"0.36"} 41 | es6.typed.float32-array {"electron":"0.36"} 42 | es6.typed.float64-array {"electron":"0.36"} 43 | es6.map {"electron":"0.36"} 44 | es6.set {"electron":"0.36"} 45 | es6.weak-map {"electron":"0.36"} 46 | es6.weak-set {"electron":"0.36"} 47 | es6.reflect.apply {"electron":"0.36"} 48 | es6.reflect.construct {"electron":"0.36"} 49 | es6.reflect.define-property {"electron":"0.36"} 50 | es6.reflect.delete-property {"electron":"0.36"} 51 | es6.reflect.get {"electron":"0.36"} 52 | es6.reflect.get-own-property-descriptor {"electron":"0.36"} 53 | es6.reflect.get-prototype-of {"electron":"0.36"} 54 | es6.reflect.has {"electron":"0.36"} 55 | es6.reflect.is-extensible {"electron":"0.36"} 56 | es6.reflect.own-keys {"electron":"0.36"} 57 | es6.reflect.prevent-extensions {"electron":"0.36"} 58 | es6.reflect.set {"electron":"0.36"} 59 | es6.reflect.set-prototype-of {"electron":"0.36"} 60 | es6.promise {"electron":"0.36"} 61 | es6.symbol {"electron":"0.36"} 62 | es6.function.name {"electron":"0.36"} 63 | es6.regexp.flags {"electron":"0.36"} 64 | es6.regexp.match {"electron":"0.36"} 65 | es6.regexp.replace {"electron":"0.36"} 66 | es6.regexp.split {"electron":"0.36"} 67 | es6.regexp.search {"electron":"0.36"} 68 | es6.array.from {"electron":"0.36"} 69 | es7.object.values {"electron":"0.36"} 70 | es7.object.entries {"electron":"0.36"} 71 | es7.object.get-own-property-descriptors {"electron":"0.36"} 72 | es7.string.pad-start {"electron":"0.36"} 73 | es7.string.pad-end {"electron":"0.36"} 74 | web.timers {"electron":"0.36"} 75 | web.immediate {"electron":"0.36"} 76 | web.dom.iterable {"electron":"0.36"} 77 | src/in.js -> lib/in.js -------------------------------------------------------------------------------- /test/debug-fixtures/plugins-only/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "exclude": [ 6 | "transform-async-to-generator", 7 | "transform-regenerator", 8 | "transform-es2015-parameters" 9 | ], 10 | "targets": { 11 | "firefox": 52, 12 | "node": 7.4 13 | } 14 | }] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /test/debug-fixtures/plugins-only/stdout.txt: -------------------------------------------------------------------------------- 1 | Warning, the following targets are using a decimal version: 2 | 3 | node: 7.4 4 | 5 | We recommend using a string for minor/patch versions to avoid numbers like 6.10 6 | getting parsed as 6.1, which can lead to unexpected behavior. 7 | 8 | babel-preset-env: `DEBUG` option 9 | 10 | Using targets: 11 | { 12 | "firefox": "52", 13 | "node": "7.4" 14 | } 15 | 16 | Modules transform: commonjs 17 | 18 | Using plugins: 19 | transform-es2015-destructuring {"firefox":"52"} 20 | transform-es2015-for-of {"firefox":"52"} 21 | transform-es2015-function-name {"firefox":"52"} 22 | transform-es2015-literals {"firefox":"52"} 23 | syntax-trailing-function-commas {"node":"7.4"} 24 | src/in.js -> lib/in.js -------------------------------------------------------------------------------- /test/debug-fixtures/specific-targets/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "browsers": "ie 10, ios 9, safari 7, edge 13, chrome 54, firefox 49" 7 | }, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/debug-fixtures/specific-targets/stdout.txt: -------------------------------------------------------------------------------- 1 | babel-preset-env: `DEBUG` option 2 | 3 | Using targets: 4 | { 5 | "chrome": "54", 6 | "edge": "13", 7 | "firefox": "49", 8 | "ie": "10", 9 | "ios": "9", 10 | "safari": "7" 11 | } 12 | 13 | Modules transform: commonjs 14 | 15 | Using plugins: 16 | check-es2015-constants {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 17 | transform-es2015-arrow-functions {"ie":"10","ios":"9","safari":"7"} 18 | transform-es2015-block-scoped-functions {"ie":"10","ios":"9","safari":"7"} 19 | transform-es2015-block-scoping {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 20 | transform-es2015-classes {"ie":"10","ios":"9","safari":"7"} 21 | transform-es2015-computed-properties {"ie":"10","safari":"7"} 22 | transform-es2015-destructuring {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 23 | transform-es2015-duplicate-keys {"ie":"10","safari":"7"} 24 | transform-es2015-for-of {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 25 | transform-es2015-function-name {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 26 | transform-es2015-literals {"firefox":"49","ie":"10","safari":"7"} 27 | transform-es2015-object-super {"ie":"10","ios":"9","safari":"7"} 28 | transform-es2015-parameters {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 29 | transform-es2015-shorthand-properties {"ie":"10","safari":"7"} 30 | transform-es2015-spread {"ie":"10","ios":"9","safari":"7"} 31 | transform-es2015-sticky-regex {"ie":"10","ios":"9","safari":"7"} 32 | transform-es2015-template-literals {"ie":"10","safari":"7"} 33 | transform-es2015-typeof-symbol {"ie":"10","safari":"7"} 34 | transform-es2015-unicode-regex {"ie":"10","ios":"9","safari":"7"} 35 | transform-regenerator {"firefox":"49","ie":"10","ios":"9","safari":"7"} 36 | transform-exponentiation-operator {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 37 | transform-async-to-generator {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 38 | syntax-trailing-function-commas {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 39 | 40 | Using polyfills: 41 | es6.typed.array-buffer {"ie":"10","ios":"9","safari":"7"} 42 | es6.typed.int8-array {"ie":"10","ios":"9","safari":"7"} 43 | es6.typed.uint8-array {"ie":"10","ios":"9","safari":"7"} 44 | es6.typed.uint8-clamped-array {"ie":"10","ios":"9","safari":"7"} 45 | es6.typed.int16-array {"ie":"10","ios":"9","safari":"7"} 46 | es6.typed.uint16-array {"ie":"10","ios":"9","safari":"7"} 47 | es6.typed.int32-array {"ie":"10","ios":"9","safari":"7"} 48 | es6.typed.uint32-array {"ie":"10","ios":"9","safari":"7"} 49 | es6.typed.float32-array {"ie":"10","ios":"9","safari":"7"} 50 | es6.typed.float64-array {"ie":"10","ios":"9","safari":"7"} 51 | es6.map {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 52 | es6.set {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 53 | es6.weak-map {"edge":"13","firefox":"49","ie":"10","safari":"7"} 54 | es6.weak-set {"edge":"13","firefox":"49","ie":"10","safari":"7"} 55 | es6.reflect.apply {"ie":"10","ios":"9","safari":"7"} 56 | es6.reflect.construct {"ie":"10","ios":"9","safari":"7"} 57 | es6.reflect.define-property {"ie":"10","ios":"9","safari":"7"} 58 | es6.reflect.delete-property {"ie":"10","ios":"9","safari":"7"} 59 | es6.reflect.get {"ie":"10","ios":"9","safari":"7"} 60 | es6.reflect.get-own-property-descriptor {"ie":"10","ios":"9","safari":"7"} 61 | es6.reflect.get-prototype-of {"ie":"10","ios":"9","safari":"7"} 62 | es6.reflect.has {"ie":"10","ios":"9","safari":"7"} 63 | es6.reflect.is-extensible {"ie":"10","ios":"9","safari":"7"} 64 | es6.reflect.own-keys {"ie":"10","ios":"9","safari":"7"} 65 | es6.reflect.prevent-extensions {"ie":"10","ios":"9","safari":"7"} 66 | es6.reflect.set {"ie":"10","ios":"9","safari":"7"} 67 | es6.reflect.set-prototype-of {"ie":"10","ios":"9","safari":"7"} 68 | es6.promise {"ie":"10","ios":"9","safari":"7"} 69 | es6.symbol {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 70 | es6.object.freeze {"ie":"10","safari":"7"} 71 | es6.object.seal {"ie":"10","safari":"7"} 72 | es6.object.prevent-extensions {"ie":"10","safari":"7"} 73 | es6.object.is-frozen {"ie":"10","safari":"7"} 74 | es6.object.is-sealed {"ie":"10","safari":"7"} 75 | es6.object.is-extensible {"ie":"10","safari":"7"} 76 | es6.object.get-own-property-descriptor {"ie":"10","safari":"7"} 77 | es6.object.get-prototype-of {"ie":"10","safari":"7"} 78 | es6.object.keys {"ie":"10","safari":"7"} 79 | es6.object.get-own-property-names {"ie":"10","safari":"7"} 80 | es6.object.assign {"ie":"10","safari":"7"} 81 | es6.object.is {"ie":"10","safari":"7"} 82 | es6.object.set-prototype-of {"ie":"10","safari":"7"} 83 | es6.function.name {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 84 | es6.string.raw {"ie":"10","safari":"7"} 85 | es6.string.from-code-point {"ie":"10","safari":"7"} 86 | es6.string.code-point-at {"ie":"10","safari":"7"} 87 | es6.string.repeat {"ie":"10","safari":"7"} 88 | es6.string.starts-with {"ie":"10","safari":"7"} 89 | es6.string.ends-with {"ie":"10","safari":"7"} 90 | es6.string.includes {"ie":"10","safari":"7"} 91 | es6.regexp.flags {"edge":"13","ie":"10","safari":"7"} 92 | es6.regexp.match {"edge":"13","ie":"10","ios":"9","safari":"7"} 93 | es6.regexp.replace {"edge":"13","ie":"10","ios":"9","safari":"7"} 94 | es6.regexp.split {"edge":"13","ie":"10","ios":"9","safari":"7"} 95 | es6.regexp.search {"edge":"13","ie":"10","ios":"9","safari":"7"} 96 | es6.array.from {"edge":"13","ie":"10","ios":"9","safari":"7"} 97 | es6.array.of {"ie":"10","safari":"7"} 98 | es6.array.copy-within {"ie":"10","safari":"7"} 99 | es6.array.find {"ie":"10","safari":"7"} 100 | es6.array.find-index {"ie":"10","safari":"7"} 101 | es6.array.fill {"ie":"10","safari":"7"} 102 | es6.array.iterator {"ie":"10","safari":"7"} 103 | es6.number.is-finite {"ie":"10","safari":"7"} 104 | es6.number.is-integer {"ie":"10","safari":"7"} 105 | es6.number.is-safe-integer {"ie":"10","safari":"7"} 106 | es6.number.is-nan {"ie":"10","safari":"7"} 107 | es6.number.epsilon {"ie":"10","safari":"7"} 108 | es6.number.min-safe-integer {"ie":"10","safari":"7"} 109 | es6.number.max-safe-integer {"ie":"10","safari":"7"} 110 | es6.math.acosh {"ie":"10","safari":"7"} 111 | es6.math.asinh {"ie":"10","safari":"7"} 112 | es6.math.atanh {"ie":"10","safari":"7"} 113 | es6.math.cbrt {"ie":"10","safari":"7"} 114 | es6.math.clz32 {"ie":"10","safari":"7"} 115 | es6.math.cosh {"ie":"10","safari":"7"} 116 | es6.math.expm1 {"ie":"10","safari":"7"} 117 | es6.math.fround {"ie":"10","safari":"7"} 118 | es6.math.hypot {"ie":"10","safari":"7"} 119 | es6.math.imul {"ie":"10"} 120 | es6.math.log1p {"ie":"10","safari":"7"} 121 | es6.math.log10 {"ie":"10","safari":"7"} 122 | es6.math.log2 {"ie":"10","safari":"7"} 123 | es6.math.sign {"ie":"10","safari":"7"} 124 | es6.math.sinh {"ie":"10","safari":"7"} 125 | es6.math.tanh {"ie":"10","safari":"7"} 126 | es6.math.trunc {"ie":"10","safari":"7"} 127 | es7.array.includes {"edge":"13","ie":"10","ios":"9","safari":"7"} 128 | es7.object.values {"edge":"13","ie":"10","ios":"9","safari":"7"} 129 | es7.object.entries {"edge":"13","ie":"10","ios":"9","safari":"7"} 130 | es7.object.get-own-property-descriptors {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 131 | es7.string.pad-start {"chrome":"54","edge":"13","ie":"10","ios":"9","safari":"7"} 132 | es7.string.pad-end {"chrome":"54","edge":"13","ie":"10","ios":"9","safari":"7"} 133 | web.timers {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 134 | web.immediate {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 135 | web.dom.iterable {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} 136 | src/in.js -> lib/in.js 137 | -------------------------------------------------------------------------------- /test/debug-fixtures/versions-decimals/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "chrome": 54, 7 | "electron": 0.36, 8 | "node": 6.10, 9 | "ie": 10 10 | } 11 | }] 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /test/debug-fixtures/versions-decimals/stdout.txt: -------------------------------------------------------------------------------- 1 | Warning, the following targets are using a decimal version: 2 | 3 | electron: 0.36 4 | node: 6.1 5 | 6 | We recommend using a string for minor/patch versions to avoid numbers like 6.10 7 | getting parsed as 6.1, which can lead to unexpected behavior. 8 | 9 | babel-preset-env: `DEBUG` option 10 | 11 | Using targets: 12 | { 13 | "chrome": "54", 14 | "electron": "0.36", 15 | "node": "6.1", 16 | "ie": "10" 17 | } 18 | 19 | Modules transform: commonjs 20 | 21 | Using plugins: 22 | check-es2015-constants {"electron":"0.36","ie":"10"} 23 | transform-es2015-arrow-functions {"ie":"10"} 24 | transform-es2015-block-scoped-functions {"ie":"10"} 25 | transform-es2015-block-scoping {"electron":"0.36","ie":"10"} 26 | transform-es2015-classes {"ie":"10"} 27 | transform-es2015-computed-properties {"ie":"10"} 28 | transform-es2015-destructuring {"electron":"0.36","node":"6.1","ie":"10"} 29 | transform-es2015-duplicate-keys {"ie":"10"} 30 | transform-es2015-for-of {"electron":"0.36","node":"6.1","ie":"10"} 31 | transform-es2015-function-name {"electron":"0.36","node":"6.1","ie":"10"} 32 | transform-es2015-literals {"ie":"10"} 33 | transform-es2015-object-super {"ie":"10"} 34 | transform-es2015-parameters {"electron":"0.36","ie":"10"} 35 | transform-es2015-shorthand-properties {"ie":"10"} 36 | transform-es2015-spread {"ie":"10"} 37 | transform-es2015-sticky-regex {"electron":"0.36","ie":"10"} 38 | transform-es2015-template-literals {"ie":"10"} 39 | transform-es2015-typeof-symbol {"ie":"10"} 40 | transform-es2015-unicode-regex {"electron":"0.36","ie":"10"} 41 | transform-regenerator {"electron":"0.36","ie":"10"} 42 | transform-exponentiation-operator {"electron":"0.36","node":"6.1","ie":"10"} 43 | transform-async-to-generator {"chrome":"54","electron":"0.36","node":"6.1","ie":"10"} 44 | syntax-trailing-function-commas {"chrome":"54","electron":"0.36","node":"6.1","ie":"10"} 45 | src/in.js -> lib/in.js -------------------------------------------------------------------------------- /test/debug-fixtures/versions-strings/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../lib", { 4 | "debug": true, 5 | "targets": { 6 | "chrome": "54", 7 | "node": "6.10", 8 | "ie": "10" 9 | } 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/debug-fixtures/versions-strings/stdout.txt: -------------------------------------------------------------------------------- 1 | babel-preset-env: `DEBUG` option 2 | 3 | Using targets: 4 | { 5 | "chrome": "54", 6 | "node": "6.10", 7 | "ie": "10" 8 | } 9 | 10 | Modules transform: commonjs 11 | 12 | Using plugins: 13 | check-es2015-constants {"ie":"10"} 14 | transform-es2015-arrow-functions {"ie":"10"} 15 | transform-es2015-block-scoped-functions {"ie":"10"} 16 | transform-es2015-block-scoping {"ie":"10"} 17 | transform-es2015-classes {"ie":"10"} 18 | transform-es2015-computed-properties {"ie":"10"} 19 | transform-es2015-destructuring {"ie":"10"} 20 | transform-es2015-duplicate-keys {"ie":"10"} 21 | transform-es2015-for-of {"ie":"10"} 22 | transform-es2015-function-name {"ie":"10"} 23 | transform-es2015-literals {"ie":"10"} 24 | transform-es2015-object-super {"ie":"10"} 25 | transform-es2015-parameters {"ie":"10"} 26 | transform-es2015-shorthand-properties {"ie":"10"} 27 | transform-es2015-spread {"ie":"10"} 28 | transform-es2015-sticky-regex {"ie":"10"} 29 | transform-es2015-template-literals {"ie":"10"} 30 | transform-es2015-typeof-symbol {"ie":"10"} 31 | transform-es2015-unicode-regex {"ie":"10"} 32 | transform-regenerator {"ie":"10"} 33 | transform-exponentiation-operator {"node":"6.10","ie":"10"} 34 | transform-async-to-generator {"chrome":"54","node":"6.10","ie":"10"} 35 | syntax-trailing-function-commas {"chrome":"54","node":"6.10","ie":"10"} 36 | src/in.js -> lib/in.js -------------------------------------------------------------------------------- /test/fixtures.js: -------------------------------------------------------------------------------- 1 | require("babel-helper-plugin-test-runner")(__dirname); 2 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/filters-duplicates/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/filters-duplicates/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.data-view"; 2 | import "core-js/modules/es6.reflect.apply"; 3 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/filters-duplicates/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | ["../../../../lib/transform-polyfill-require-plugin", { 4 | "polyfills": [ 5 | "es6.typed.data-view", 6 | "es6.typed.data-view", 7 | "es6.reflect.apply" 8 | ] 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-false/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-false/expected.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babel/babel-preset-env/31f33e3656e1bd8036317c54128fdc2812a2e8aa/test/fixtures/plugin-options/regenerator-false/expected.js -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-false/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | ["../../../../lib/transform-polyfill-require-plugin", { 4 | "regenerator": false, 5 | "polyfills": [] 6 | }] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-true/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-true/expected.js: -------------------------------------------------------------------------------- 1 | import "regenerator-runtime/runtime"; 2 | -------------------------------------------------------------------------------- /test/fixtures/plugin-options/regenerator-true/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | ["../../../../lib/transform-polyfill-require-plugin", { 4 | "regenerator": true, 5 | "polyfills": [] 6 | }] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/core-js/actual.js: -------------------------------------------------------------------------------- 1 | import "core-js"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/core-js/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/core-js/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/electron/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 3 | a ** b; 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/electron/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.object.values"; 2 | import "core-js/modules/es7.object.entries"; 3 | import "core-js/modules/es7.object.get-own-property-descriptors"; 4 | import "core-js/modules/es7.string.pad-start"; 5 | import "core-js/modules/es7.string.pad-end"; 6 | import "core-js/modules/web.timers"; 7 | import "core-js/modules/web.immediate"; 8 | import "core-js/modules/web.dom.iterable"; 9 | 10 | 11 | a ** b; 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/electron/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "electron": "1.4" 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/empty-options/actual.js: -------------------------------------------------------------------------------- 1 | const a = "1"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/empty-options/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var a = "1"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/empty-options/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", {}] 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-built-ins/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-built-ins/expected.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babel/babel-preset-env/31f33e3656e1bd8036317c54128fdc2812a2e8aa/test/fixtures/preset-options/exclude-built-ins/expected.js -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-built-ins/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true, 9 | "exclude": [ 10 | "es7.string.pad-start", 11 | "es7.string.pad-end", 12 | "web.timers", 13 | "web.immediate", 14 | "web.dom.iterable" 15 | ] 16 | }] 17 | ] 18 | } -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-include/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 3 | async function a() { 4 | await 1; 5 | } 6 | 7 | (() => {}) -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-include/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-end"; 2 | import "core-js/modules/web.timers"; 3 | import "core-js/modules/web.immediate"; 4 | import "core-js/modules/web.dom.iterable"; 5 | import "core-js/modules/es6.map"; 6 | 7 | 8 | async function a() { 9 | await 1; 10 | } 11 | 12 | (function () {}); 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-include/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true, 9 | "exclude": [ 10 | "transform-async-to-generator", 11 | "transform-regenerator", 12 | "es7.string.pad-start" 13 | ], 14 | "include": [ 15 | "transform-es2015-arrow-functions", 16 | "es6.map" 17 | ] 18 | }] 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-regenerator/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-regenerator/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.data-view"; 3 | import "core-js/modules/es6.typed.int8-array"; 4 | import "core-js/modules/es6.typed.uint8-array"; 5 | import "core-js/modules/es6.typed.uint8-clamped-array"; 6 | import "core-js/modules/es6.typed.int16-array"; 7 | import "core-js/modules/es6.typed.uint16-array"; 8 | import "core-js/modules/es6.typed.int32-array"; 9 | import "core-js/modules/es6.typed.uint32-array"; 10 | import "core-js/modules/es6.typed.float32-array"; 11 | import "core-js/modules/es6.typed.float64-array"; 12 | import "core-js/modules/es6.map"; 13 | import "core-js/modules/es6.set"; 14 | import "core-js/modules/es6.weak-map"; 15 | import "core-js/modules/es6.weak-set"; 16 | import "core-js/modules/es6.reflect.apply"; 17 | import "core-js/modules/es6.reflect.construct"; 18 | import "core-js/modules/es6.reflect.define-property"; 19 | import "core-js/modules/es6.reflect.delete-property"; 20 | import "core-js/modules/es6.reflect.get"; 21 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 22 | import "core-js/modules/es6.reflect.get-prototype-of"; 23 | import "core-js/modules/es6.reflect.has"; 24 | import "core-js/modules/es6.reflect.is-extensible"; 25 | import "core-js/modules/es6.reflect.own-keys"; 26 | import "core-js/modules/es6.reflect.prevent-extensions"; 27 | import "core-js/modules/es6.reflect.set"; 28 | import "core-js/modules/es6.reflect.set-prototype-of"; 29 | import "core-js/modules/es6.promise"; 30 | import "core-js/modules/es6.symbol"; 31 | import "core-js/modules/es6.object.freeze"; 32 | import "core-js/modules/es6.object.seal"; 33 | import "core-js/modules/es6.object.prevent-extensions"; 34 | import "core-js/modules/es6.object.is-frozen"; 35 | import "core-js/modules/es6.object.is-sealed"; 36 | import "core-js/modules/es6.object.is-extensible"; 37 | import "core-js/modules/es6.object.get-own-property-descriptor"; 38 | import "core-js/modules/es6.object.get-prototype-of"; 39 | import "core-js/modules/es6.object.keys"; 40 | import "core-js/modules/es6.object.get-own-property-names"; 41 | import "core-js/modules/es6.object.assign"; 42 | import "core-js/modules/es6.object.is"; 43 | import "core-js/modules/es6.object.set-prototype-of"; 44 | import "core-js/modules/es6.function.name"; 45 | import "core-js/modules/es6.string.raw"; 46 | import "core-js/modules/es6.string.from-code-point"; 47 | import "core-js/modules/es6.string.code-point-at"; 48 | import "core-js/modules/es6.string.repeat"; 49 | import "core-js/modules/es6.string.starts-with"; 50 | import "core-js/modules/es6.string.ends-with"; 51 | import "core-js/modules/es6.string.includes"; 52 | import "core-js/modules/es6.regexp.flags"; 53 | import "core-js/modules/es6.regexp.match"; 54 | import "core-js/modules/es6.regexp.replace"; 55 | import "core-js/modules/es6.regexp.split"; 56 | import "core-js/modules/es6.regexp.search"; 57 | import "core-js/modules/es6.array.from"; 58 | import "core-js/modules/es6.array.of"; 59 | import "core-js/modules/es6.array.copy-within"; 60 | import "core-js/modules/es6.array.find"; 61 | import "core-js/modules/es6.array.find-index"; 62 | import "core-js/modules/es6.array.fill"; 63 | import "core-js/modules/es6.array.iterator"; 64 | import "core-js/modules/es6.number.is-finite"; 65 | import "core-js/modules/es6.number.is-integer"; 66 | import "core-js/modules/es6.number.is-safe-integer"; 67 | import "core-js/modules/es6.number.is-nan"; 68 | import "core-js/modules/es6.number.epsilon"; 69 | import "core-js/modules/es6.number.min-safe-integer"; 70 | import "core-js/modules/es6.number.max-safe-integer"; 71 | import "core-js/modules/es6.math.acosh"; 72 | import "core-js/modules/es6.math.asinh"; 73 | import "core-js/modules/es6.math.atanh"; 74 | import "core-js/modules/es6.math.cbrt"; 75 | import "core-js/modules/es6.math.clz32"; 76 | import "core-js/modules/es6.math.cosh"; 77 | import "core-js/modules/es6.math.expm1"; 78 | import "core-js/modules/es6.math.fround"; 79 | import "core-js/modules/es6.math.hypot"; 80 | import "core-js/modules/es6.math.imul"; 81 | import "core-js/modules/es6.math.log1p"; 82 | import "core-js/modules/es6.math.log10"; 83 | import "core-js/modules/es6.math.log2"; 84 | import "core-js/modules/es6.math.sign"; 85 | import "core-js/modules/es6.math.sinh"; 86 | import "core-js/modules/es6.math.tanh"; 87 | import "core-js/modules/es6.math.trunc"; 88 | import "core-js/modules/es7.array.includes"; 89 | import "core-js/modules/es7.object.values"; 90 | import "core-js/modules/es7.object.entries"; 91 | import "core-js/modules/es7.object.get-own-property-descriptors"; 92 | import "core-js/modules/es7.string.pad-start"; 93 | import "core-js/modules/es7.string.pad-end"; 94 | import "core-js/modules/web.timers"; 95 | import "core-js/modules/web.immediate"; 96 | import "core-js/modules/web.dom.iterable"; 97 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude-regenerator/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "modules": false, 5 | "useBuiltIns": true, 6 | "exclude": ["transform-regenerator"] 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude/actual.js: -------------------------------------------------------------------------------- 1 | async function a() { 2 | await 1; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude/expected.js: -------------------------------------------------------------------------------- 1 | async function a() { 2 | await 1; 3 | } -------------------------------------------------------------------------------- /test/fixtures/preset-options/exclude/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "modules": false, 5 | "useBuiltIns": true, 6 | "exclude": [ 7 | "transform-async-to-generator", 8 | "transform-regenerator" 9 | ] 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ie-11-built-ins/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ie-11-built-ins/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.int8-array"; 3 | import "core-js/modules/es6.typed.uint8-array"; 4 | import "core-js/modules/es6.typed.uint8-clamped-array"; 5 | import "core-js/modules/es6.typed.int16-array"; 6 | import "core-js/modules/es6.typed.uint16-array"; 7 | import "core-js/modules/es6.typed.int32-array"; 8 | import "core-js/modules/es6.typed.uint32-array"; 9 | import "core-js/modules/es6.typed.float32-array"; 10 | import "core-js/modules/es6.typed.float64-array"; 11 | import "core-js/modules/es6.map"; 12 | import "core-js/modules/es6.set"; 13 | import "core-js/modules/es6.weak-map"; 14 | import "core-js/modules/es6.weak-set"; 15 | import "core-js/modules/es6.reflect.apply"; 16 | import "core-js/modules/es6.reflect.construct"; 17 | import "core-js/modules/es6.reflect.define-property"; 18 | import "core-js/modules/es6.reflect.delete-property"; 19 | import "core-js/modules/es6.reflect.get"; 20 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 21 | import "core-js/modules/es6.reflect.get-prototype-of"; 22 | import "core-js/modules/es6.reflect.has"; 23 | import "core-js/modules/es6.reflect.is-extensible"; 24 | import "core-js/modules/es6.reflect.own-keys"; 25 | import "core-js/modules/es6.reflect.prevent-extensions"; 26 | import "core-js/modules/es6.reflect.set"; 27 | import "core-js/modules/es6.reflect.set-prototype-of"; 28 | import "core-js/modules/es6.promise"; 29 | import "core-js/modules/es6.symbol"; 30 | import "core-js/modules/es6.object.freeze"; 31 | import "core-js/modules/es6.object.seal"; 32 | import "core-js/modules/es6.object.prevent-extensions"; 33 | import "core-js/modules/es6.object.is-frozen"; 34 | import "core-js/modules/es6.object.is-sealed"; 35 | import "core-js/modules/es6.object.is-extensible"; 36 | import "core-js/modules/es6.object.get-own-property-descriptor"; 37 | import "core-js/modules/es6.object.get-prototype-of"; 38 | import "core-js/modules/es6.object.keys"; 39 | import "core-js/modules/es6.object.get-own-property-names"; 40 | import "core-js/modules/es6.object.assign"; 41 | import "core-js/modules/es6.object.is"; 42 | import "core-js/modules/es6.function.name"; 43 | import "core-js/modules/es6.string.raw"; 44 | import "core-js/modules/es6.string.from-code-point"; 45 | import "core-js/modules/es6.string.code-point-at"; 46 | import "core-js/modules/es6.string.repeat"; 47 | import "core-js/modules/es6.string.starts-with"; 48 | import "core-js/modules/es6.string.ends-with"; 49 | import "core-js/modules/es6.string.includes"; 50 | import "core-js/modules/es6.regexp.flags"; 51 | import "core-js/modules/es6.regexp.match"; 52 | import "core-js/modules/es6.regexp.replace"; 53 | import "core-js/modules/es6.regexp.split"; 54 | import "core-js/modules/es6.regexp.search"; 55 | import "core-js/modules/es6.array.from"; 56 | import "core-js/modules/es6.array.of"; 57 | import "core-js/modules/es6.array.copy-within"; 58 | import "core-js/modules/es6.array.find"; 59 | import "core-js/modules/es6.array.find-index"; 60 | import "core-js/modules/es6.array.fill"; 61 | import "core-js/modules/es6.array.iterator"; 62 | import "core-js/modules/es6.number.is-finite"; 63 | import "core-js/modules/es6.number.is-integer"; 64 | import "core-js/modules/es6.number.is-safe-integer"; 65 | import "core-js/modules/es6.number.is-nan"; 66 | import "core-js/modules/es6.number.epsilon"; 67 | import "core-js/modules/es6.number.min-safe-integer"; 68 | import "core-js/modules/es6.number.max-safe-integer"; 69 | import "core-js/modules/es6.math.acosh"; 70 | import "core-js/modules/es6.math.asinh"; 71 | import "core-js/modules/es6.math.atanh"; 72 | import "core-js/modules/es6.math.cbrt"; 73 | import "core-js/modules/es6.math.clz32"; 74 | import "core-js/modules/es6.math.cosh"; 75 | import "core-js/modules/es6.math.expm1"; 76 | import "core-js/modules/es6.math.fround"; 77 | import "core-js/modules/es6.math.hypot"; 78 | import "core-js/modules/es6.math.imul"; 79 | import "core-js/modules/es6.math.log1p"; 80 | import "core-js/modules/es6.math.log10"; 81 | import "core-js/modules/es6.math.log2"; 82 | import "core-js/modules/es6.math.sign"; 83 | import "core-js/modules/es6.math.sinh"; 84 | import "core-js/modules/es6.math.tanh"; 85 | import "core-js/modules/es6.math.trunc"; 86 | import "core-js/modules/es7.array.includes"; 87 | import "core-js/modules/es7.object.values"; 88 | import "core-js/modules/es7.object.entries"; 89 | import "core-js/modules/es7.object.get-own-property-descriptors"; 90 | import "core-js/modules/es7.string.pad-start"; 91 | import "core-js/modules/es7.string.pad-end"; 92 | import "core-js/modules/web.timers"; 93 | import "core-js/modules/web.immediate"; 94 | import "core-js/modules/web.dom.iterable"; 95 | import "regenerator-runtime/runtime"; 96 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ie-11-built-ins/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "ie": 11 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true, 9 | "modules": false 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/include-built-ins/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/include-built-ins/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; 6 | import "core-js/modules/es6.map"; 7 | import "core-js/modules/es6.set"; 8 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/include-built-ins/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "include": [ 8 | "es6.map", 9 | "es6.set" 10 | ], 11 | "modules": false, 12 | "useBuiltIns": true 13 | }] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/include/actual.js: -------------------------------------------------------------------------------- 1 | import a from "a"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/include/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _a = require("a"); 4 | 5 | var _a2 = _interopRequireDefault(_a); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -------------------------------------------------------------------------------- /test/fixtures/preset-options/include/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": {}, 5 | "include": ["transform-es2015-modules-commonjs"], 6 | "modules": false 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-10/actual.js: -------------------------------------------------------------------------------- 1 | const a = () => 1; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-10/expected.js: -------------------------------------------------------------------------------- 1 | const a = () => 1; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-10/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "browsers": ["ios >= 10"] 6 | }, 7 | "modules": false 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-6/actual.js: -------------------------------------------------------------------------------- 1 | import "core-js"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-6/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.int8-array"; 3 | import "core-js/modules/es6.typed.uint8-array"; 4 | import "core-js/modules/es6.typed.uint8-clamped-array"; 5 | import "core-js/modules/es6.typed.int16-array"; 6 | import "core-js/modules/es6.typed.uint16-array"; 7 | import "core-js/modules/es6.typed.int32-array"; 8 | import "core-js/modules/es6.typed.uint32-array"; 9 | import "core-js/modules/es6.typed.float32-array"; 10 | import "core-js/modules/es6.typed.float64-array"; 11 | import "core-js/modules/es6.map"; 12 | import "core-js/modules/es6.set"; 13 | import "core-js/modules/es6.weak-map"; 14 | import "core-js/modules/es6.weak-set"; 15 | import "core-js/modules/es6.reflect.apply"; 16 | import "core-js/modules/es6.reflect.construct"; 17 | import "core-js/modules/es6.reflect.define-property"; 18 | import "core-js/modules/es6.reflect.delete-property"; 19 | import "core-js/modules/es6.reflect.get"; 20 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 21 | import "core-js/modules/es6.reflect.get-prototype-of"; 22 | import "core-js/modules/es6.reflect.has"; 23 | import "core-js/modules/es6.reflect.is-extensible"; 24 | import "core-js/modules/es6.reflect.own-keys"; 25 | import "core-js/modules/es6.reflect.prevent-extensions"; 26 | import "core-js/modules/es6.reflect.set"; 27 | import "core-js/modules/es6.reflect.set-prototype-of"; 28 | import "core-js/modules/es6.promise"; 29 | import "core-js/modules/es6.symbol"; 30 | import "core-js/modules/es6.object.freeze"; 31 | import "core-js/modules/es6.object.seal"; 32 | import "core-js/modules/es6.object.prevent-extensions"; 33 | import "core-js/modules/es6.object.is-frozen"; 34 | import "core-js/modules/es6.object.is-sealed"; 35 | import "core-js/modules/es6.object.is-extensible"; 36 | import "core-js/modules/es6.object.get-own-property-descriptor"; 37 | import "core-js/modules/es6.object.get-prototype-of"; 38 | import "core-js/modules/es6.object.keys"; 39 | import "core-js/modules/es6.object.get-own-property-names"; 40 | import "core-js/modules/es6.object.assign"; 41 | import "core-js/modules/es6.object.is"; 42 | import "core-js/modules/es6.object.set-prototype-of"; 43 | import "core-js/modules/es6.function.name"; 44 | import "core-js/modules/es6.string.raw"; 45 | import "core-js/modules/es6.string.from-code-point"; 46 | import "core-js/modules/es6.string.code-point-at"; 47 | import "core-js/modules/es6.string.repeat"; 48 | import "core-js/modules/es6.string.starts-with"; 49 | import "core-js/modules/es6.string.ends-with"; 50 | import "core-js/modules/es6.string.includes"; 51 | import "core-js/modules/es6.regexp.flags"; 52 | import "core-js/modules/es6.regexp.match"; 53 | import "core-js/modules/es6.regexp.replace"; 54 | import "core-js/modules/es6.regexp.split"; 55 | import "core-js/modules/es6.regexp.search"; 56 | import "core-js/modules/es6.array.from"; 57 | import "core-js/modules/es6.array.of"; 58 | import "core-js/modules/es6.array.copy-within"; 59 | import "core-js/modules/es6.array.find"; 60 | import "core-js/modules/es6.array.find-index"; 61 | import "core-js/modules/es6.array.fill"; 62 | import "core-js/modules/es6.array.iterator"; 63 | import "core-js/modules/es6.number.is-finite"; 64 | import "core-js/modules/es6.number.is-integer"; 65 | import "core-js/modules/es6.number.is-safe-integer"; 66 | import "core-js/modules/es6.number.is-nan"; 67 | import "core-js/modules/es6.number.epsilon"; 68 | import "core-js/modules/es6.number.min-safe-integer"; 69 | import "core-js/modules/es6.number.max-safe-integer"; 70 | import "core-js/modules/es6.math.acosh"; 71 | import "core-js/modules/es6.math.asinh"; 72 | import "core-js/modules/es6.math.atanh"; 73 | import "core-js/modules/es6.math.cbrt"; 74 | import "core-js/modules/es6.math.clz32"; 75 | import "core-js/modules/es6.math.cosh"; 76 | import "core-js/modules/es6.math.expm1"; 77 | import "core-js/modules/es6.math.fround"; 78 | import "core-js/modules/es6.math.hypot"; 79 | import "core-js/modules/es6.math.imul"; 80 | import "core-js/modules/es6.math.log1p"; 81 | import "core-js/modules/es6.math.log10"; 82 | import "core-js/modules/es6.math.log2"; 83 | import "core-js/modules/es6.math.sign"; 84 | import "core-js/modules/es6.math.sinh"; 85 | import "core-js/modules/es6.math.tanh"; 86 | import "core-js/modules/es6.math.trunc"; 87 | import "core-js/modules/es7.array.includes"; 88 | import "core-js/modules/es7.object.values"; 89 | import "core-js/modules/es7.object.entries"; 90 | import "core-js/modules/es7.object.get-own-property-descriptors"; 91 | import "core-js/modules/es7.string.pad-start"; 92 | import "core-js/modules/es7.string.pad-end"; 93 | import "core-js/modules/web.timers"; 94 | import "core-js/modules/web.immediate"; 95 | import "core-js/modules/web.dom.iterable"; 96 | import "regenerator-runtime/runtime"; 97 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/ios-6/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "browsers": ["ios >= 6"] 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/modules-false/actual.js: -------------------------------------------------------------------------------- 1 | import a from "a"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/modules-false/expected.js: -------------------------------------------------------------------------------- 1 | import a from "a"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/modules-false/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "modules": false 5 | }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-options/actual.js: -------------------------------------------------------------------------------- 1 | const a = "1"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-options/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var a = "1"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-options/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "../../../../lib" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-transform/actual.js: -------------------------------------------------------------------------------- 1 | import "not-core-js"; 2 | import "not-babel-polyfill"; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-transform/expected.js: -------------------------------------------------------------------------------- 1 | import "not-core-js"; 2 | import "not-babel-polyfill"; -------------------------------------------------------------------------------- /test/fixtures/preset-options/no-transform/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": "55" 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/spec/actual.js: -------------------------------------------------------------------------------- 1 | const bar = "bar"; 2 | const x = () => `foo${bar}`; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/spec/expected.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | function _newArrowCheck(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } } 4 | 5 | var bar = "bar"; 6 | var x = function () { 7 | _newArrowCheck(undefined, undefined); 8 | 9 | return "foo" + bar; 10 | }.bind(undefined); -------------------------------------------------------------------------------- /test/fixtures/preset-options/spec/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "spec": true 5 | }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/uglify/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 3 | const a = 1; 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/uglify/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; 6 | import "regenerator-runtime/runtime"; 7 | 8 | 9 | var a = 1; 10 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/uglify/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55, 6 | "uglify": true 7 | }, 8 | "modules": false, 9 | "useBuiltIns": true 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-all-exec/exec.js: -------------------------------------------------------------------------------- 1 | if (parseInt(process.version.slice(1)) > 5) { 2 | require('babel-polyfill'); 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-all-exec/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "useBuiltIns": true 5 | }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-all/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-all/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.data-view"; 3 | import "core-js/modules/es6.typed.int8-array"; 4 | import "core-js/modules/es6.typed.uint8-array"; 5 | import "core-js/modules/es6.typed.uint8-clamped-array"; 6 | import "core-js/modules/es6.typed.int16-array"; 7 | import "core-js/modules/es6.typed.uint16-array"; 8 | import "core-js/modules/es6.typed.int32-array"; 9 | import "core-js/modules/es6.typed.uint32-array"; 10 | import "core-js/modules/es6.typed.float32-array"; 11 | import "core-js/modules/es6.typed.float64-array"; 12 | import "core-js/modules/es6.map"; 13 | import "core-js/modules/es6.set"; 14 | import "core-js/modules/es6.weak-map"; 15 | import "core-js/modules/es6.weak-set"; 16 | import "core-js/modules/es6.reflect.apply"; 17 | import "core-js/modules/es6.reflect.construct"; 18 | import "core-js/modules/es6.reflect.define-property"; 19 | import "core-js/modules/es6.reflect.delete-property"; 20 | import "core-js/modules/es6.reflect.get"; 21 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 22 | import "core-js/modules/es6.reflect.get-prototype-of"; 23 | import "core-js/modules/es6.reflect.has"; 24 | import "core-js/modules/es6.reflect.is-extensible"; 25 | import "core-js/modules/es6.reflect.own-keys"; 26 | import "core-js/modules/es6.reflect.prevent-extensions"; 27 | import "core-js/modules/es6.reflect.set"; 28 | import "core-js/modules/es6.reflect.set-prototype-of"; 29 | import "core-js/modules/es6.promise"; 30 | import "core-js/modules/es6.symbol"; 31 | import "core-js/modules/es6.object.freeze"; 32 | import "core-js/modules/es6.object.seal"; 33 | import "core-js/modules/es6.object.prevent-extensions"; 34 | import "core-js/modules/es6.object.is-frozen"; 35 | import "core-js/modules/es6.object.is-sealed"; 36 | import "core-js/modules/es6.object.is-extensible"; 37 | import "core-js/modules/es6.object.get-own-property-descriptor"; 38 | import "core-js/modules/es6.object.get-prototype-of"; 39 | import "core-js/modules/es6.object.keys"; 40 | import "core-js/modules/es6.object.get-own-property-names"; 41 | import "core-js/modules/es6.object.assign"; 42 | import "core-js/modules/es6.object.is"; 43 | import "core-js/modules/es6.object.set-prototype-of"; 44 | import "core-js/modules/es6.function.name"; 45 | import "core-js/modules/es6.string.raw"; 46 | import "core-js/modules/es6.string.from-code-point"; 47 | import "core-js/modules/es6.string.code-point-at"; 48 | import "core-js/modules/es6.string.repeat"; 49 | import "core-js/modules/es6.string.starts-with"; 50 | import "core-js/modules/es6.string.ends-with"; 51 | import "core-js/modules/es6.string.includes"; 52 | import "core-js/modules/es6.regexp.flags"; 53 | import "core-js/modules/es6.regexp.match"; 54 | import "core-js/modules/es6.regexp.replace"; 55 | import "core-js/modules/es6.regexp.split"; 56 | import "core-js/modules/es6.regexp.search"; 57 | import "core-js/modules/es6.array.from"; 58 | import "core-js/modules/es6.array.of"; 59 | import "core-js/modules/es6.array.copy-within"; 60 | import "core-js/modules/es6.array.find"; 61 | import "core-js/modules/es6.array.find-index"; 62 | import "core-js/modules/es6.array.fill"; 63 | import "core-js/modules/es6.array.iterator"; 64 | import "core-js/modules/es6.number.is-finite"; 65 | import "core-js/modules/es6.number.is-integer"; 66 | import "core-js/modules/es6.number.is-safe-integer"; 67 | import "core-js/modules/es6.number.is-nan"; 68 | import "core-js/modules/es6.number.epsilon"; 69 | import "core-js/modules/es6.number.min-safe-integer"; 70 | import "core-js/modules/es6.number.max-safe-integer"; 71 | import "core-js/modules/es6.math.acosh"; 72 | import "core-js/modules/es6.math.asinh"; 73 | import "core-js/modules/es6.math.atanh"; 74 | import "core-js/modules/es6.math.cbrt"; 75 | import "core-js/modules/es6.math.clz32"; 76 | import "core-js/modules/es6.math.cosh"; 77 | import "core-js/modules/es6.math.expm1"; 78 | import "core-js/modules/es6.math.fround"; 79 | import "core-js/modules/es6.math.hypot"; 80 | import "core-js/modules/es6.math.imul"; 81 | import "core-js/modules/es6.math.log1p"; 82 | import "core-js/modules/es6.math.log10"; 83 | import "core-js/modules/es6.math.log2"; 84 | import "core-js/modules/es6.math.sign"; 85 | import "core-js/modules/es6.math.sinh"; 86 | import "core-js/modules/es6.math.tanh"; 87 | import "core-js/modules/es6.math.trunc"; 88 | import "core-js/modules/es7.array.includes"; 89 | import "core-js/modules/es7.object.values"; 90 | import "core-js/modules/es7.object.entries"; 91 | import "core-js/modules/es7.object.get-own-property-descriptors"; 92 | import "core-js/modules/es7.string.pad-start"; 93 | import "core-js/modules/es7.string.pad-end"; 94 | import "core-js/modules/web.timers"; 95 | import "core-js/modules/web.immediate"; 96 | import "core-js/modules/web.dom.iterable"; 97 | import "regenerator-runtime/runtime"; 98 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-all/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "modules": false, 5 | "useBuiltIns": true 6 | }] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-48/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 1 ** 2; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-48/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.int8-array"; 3 | import "core-js/modules/es6.typed.uint8-array"; 4 | import "core-js/modules/es6.typed.uint8-clamped-array"; 5 | import "core-js/modules/es6.typed.int16-array"; 6 | import "core-js/modules/es6.typed.uint16-array"; 7 | import "core-js/modules/es6.typed.int32-array"; 8 | import "core-js/modules/es6.typed.uint32-array"; 9 | import "core-js/modules/es6.typed.float32-array"; 10 | import "core-js/modules/es6.typed.float64-array"; 11 | import "core-js/modules/es6.map"; 12 | import "core-js/modules/es6.set"; 13 | import "core-js/modules/es6.weak-map"; 14 | import "core-js/modules/es6.weak-set"; 15 | import "core-js/modules/es6.reflect.apply"; 16 | import "core-js/modules/es6.reflect.construct"; 17 | import "core-js/modules/es6.reflect.define-property"; 18 | import "core-js/modules/es6.reflect.delete-property"; 19 | import "core-js/modules/es6.reflect.get"; 20 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 21 | import "core-js/modules/es6.reflect.get-prototype-of"; 22 | import "core-js/modules/es6.reflect.has"; 23 | import "core-js/modules/es6.reflect.is-extensible"; 24 | import "core-js/modules/es6.reflect.own-keys"; 25 | import "core-js/modules/es6.reflect.prevent-extensions"; 26 | import "core-js/modules/es6.reflect.set"; 27 | import "core-js/modules/es6.reflect.set-prototype-of"; 28 | import "core-js/modules/es6.promise"; 29 | import "core-js/modules/es6.symbol"; 30 | import "core-js/modules/es6.function.name"; 31 | import "core-js/modules/es6.regexp.flags"; 32 | import "core-js/modules/es6.regexp.match"; 33 | import "core-js/modules/es6.regexp.replace"; 34 | import "core-js/modules/es6.regexp.split"; 35 | import "core-js/modules/es6.regexp.search"; 36 | import "core-js/modules/es6.array.from"; 37 | import "core-js/modules/es7.object.values"; 38 | import "core-js/modules/es7.object.entries"; 39 | import "core-js/modules/es7.object.get-own-property-descriptors"; 40 | import "core-js/modules/es7.string.pad-start"; 41 | import "core-js/modules/es7.string.pad-end"; 42 | import "core-js/modules/web.timers"; 43 | import "core-js/modules/web.immediate"; 44 | import "core-js/modules/web.dom.iterable"; 45 | import "regenerator-runtime/runtime"; 46 | 47 | Math.pow(1, 2); 48 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-48/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 48 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-49/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 1 ** 2; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-49/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.int8-array"; 3 | import "core-js/modules/es6.typed.uint8-array"; 4 | import "core-js/modules/es6.typed.uint8-clamped-array"; 5 | import "core-js/modules/es6.typed.int16-array"; 6 | import "core-js/modules/es6.typed.uint16-array"; 7 | import "core-js/modules/es6.typed.int32-array"; 8 | import "core-js/modules/es6.typed.uint32-array"; 9 | import "core-js/modules/es6.typed.float32-array"; 10 | import "core-js/modules/es6.typed.float64-array"; 11 | import "core-js/modules/es6.map"; 12 | import "core-js/modules/es6.set"; 13 | import "core-js/modules/es6.weak-map"; 14 | import "core-js/modules/es6.weak-set"; 15 | import "core-js/modules/es6.promise"; 16 | import "core-js/modules/es6.symbol"; 17 | import "core-js/modules/es6.function.name"; 18 | import "core-js/modules/es6.regexp.match"; 19 | import "core-js/modules/es6.regexp.replace"; 20 | import "core-js/modules/es6.regexp.split"; 21 | import "core-js/modules/es6.regexp.search"; 22 | import "core-js/modules/es6.array.from"; 23 | import "core-js/modules/es7.object.values"; 24 | import "core-js/modules/es7.object.entries"; 25 | import "core-js/modules/es7.object.get-own-property-descriptors"; 26 | import "core-js/modules/es7.string.pad-start"; 27 | import "core-js/modules/es7.string.pad-end"; 28 | import "core-js/modules/web.timers"; 29 | import "core-js/modules/web.immediate"; 30 | import "core-js/modules/web.dom.iterable"; 31 | import "regenerator-runtime/runtime"; 32 | 33 | Math.pow(1, 2); 34 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chrome-49/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 49 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chromeandroid/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 1 ** 2; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chromeandroid/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/web.timers"; 2 | import "core-js/modules/web.immediate"; 3 | import "core-js/modules/web.dom.iterable"; 4 | 5 | 1 ** 2; -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-chromeandroid/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "browsers": "chromeandroid 59" 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-ie-9/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-ie-9/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es6.typed.array-buffer"; 2 | import "core-js/modules/es6.typed.data-view"; 3 | import "core-js/modules/es6.typed.int8-array"; 4 | import "core-js/modules/es6.typed.uint8-array"; 5 | import "core-js/modules/es6.typed.uint8-clamped-array"; 6 | import "core-js/modules/es6.typed.int16-array"; 7 | import "core-js/modules/es6.typed.uint16-array"; 8 | import "core-js/modules/es6.typed.int32-array"; 9 | import "core-js/modules/es6.typed.uint32-array"; 10 | import "core-js/modules/es6.typed.float32-array"; 11 | import "core-js/modules/es6.typed.float64-array"; 12 | import "core-js/modules/es6.map"; 13 | import "core-js/modules/es6.set"; 14 | import "core-js/modules/es6.weak-map"; 15 | import "core-js/modules/es6.weak-set"; 16 | import "core-js/modules/es6.reflect.apply"; 17 | import "core-js/modules/es6.reflect.construct"; 18 | import "core-js/modules/es6.reflect.define-property"; 19 | import "core-js/modules/es6.reflect.delete-property"; 20 | import "core-js/modules/es6.reflect.get"; 21 | import "core-js/modules/es6.reflect.get-own-property-descriptor"; 22 | import "core-js/modules/es6.reflect.get-prototype-of"; 23 | import "core-js/modules/es6.reflect.has"; 24 | import "core-js/modules/es6.reflect.is-extensible"; 25 | import "core-js/modules/es6.reflect.own-keys"; 26 | import "core-js/modules/es6.reflect.prevent-extensions"; 27 | import "core-js/modules/es6.reflect.set"; 28 | import "core-js/modules/es6.reflect.set-prototype-of"; 29 | import "core-js/modules/es6.promise"; 30 | import "core-js/modules/es6.symbol"; 31 | import "core-js/modules/es6.object.freeze"; 32 | import "core-js/modules/es6.object.seal"; 33 | import "core-js/modules/es6.object.prevent-extensions"; 34 | import "core-js/modules/es6.object.is-frozen"; 35 | import "core-js/modules/es6.object.is-sealed"; 36 | import "core-js/modules/es6.object.is-extensible"; 37 | import "core-js/modules/es6.object.get-own-property-descriptor"; 38 | import "core-js/modules/es6.object.get-prototype-of"; 39 | import "core-js/modules/es6.object.keys"; 40 | import "core-js/modules/es6.object.get-own-property-names"; 41 | import "core-js/modules/es6.object.assign"; 42 | import "core-js/modules/es6.object.is"; 43 | import "core-js/modules/es6.object.set-prototype-of"; 44 | import "core-js/modules/es6.function.name"; 45 | import "core-js/modules/es6.string.raw"; 46 | import "core-js/modules/es6.string.from-code-point"; 47 | import "core-js/modules/es6.string.code-point-at"; 48 | import "core-js/modules/es6.string.repeat"; 49 | import "core-js/modules/es6.string.starts-with"; 50 | import "core-js/modules/es6.string.ends-with"; 51 | import "core-js/modules/es6.string.includes"; 52 | import "core-js/modules/es6.regexp.flags"; 53 | import "core-js/modules/es6.regexp.match"; 54 | import "core-js/modules/es6.regexp.replace"; 55 | import "core-js/modules/es6.regexp.split"; 56 | import "core-js/modules/es6.regexp.search"; 57 | import "core-js/modules/es6.array.from"; 58 | import "core-js/modules/es6.array.of"; 59 | import "core-js/modules/es6.array.copy-within"; 60 | import "core-js/modules/es6.array.find"; 61 | import "core-js/modules/es6.array.find-index"; 62 | import "core-js/modules/es6.array.fill"; 63 | import "core-js/modules/es6.array.iterator"; 64 | import "core-js/modules/es6.number.is-finite"; 65 | import "core-js/modules/es6.number.is-integer"; 66 | import "core-js/modules/es6.number.is-safe-integer"; 67 | import "core-js/modules/es6.number.is-nan"; 68 | import "core-js/modules/es6.number.epsilon"; 69 | import "core-js/modules/es6.number.min-safe-integer"; 70 | import "core-js/modules/es6.number.max-safe-integer"; 71 | import "core-js/modules/es6.math.acosh"; 72 | import "core-js/modules/es6.math.asinh"; 73 | import "core-js/modules/es6.math.atanh"; 74 | import "core-js/modules/es6.math.cbrt"; 75 | import "core-js/modules/es6.math.clz32"; 76 | import "core-js/modules/es6.math.cosh"; 77 | import "core-js/modules/es6.math.expm1"; 78 | import "core-js/modules/es6.math.fround"; 79 | import "core-js/modules/es6.math.hypot"; 80 | import "core-js/modules/es6.math.imul"; 81 | import "core-js/modules/es6.math.log1p"; 82 | import "core-js/modules/es6.math.log10"; 83 | import "core-js/modules/es6.math.log2"; 84 | import "core-js/modules/es6.math.sign"; 85 | import "core-js/modules/es6.math.sinh"; 86 | import "core-js/modules/es6.math.tanh"; 87 | import "core-js/modules/es6.math.trunc"; 88 | import "core-js/modules/es7.array.includes"; 89 | import "core-js/modules/es7.object.values"; 90 | import "core-js/modules/es7.object.entries"; 91 | import "core-js/modules/es7.object.get-own-property-descriptors"; 92 | import "core-js/modules/es7.string.pad-start"; 93 | import "core-js/modules/es7.string.pad-end"; 94 | import "core-js/modules/web.timers"; 95 | import "core-js/modules/web.immediate"; 96 | import "core-js/modules/web.dom.iterable"; 97 | import "regenerator-runtime/runtime"; 98 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-ie-9/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "ie": 9 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true, 9 | "modules": false 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-import/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | 1 ** 2; 3 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-import/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; 6 | 7 | 1 ** 2; -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-import/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-multiple-imports/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | import "babel-polyfill"; 3 | 1 ** 2; 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-multiple-imports/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; 6 | 7 | 1 ** 2; -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-multiple-imports/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": 55 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node-web/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node-web/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "core-js/modules/web.timers"; 4 | import "core-js/modules/web.immediate"; 5 | import "core-js/modules/web.dom.iterable"; 6 | import "regenerator-runtime/runtime"; 7 | 8 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node-web/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": "55", 6 | "node": "7.6", 7 | "uglify": true 8 | }, 9 | "modules": false, 10 | "useBuiltIns": true 11 | }] 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node/actual.js: -------------------------------------------------------------------------------- 1 | import "babel-polyfill"; 2 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node/expected.js: -------------------------------------------------------------------------------- 1 | import "core-js/modules/es7.string.pad-start"; 2 | import "core-js/modules/es7.string.pad-end"; 3 | import "regenerator-runtime/runtime"; 4 | 5 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-node/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "node": "7.6", 6 | "uglify": true 7 | }, 8 | "modules": false, 9 | "useBuiltIns": true 10 | }] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-require/actual.js: -------------------------------------------------------------------------------- 1 | require("babel-polyfill"); 2 | 3 | 1 ** 2; 4 | -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-require/expected.js: -------------------------------------------------------------------------------- 1 | require("core-js/modules/es7.string.pad-start"); 2 | 3 | require("core-js/modules/es7.string.pad-end"); 4 | 5 | require("core-js/modules/web.timers"); 6 | 7 | require("core-js/modules/web.immediate"); 8 | 9 | require("core-js/modules/web.dom.iterable"); 10 | 11 | 1 ** 2; -------------------------------------------------------------------------------- /test/fixtures/preset-options/use-builtins-require/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "targets": { 5 | "chrome": "55" 6 | }, 7 | "modules": false, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/sanity/check-es2015-constants/exec.js: -------------------------------------------------------------------------------- 1 | const one = 123; 2 | one = 432; 3 | -------------------------------------------------------------------------------- /test/fixtures/sanity/check-es2015-constants/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib"] 4 | ], 5 | "throws": "\"one\" is read-only" 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/sanity/transform-duplicate-keys/actual.js: -------------------------------------------------------------------------------- 1 | var a = { b:1, b: 2}; 2 | -------------------------------------------------------------------------------- /test/fixtures/sanity/transform-duplicate-keys/expected.js: -------------------------------------------------------------------------------- 1 | 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; } 2 | 3 | var a = _defineProperty({ b: 1 }, "b", 2); -------------------------------------------------------------------------------- /test/fixtures/sanity/transform-duplicate-keys/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["../../../../lib", { 4 | "modules": false 5 | }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/index.spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const babelPresetEnv = require("../lib/index.js"); 4 | const assert = require("assert"); 5 | 6 | describe("babel-preset-env", () => { 7 | describe("isPluginRequired", () => { 8 | const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`; 9 | 10 | it("returns true if no targets are specified", () => { 11 | assert.strictEqual(babelPresetEnv.isPluginRequired({}, {}), true); 12 | }); 13 | 14 | it("returns true if plugin feature is not implemented in one or more targets", () => { 15 | let targets; 16 | const plugin = { 17 | edge: false, 18 | firefox: 45, 19 | chrome: 49, 20 | }; 21 | 22 | targets = { 23 | chrome: MAX_VERSION, 24 | firefox: MAX_VERSION, 25 | }; 26 | assert.strictEqual( 27 | babelPresetEnv.isPluginRequired(targets, plugin), 28 | false, 29 | ); 30 | 31 | targets = { 32 | edge: "12", 33 | }; 34 | assert.strictEqual( 35 | babelPresetEnv.isPluginRequired(targets, plugin), 36 | true, 37 | ); 38 | }); 39 | 40 | it("returns false if plugin feature is implemented by lower than target", () => { 41 | const plugin = { 42 | chrome: 49, 43 | }; 44 | const targets = { 45 | chrome: MAX_VERSION, 46 | }; 47 | 48 | assert.strictEqual( 49 | babelPresetEnv.isPluginRequired(targets, plugin), 50 | false, 51 | ); 52 | }); 53 | 54 | it("returns false if plugin feature is implemented is equal to target", () => { 55 | const plugin = { 56 | chrome: 49, 57 | }; 58 | const targets = { 59 | chrome: "49.0.0", 60 | }; 61 | assert.strictEqual( 62 | babelPresetEnv.isPluginRequired(targets, plugin), 63 | false, 64 | ); 65 | }); 66 | 67 | it("returns true if plugin feature is implemented is greater than target", () => { 68 | const plugin = { 69 | chrome: 50, 70 | }; 71 | const targets = { 72 | chrome: "49.0.0", 73 | }; 74 | assert.strictEqual( 75 | babelPresetEnv.isPluginRequired(targets, plugin), 76 | true, 77 | ); 78 | }); 79 | 80 | it("returns true if uglify is specified as a target", () => { 81 | const plugin = { 82 | chrome: 50, 83 | }; 84 | const targets = { 85 | chrome: "55.0.0", 86 | uglify: true, 87 | }; 88 | assert.strictEqual( 89 | babelPresetEnv.isPluginRequired(targets, plugin), 90 | true, 91 | ); 92 | }); 93 | 94 | it("returns when target is a decimal", () => { 95 | const plugin = { 96 | node: 6.9, 97 | }; 98 | const targets = { 99 | node: "6.10.0", 100 | }; 101 | assert.strictEqual( 102 | babelPresetEnv.isPluginRequired(targets, plugin), 103 | false, 104 | ); 105 | }); 106 | 107 | it("throws an error if target version is invalid", () => { 108 | const plugin = { 109 | chrome: 50, 110 | }; 111 | const targets = { 112 | chrome: 55, 113 | }; 114 | assert.throws(() => babelPresetEnv.isPluginRequired(targets, plugin)); 115 | }); 116 | }); 117 | 118 | describe("transformIncludesAndExcludes", function() { 119 | it("should return in transforms array", function() { 120 | assert.deepEqual( 121 | babelPresetEnv.transformIncludesAndExcludes(["transform-es2015-arrow-functions"]), 122 | { 123 | all: ["transform-es2015-arrow-functions"], 124 | plugins: ["transform-es2015-arrow-functions"], 125 | builtIns: [] 126 | } 127 | ); 128 | }); 129 | 130 | it("should return in built-ins array", function() { 131 | assert.deepEqual( 132 | babelPresetEnv.transformIncludesAndExcludes(["es6.map"]), 133 | { 134 | all: ["es6.map"], 135 | plugins: [], 136 | builtIns: ["es6.map"] 137 | } 138 | ); 139 | }); 140 | }); 141 | }); 142 | -------------------------------------------------------------------------------- /test/normalize-options.spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const normalizeOptions = require("../lib/normalize-options.js"); 4 | const assert = require("assert"); 5 | 6 | const { 7 | checkDuplicateIncludeExcludes, 8 | normalizePluginNames, 9 | validateIncludesAndExcludes, 10 | validateLooseOption, 11 | validateModulesOption, 12 | validateSpecOption, 13 | } = normalizeOptions; 14 | 15 | describe("normalize-options", () => { 16 | describe("normalizeOptions", () => { 17 | it("should return normalized `include` and `exclude`", () => { 18 | const normalized = normalizeOptions.default({ 19 | include: [ 20 | "babel-plugin-transform-es2015-spread", 21 | "transform-es2015-classes" 22 | ] 23 | }); 24 | assert.deepEqual(normalized.include, [ 25 | "transform-es2015-spread", 26 | "transform-es2015-classes" 27 | ]); 28 | }); 29 | 30 | it("should throw if duplicate names in `include` and `exclude`", () => { 31 | const normalizeWithSameIncludes = () => { 32 | normalizeOptions.default({ 33 | include: [ 34 | "babel-plugin-transform-es2015-spread", 35 | ], 36 | exclude: [ 37 | "transform-es2015-spread" 38 | ] 39 | }); 40 | }; 41 | assert.throws(normalizeWithSameIncludes, Error); 42 | }); 43 | }); 44 | describe("validateLooseOption", () => { 45 | it("`undefined` option returns false", () => { 46 | assert(validateLooseOption() === false); 47 | }); 48 | 49 | it("`false` option returns false", () => { 50 | assert(validateLooseOption(false) === false); 51 | }); 52 | 53 | it("`true` option returns true", () => { 54 | assert(validateLooseOption(true) === true); 55 | }); 56 | 57 | it("array option is invalid", () => { 58 | assert.throws(() => { 59 | validateLooseOption([]); 60 | }, Error); 61 | }); 62 | }); 63 | 64 | describe("validateSpecOption", () => { 65 | it("`undefined` option returns false", () => { 66 | assert(validateSpecOption() === false); 67 | }); 68 | 69 | it("`false` option returns false", () => { 70 | assert(validateSpecOption(false) === false); 71 | }); 72 | 73 | it("`true` option returns true", () => { 74 | assert(validateSpecOption(true) === true); 75 | }); 76 | }); 77 | 78 | describe("checkDuplicateIncludeExcludes", function() { 79 | it("should throw if duplicate names in both", function() { 80 | assert.throws(() => { 81 | checkDuplicateIncludeExcludes( 82 | ["transform-regenerator", "map"], 83 | ["transform-regenerator", "map"] 84 | ); 85 | }, Error); 86 | }); 87 | 88 | it("should not throw if no duplicate names in both", function() { 89 | assert.doesNotThrow(() => { 90 | checkDuplicateIncludeExcludes( 91 | ["transform-regenerator"], 92 | ["map"] 93 | ); 94 | }, Error); 95 | }); 96 | }); 97 | 98 | describe("normalizePluginNames", function() { 99 | it("should drop `babel-plugin-` prefix if needed", function() { 100 | assert.deepEqual( 101 | normalizePluginNames([ 102 | "babel-plugin-transform-es2015-object-super", 103 | "transform-es2015-parameters" 104 | ]), 105 | ["transform-es2015-object-super", "transform-es2015-parameters"] 106 | ); 107 | }); 108 | 109 | it("should not throw if no duplicate names in both", function() { 110 | assert.doesNotThrow(() => { 111 | checkDuplicateIncludeExcludes( 112 | ["transform-regenerator"], 113 | ["map"] 114 | ); 115 | }, Error); 116 | }); 117 | }); 118 | 119 | describe("validateModulesOption", () => { 120 | it("`undefined` option returns commonjs", () => { 121 | assert(validateModulesOption() === "commonjs"); 122 | }); 123 | 124 | it("`false` option returns commonjs", () => { 125 | assert(validateModulesOption(false) === false); 126 | }); 127 | 128 | it("commonjs option is valid", () => { 129 | assert(validateModulesOption("commonjs") === "commonjs"); 130 | }); 131 | 132 | it("systemjs option is valid", () => { 133 | assert(validateModulesOption("systemjs") === "systemjs"); 134 | }); 135 | 136 | it("amd option is valid", () => { 137 | assert(validateModulesOption("amd") === "amd"); 138 | }); 139 | 140 | it("umd option is valid", () => { 141 | assert(validateModulesOption("umd") === "umd"); 142 | }); 143 | 144 | it("`true` option is invalid", () => { 145 | assert.throws(() => { 146 | validateModulesOption(true); 147 | }, Error); 148 | }); 149 | 150 | it("array option is invalid", () => { 151 | assert.throws(() => { 152 | assert(validateModulesOption([])); 153 | }, Error); 154 | }); 155 | }); 156 | describe("validateIncludesAndExcludes", function() { 157 | it("should return empty arrays if undefined", function() { 158 | assert.deepEqual(validateIncludesAndExcludes(), []); 159 | }); 160 | it("should throw if not in features", function() { 161 | assert.throws(() => { 162 | validateIncludesAndExcludes(["asdf"]); 163 | }, Error); 164 | }); 165 | }); 166 | }); 167 | -------------------------------------------------------------------------------- /test/targets-parser.spec.js: -------------------------------------------------------------------------------- 1 | import assert from "assert"; 2 | import getTargets from "../src/targets-parser"; 3 | 4 | describe("getTargets", () => { 5 | it("parses", () => { 6 | assert.deepEqual( 7 | getTargets({ 8 | chrome: 49, 9 | firefox: "55", 10 | ie: "9", 11 | node: "6.10", 12 | electron: "1.6", 13 | }), 14 | { 15 | chrome: "49.0.0", 16 | electron: "1.6.0", 17 | firefox: "55.0.0", 18 | ie: "9.0.0", 19 | node: "6.10.0", 20 | }, 21 | ); 22 | }); 23 | 24 | describe("browser", () => { 25 | it("merges browser key targets", () => { 26 | assert.deepEqual( 27 | getTargets({ 28 | browsers: "chrome 56, ie 11, firefox 51, safari 9", 29 | chrome: "49", 30 | firefox: "55", 31 | ie: "9", 32 | }), 33 | { 34 | chrome: "49.0.0", 35 | firefox: "55.0.0", 36 | ie: "9.0.0", 37 | safari: "9.0.0", 38 | }, 39 | ); 40 | }); 41 | 42 | it("ignores invalid", () => { 43 | assert.deepEqual( 44 | getTargets({ 45 | browsers: 59, 46 | chrome: "49", 47 | firefox: "55", 48 | ie: "11", 49 | }), 50 | { 51 | chrome: "49.0.0", 52 | firefox: "55.0.0", 53 | ie: "11.0.0", 54 | }, 55 | ); 56 | }); 57 | }); 58 | 59 | describe("node", () => { 60 | it("should return the current node version with option 'current'", () => { 61 | assert.deepEqual( 62 | getTargets({ 63 | node: true, 64 | }), 65 | { 66 | node: process.versions.node, 67 | }, 68 | ); 69 | }); 70 | }); 71 | 72 | describe("electron", () => { 73 | it("should be its own target", () => { 74 | assert.deepEqual( 75 | getTargets({ 76 | chrome: "46", 77 | electron: "0.34", 78 | }), 79 | { 80 | chrome: "46.0.0", 81 | electron: "0.34.0", 82 | }, 83 | ); 84 | }); 85 | }); 86 | 87 | describe("uglify", () => { 88 | it("should work with `true`", function() { 89 | assert.deepEqual( 90 | getTargets({ 91 | uglify: true, 92 | }), 93 | { 94 | uglify: true, 95 | }, 96 | ); 97 | }); 98 | 99 | it("should ignore `false`", function() { 100 | assert.deepEqual( 101 | getTargets({ 102 | uglify: false, 103 | }), 104 | {}, 105 | ); 106 | }); 107 | 108 | it("should ignore `null`", function() { 109 | assert.deepEqual( 110 | getTargets({ 111 | uglify: null, 112 | }), 113 | {}, 114 | ); 115 | }); 116 | }); 117 | }); 118 | -------------------------------------------------------------------------------- /test/utils.spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const utils = require("../lib/utils"); 4 | const assert = require("assert"); 5 | 6 | const { 7 | prettifyTargets, 8 | prettifyVersion, 9 | semverify, 10 | } = utils; 11 | 12 | describe("utils", () => { 13 | describe("semverify", () => { 14 | it("returns", () => { 15 | assert.strictEqual(semverify("1"), "1.0.0"); 16 | assert.strictEqual(semverify("1.0"), "1.0.0"); 17 | assert.strictEqual(semverify("1.0.0"), "1.0.0"); 18 | assert.strictEqual(semverify(1), "1.0.0"); 19 | assert.strictEqual(semverify(1.2), "1.2.0"); 20 | }); 21 | }); 22 | 23 | describe("prettifyVersion", () => { 24 | it("returns", () => { 25 | assert.strictEqual(prettifyVersion(true), true); 26 | assert.strictEqual(prettifyVersion("0.16.0"), "0.16"); 27 | assert.strictEqual(prettifyVersion("1.0.0"), "1"); 28 | assert.strictEqual(prettifyVersion("1.1.0"), "1.1"); 29 | assert.strictEqual(prettifyVersion("1.0.2"), "1.0.2"); 30 | assert.strictEqual(prettifyVersion("1.2.3"), "1.2.3"); 31 | }); 32 | }); 33 | 34 | describe("prettifyTargets", () => { 35 | it("returns", () => { 36 | assert.deepEqual(prettifyTargets({}), {}); 37 | 38 | assert.deepEqual( 39 | prettifyTargets({ 40 | uglify: true, 41 | }), 42 | { 43 | uglify: true, 44 | }, 45 | ); 46 | 47 | assert.deepEqual( 48 | prettifyTargets({ 49 | chrome: "54.0.0", 50 | electron: "1.6.0", 51 | node: "0.12.0", 52 | }), 53 | { 54 | chrome: "54", 55 | electron: "1.6", 56 | node: "0.12", 57 | }, 58 | ); 59 | }); 60 | }); 61 | }); 62 | --------------------------------------------------------------------------------