diff --git a/CHANGELOG.md b/CHANGELOG.md index 96d28278e150..f90ac42c1212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,107 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog. +## 6.24.0 (2017-03-13) + +A quick release for 2 features: + +- Thanks to @rwjblue, there is now a `noInterop` option for our `es2015-modules` transform to remove the `interopRequireDefault` and `interopRequireWildcard` helpers. + +Input + +```js +import foo from "foo"; +foo; +``` + +Regular Output + +```js +var _foo = require("foo"); +var _foo2 = _interopRequireDefault(_foo); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +_foo2.default; +``` + +Output with option `noInterop` + +```js +"use strict"; +var _foo = require("foo"); +(0, _foo.default)(); +``` + +> This also helps [ember-cli migrate to Babel 6](https://github.com/ember-cli/ember-cli/pull/6828). + +- @izaakschroeder has added `dirname` to the preset constructor which presets can use to resolve things relative to files. + +Example usage of `fileContext.dirname` in a preset + +```js +module.exports = function preset (context, options, fileContext) { + if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) { + return { + plugins: ['plugin-here'], + }; + } + return {}; +}; +``` + +> This will help out with reusing a [`browserslist` file for babel-preset-env](https://github.com/babel/babel-preset-env/issues/26) and for plugins like https://github.com/tleunen/babel-plugin-module-resolver. + +#### :rocket: New Feature +* `babel-plugin-transform-es2015-modules-amd`, `babel-plugin-transform-es2015-modules-commonjs` + * [#5427](https://github.com/babel/babel/pull/5427) Backport `noInterop` flag for modules to 6.x. ([@rwjblue](https://github.com/rwjblue)) +* `babel-core` + * [#4834](https://github.com/babel/babel/pull/4834) Pass `dirname` as extra metadata to preset constructor. ([@izaakschroeder](https://github.com/izaakschroeder)) + +#### :bug: Bug Fix +* `babel-generator` + * [#5453](https://github.com/babel/babel/pull/5453) Keep parentheses for logical expression when in await expression. ([@aaronang](https://github.com/aaronang)) + * [#5339](https://github.com/babel/babel/pull/5339) Wrap some generated do expressions in parens. ([@zjmiller](https://github.com/zjmiller)) +* `babel-generator`, `babel-plugin-transform-object-rest-spread` + * [#5322](https://github.com/babel/babel/pull/5322) Fix for-await printing. ([@danez](https://github.com/danez)) + +#### :memo: Documentation + +* [#5449](https://github.com/babel/babel/pull/5449) Fixed broken links in README.md [skip-ci]. ([@sethbergman](https://github.com/sethbergman)) +* [#5409](https://github.com/babel/babel/pull/5409) Fix transform-object-rest-spread README. ([@existentialism](https://github.com/existentialism)) +* [#5379](https://github.com/babel/babel/pull/5379) Lint code snippets in READMEs. ([@xtuc](https://github.com/xtuc)) +* [#5334](https://github.com/babel/babel/pull/5334) Shorthand properties examples. ([@bhoule](https://github.com/bhoule)) +* [#5329](https://github.com/babel/babel/pull/5329) Update CONTRIBUTING.md with respect to coverage check [skip ci]. ([@zjmiller](https://github.com/zjmiller)) + +#### :house: Internal +* Other + * [#5338](https://github.com/babel/babel/pull/5338) Improve babel-generator's code coverage. ([@alxpy](https://github.com/alxpy)) + * [#5336](https://github.com/babel/babel/pull/5336) Enable codecov partial coverage. ([@danez](https://github.com/danez)) + * [#5350](https://github.com/babel/babel/pull/5350) Remove redundant NODE_ENV=test in Makefile. ([@aaronang](https://github.com/aaronang)) + * [#5312](https://github.com/babel/babel/pull/5312) [skip ci] Add devEngines to package.json. ([@yavorsky](https://github.com/yavorsky)) +* `babel-cli` + * [#5342](https://github.com/babel/babel/pull/5342) Add test for passing arguments to babel-node (#5163). ([@outsideris](https://github.com/outsideris)) +* `babel-traverse` + * [#5296](https://github.com/babel/babel/pull/5296) Add test for reference paths. ([@jasonLaster](https://github.com/jasonLaster)) + +#### Committers: 14 +- Aaron Ang ([aaronang](https://github.com/aaronang)) +- Alex Kuzmenko ([alxpy](https://github.com/alxpy)) +- Artem Gurzhii ([artemgurzhii](https://github.com/artemgurzhii)) +- Artem Yavorsky ([yavorsky](https://github.com/yavorsky)) +- Brendan Houle ([bhoule](https://github.com/bhoule)) +- Brian Ng ([existentialism](https://github.com/existentialism)) +- Daniel Tschinder ([danez](https://github.com/danez)) +- Izaak Schroeder ([izaakschroeder](https://github.com/izaakschroeder)) +- Jason Laster ([jasonLaster](https://github.com/jasonLaster)) +- JeongHoon Byun (aka Outsider) ([outsideris](https://github.com/outsideris)) +- Robert Jackson ([rwjblue](https://github.com/rwjblue)) +- Seth Bergman ([sethbergman](https://github.com/sethbergman)) +- Sven SAULEAU ([xtuc](https://github.com/xtuc)) +- Zachary Miller ([zjmiller](https://github.com/zjmiller)) + +## 6.23.1 (2017-02-13) + +Regression: Revert https://github.com/babel/babel/pull/5306 since it made a backwards-incompatible change. + ## 6.23.0 (2017-02-13) #### :rocket: New Feature diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 086a0422661b..fa6650e420d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ---- -

+

Setup | Running linting/tests @@ -27,7 +27,7 @@ Contributions are always welcome, no matter how large or small. - If you aren't just making a documentation change, you'll probably want to learn a bit about a few topics. - [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babylon/blob/master/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babylon#output). - - This repository's [`/doc`](/doc) directory for notes on Babel's internals + - This repository's [`/doc`](https://github.com/babel/babel/tree/master/doc) directory for notes on Babel's internals - Check out [the Babel Plugin Handbook](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-plugin-handbook) - core plugins are written the same way as any other plugin! - Check out [AST Explorer](http://astexplorer.net/#/scUfOmVOG5) to learn more about ASTs or make your own plugin in the browser - When you feel ready to finally jump into the babel source code a good start is to look out for issues which are labeled with [help-wanted](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and/or [beginner-friendly](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22beginner-friendly%22). @@ -47,7 +47,7 @@ You can check this with `node -v` and `npm -v`. In addition, make sure that Yarn is installed. Installation instructions can be found here: https://yarnpkg.com/en/docs/install. -#### Setup +### Setup ```sh $ git clone https://github.com/babel/babel @@ -77,7 +77,7 @@ If you wish to build a copy of Babel for distribution, then run: $ make build-dist ``` -#### Running linting/tests +### Running linting/tests You can run lint via: @@ -108,7 +108,7 @@ $ make test-only Most likely you'll want to focus in on a specific issue. -To run tests for a specific package in [packages](/packages), you can use the `TEST_ONLY` environment variable: +To run tests for a specific package in [packages](https://github.com/babel/babel/tree/master/packages), you can use the `TEST_ONLY` environment variable: ```sh $ TEST_ONLY=babel-cli make test @@ -133,27 +133,27 @@ $ BABEL_ENV=cov make build $ ./scripts/test-cov.sh ``` -#### Writing tests +### Writing tests -Most packages in [`/packages`](/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](/packages/babel-core/test/fixtures). +Most packages in [`/packages`](https://github.com/babel/babel/tree/master/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](https://github.com/babel/babel/tree/master/packages/babel-core/test/fixtures). -##### `babel-plugin-x` +#### `babel-plugin-x` All the Babel plugins (and other packages) that have a `/test/fixtures` are written in a similar way. -For example, in [`babel-plugin-transform-exponentiation-operator/test`](/packages/babel-plugin-transform-exponentiation-operator/test): +For example, in [`babel-plugin-transform-exponentiation-operator/test`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test): -- There is an `index.js` file. It imports our [test helper](/packages/babel-helper-plugin-test-runner). (You don't have to worry about this). -- There can be multiple folders under [`/fixtures`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures) - - There is an [`options.json`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests. +- There is an `index.js` file. It imports our [test helper](https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner). (You don't have to worry about this). +- There can be multiple folders under [`/fixtures`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures) + - There is an [`options.json`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests. - For this test, we only need the relevant plugin, so it's just `{ "plugins": ["transform-exponentiation-operator"] }`. - If necessary, you can have an `options.json` with different options in each subfolder. - In each subfolder, you can organize your directory structure by categories of tests. (Example: these folders can be named after the feature you are testing or can reference the issue number they fix) - Generally, there are two kinds of tests for plugins - - The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file. + - The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file. - If you need to expect an error, you can ignore creating the `expected.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created. - - The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file. + - The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file. In an actual/expected test, you simply write out the code you want transformed in `actual.js`. @@ -186,7 +186,7 @@ If you need to check for an error that is thrown you can add to the `options.jso } ``` -##### Bootstrapping expected output +#### Bootstrapping expected output For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js`/`expected.json` automatically by just providing `actual.js` and running the tests as you usually would. @@ -202,7 +202,7 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js - expected.json (will be generated if not created) ``` -#### Debugging code +### Debugging code A common approach to debugging JavaScript code is to walk through the code using the [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/) debugger. For illustration purposes, we are going to assume that we need to get a better understanding of [`Generator.generate()`](https://github.com/babel/babel/blob/b5246994b57f06af871be6a63dcc4c6fd41d94d6/packages/babel-generator/src/index.js#L32), which is responsible for generating code for a given AST. @@ -239,9 +239,9 @@ The debugger starts at the first executed line of code, which is Mocha's first l Click _Resume script execution_ Resume script execution button. to jump to the set breakpoint. Note that the code shown in Chrome DevTools is compiled code and therefore differs. -#### Internals +## Internals - AST spec ([babylon/ast/spec.md](https://github.com/babel/babylon/blob/master/ast/spec.md)) -- Versioning ([doc/design/versioning.md](./doc/design/versioning.md)) -- Monorepo ([doc/design/monorepo.md](./doc/design/monorepo.md)) -- Compiler environment support ([doc/design/compiler-environment-support.md](./doc/design/compiler-environment-support.md)) -- Compiler assumptions ([doc/design/compiler-assumptions.md](./doc/design/compiler-assumptions.md)) +- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.md) +- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/master/doc/design/monorepo.md)) +- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/master/doc/design/compiler-environment-support.md)) +- Compiler assumptions ([doc/design/compiler-assumptions.md](https://github.com/babel/babel/blob/master/doc/design/compiler-assumptions.md)) diff --git a/Makefile b/Makefile index 236aadb839d5..3f68e4cb0415 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ publish: make test # not using lerna independent mode atm, so only update packages that have changed since we use ^ # --only-explicit-updates - ./node_modules/.bin/lerna publish --npm-tag=next --exact + ./node_modules/.bin/lerna publish --npm-tag=next --exact --skip-temp-tag make clean bootstrap: diff --git a/README.md b/README.md index b8fe9840efe5..367565bba1cd 100644 --- a/README.md +++ b/README.md @@ -137,27 +137,9 @@ After Babel 6, the default transforms were removed; if you don't specify any plu The transformer[s] used in Babel are the independent pieces of code that transform specific things. For example: the [`es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) transform specifically changes arrow functions into a regular function. Presets are just simply an array of plugins that make it easier to run a whole a set of transforms without specifying each one manually. -There are a few presets that we maintain officially. - -| Package | Version | Dependencies | -|--------|-------|------------| -| [`babel-preset-es2015`](/packages/babel-preset-es2015) | [![npm](https://img.shields.io/npm/v/babel-preset-es2015.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2015) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2015)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2015) | -| [`babel-preset-es2016`](/packages/babel-preset-es2016) | [![npm](https://img.shields.io/npm/v/babel-preset-es2016.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2016) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2016)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2016) | -| [`babel-preset-es2017`](/packages/babel-preset-es2017) | [![npm](https://img.shields.io/npm/v/babel-preset-es2017.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2017) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2017)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2017) | -| [`babel-preset-latest`](/packages/babel-preset-latest) | [![npm](https://img.shields.io/npm/v/babel-preset-latest.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-latest) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-latest)](https://david-dm.org/babel/babel?path=packages/babel-preset-latest) | -| [`babel-preset-stage-0`](/packages/babel-preset-stage-0) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-0.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-0) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-0)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-0) | -| [`babel-preset-stage-1`](/packages/babel-preset-stage-1) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-1.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-1) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-1)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-1) | -| [`babel-preset-stage-2`](/packages/babel-preset-stage-2) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-2.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-2) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-2)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-2) | -| [`babel-preset-stage-3`](/packages/babel-preset-stage-3) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-3.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-3) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-3)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-3) | -| [`babel-preset-react`](/packages/babel-preset-react) | [![npm](https://img.shields.io/npm/v/babel-preset-react.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-react) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-react)](https://david-dm.org/babel/babel?path=packages/babel-preset-react) | -| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [![npm](https://img.shields.io/npm/v/babel-preset-env.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-env) | [![Dependency Status](https://david-dm.org/babel/babel-preset-env.svg)](https://david-dm.org/babel/babel-preset-env) | - -We maintain: - -- a preset for each yearly release of ECMAScript (Javascript) starting from ES6/ES2015. -- a preset for react (JSX/Flow). -- a preset for each [stage (0-3)](http://babeljs.io/docs/plugins/#stage-x-experimental-presets) of the [TC-39 Process](https://tc39.github.io/process-document/) for ECMAScript proposals. -- a preset that can automatically determine plugins and polyfills you need based on your supported environments. +| Package | Version | Dependencies | Description | +|--------|-------|------------|---| +| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [![npm](https://img.shields.io/npm/v/babel-preset-env.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-env) | [![Dependency Status](https://david-dm.org/babel/babel-preset-env.svg)](https://david-dm.org/babel/babel-preset-env) | automatically determines plugins and polyfills you need based on your supported environments | > You can find community maintained presets on [npm](https://www.npmjs.com/search?q=babel-preset) @@ -191,17 +173,17 @@ Babel | Daniel Tschinder | Logan Smyth | Henry Zhu | ### Members -[![Andrew Levine](https://avatars.githubusercontent.com/u/5233399?s=64)](https://github.com/drewml) | [![Boopathi Rajaa](https://avatars.githubusercontent.com/u/294474?s=64)](https://github.com/boopathi) | [![Brian Ng](https://avatars.githubusercontent.com/u/56288?s=64)](https://github.com/existentialism) | [![Dan Harper](https://avatars.githubusercontent.com/u/510740?s=64)](https://github.com/danharper) | [![Diogo Franco](https://avatars.githubusercontent.com/u/73085?s=64)](https://github.com/kovensky) | -|---|---|---|---|---|---|---|---|---| -| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco | -| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) | -| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) | +[![Andrew Levine](https://avatars.githubusercontent.com/u/5233399?s=64)](https://github.com/drewml) | [![Boopathi Rajaa](https://avatars.githubusercontent.com/u/294474?s=64)](https://github.com/boopathi) | [![Brian Ng](https://avatars.githubusercontent.com/u/56288?s=64)](https://github.com/existentialism) | [![Dan Harper](https://avatars.githubusercontent.com/u/510740?s=64)](https://github.com/danharper) | [![diogo franco](https://avatars.githubusercontent.com/u/73085?s=64)](https://github.com/kovensky) | [![Aaron Ang](https://avatars1.githubusercontent.com/u/7579804?s=64)](https://github.com/aaronang) | [![Artem Yavorsky](https://avatars2.githubusercontent.com/u/1521229?s=64)](https://github.com/yavorsky) | +|---|---|---|---|---|---|---|---|---|---|---| +| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco | Aaron Ang | Artem Yavorsky | +| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) | [@aaronang](https://github.com/aaronang) | [@yavorsky](https://github.com/yavorsky) | +| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) | [@_aaronang](https://twitter.com/_aaronang) | [@yavorsky_](https://twitter.com/yavorsky_) | -[![Juriy Zaytsev](https://avatars.githubusercontent.com/u/383?s=64)](https://github.com/kangax) | [![Kai Cataldo](https://avatars.githubusercontent.com/u/7041728?s=64)](https://github.com/kaicataldo) | [![Moti Zilberman](https://avatars.githubusercontent.com/u/2246565?s=64)](https://github.com/motiz88) | [![Sven Sauleau](https://avatars3.githubusercontent.com/u/1493671?s=64)](https://github.com/xtuc) | -|---|---|---|---|---|---|---|---|---| -| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau | -| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | -| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) | +[![Juriy Zaytsev](https://avatars.githubusercontent.com/u/383?s=64)](https://github.com/kangax) | [![Kai Cataldo](https://avatars.githubusercontent.com/u/7041728?s=64)](https://github.com/kaicataldo) | [![Moti Zilberman](https://avatars.githubusercontent.com/u/2246565?s=64)](https://github.com/motiz88) | [![Sven Sauleau](https://avatars3.githubusercontent.com/u/1493671?s=64)](https://github.com/xtuc) | [![Samuel Reed](https://avatars3.githubusercontent.com/u/1197375?s=64)](https://github.com/STRML) | [![Sergey Rubanov](https://avatars1.githubusercontent.com/u/1507086?s=64)](https://github.com/chicoxyzzy) | +|---|---|---|---|---|---|---|---|---|---|---| +| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau | Samuel Reed | Sergey Rubanov | +| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | [@STRML](https://github.com/STRML) | [@chicoxyzzy](https://github.com/chicoxyzzy) | +| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) | [@STRML_](https://twitter.com/STRML_) | [@chicoxyzzy](https://twitter.com/chicoxyzzy) | ### Non-Human Members @@ -222,3 +204,4 @@ Amjad Masad | James Kyle | Jesse McCarthy | Sebastian McKenzie | ## License [MIT](https://github.com/babel/babel/blob/master/LICENSE) + diff --git a/lerna.json b/lerna.json index de8942ffe298..91036a0b369e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "lerna": "2.0.0-beta.38", - "version": "independent", + "version": "7.0.0-alpha.2", "changelog": { "repo": "babel/babel", "labels": { diff --git a/packages/babel-cli/package.json b/packages/babel-cli/package.json index 87c8d483ac3b..81ca73d32b7a 100644 --- a/packages/babel-cli/package.json +++ b/packages/babel-cli/package.json @@ -1,6 +1,6 @@ { "name": "babel-cli", - "version": "7.0.0-alpha.1", + "version": "7.0.0-alpha.2", "description": "Babel command line.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -16,8 +16,8 @@ "compiler" ], "dependencies": { - "babel-core": "7.0.0-alpha.1", - "babel-register": "7.0.0-alpha.1", + "babel-core": "7.0.0-alpha.2", + "babel-register": "7.0.0-alpha.2", "babel-polyfill": "7.0.0-alpha.1", "commander": "^2.8.1", "convert-source-map": "^1.1.0", diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index 9e52e8894c3c..0c99b5938595 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -1,6 +1,6 @@ { "name": "babel-core", - "version": "7.0.0-alpha.1", + "version": "7.0.0-alpha.2", "description": "Babel compiler core.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -31,7 +31,7 @@ "babel-helpers": "7.0.0-alpha.1", "babel-messages": "7.0.0-alpha.1", "babel-template": "7.0.0-alpha.1", - "babel-register": "7.0.0-alpha.1", + "babel-register": "7.0.0-alpha.2", "babel-traverse": "7.0.0-alpha.1", "babel-types": "7.0.0-alpha.1", "babylon": "7.0.0-beta.4", @@ -41,12 +41,13 @@ "lodash": "^4.2.0", "minimatch": "^3.0.2", "private": "^0.1.6", + "resolve": "^1.3.2", "slash": "^1.0.0", "source-map": "^0.5.0" }, "devDependencies": { "babel-helper-fixtures": "7.0.0-alpha.1", - "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.1", + "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.2", "babel-polyfill": "7.0.0-alpha.1" } } diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/helpers/resolve.js index e8493ac8f599..f0c6b27f81ca 100644 --- a/packages/babel-core/src/helpers/resolve.js +++ b/packages/babel-core/src/helpers/resolve.js @@ -1,33 +1,8 @@ -import Module from "module"; -import path from "path"; - -const relativeModules = {}; +import resolve from "resolve"; export default function (loc: string, relative: string = process.cwd()): ?string { - // we're in the browser, probably - if (typeof Module === "object") return null; - - let relativeMod = relativeModules[relative]; - - if (!relativeMod) { - relativeMod = new Module; - - // We need to define an id and filename on our "fake" relative` module so that - // Node knows what "." means in the case of us trying to resolve a plugin - // such as "./myPlugins/somePlugin.js". If we don't specify id and filename here, - // Node presumes "." is process.cwd(), not our relative path. - // Since this fake module is never "loaded", we don't have to worry about mutating - // any global Node module cache state here. - const filename = path.join(relative, ".babelrc"); - relativeMod.id = filename; - relativeMod.filename = filename; - - relativeMod.paths = Module._nodeModulePaths(relative); - relativeModules[relative] = relativeMod; - } - try { - return Module._resolveFilename(loc, relativeMod); + return resolve.sync(loc, { basedir: relative }); } catch (err) { return null; } diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index dad9ec5b138d..f11e75030324 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -45,7 +45,17 @@ export default class File extends Store { super(); this.log = new Logger(this, opts.filename || "unknown"); - this.opts = this.initOptions(opts); + + opts = this.initOptions(opts); + + let passes = []; + if (opts.plugins) passes.push(opts.plugins); + + // With "passPerPreset" enabled there may still be presets in the options. + if (opts.presets) passes = passes.concat(opts.presets.map((preset) => preset.plugins).filter(Boolean)); + + this.pluginPasses = passes; + this.opts = opts; this.parserOpts = { sourceType: this.opts.sourceType, @@ -53,22 +63,12 @@ export default class File extends Store { plugins: [], }; - this.pluginVisitors = []; - this.pluginPasses = []; - - // Plugins for top-level options. - this.buildPluginsForOptions(this.opts); - - // If we are in the "pass per preset" mode, build - // also plugins for each preset. - if (this.opts.passPerPreset) { - // All the "per preset" options are inherited from the main options. - this.perPresetOpts = []; - this.opts.presets.forEach((presetOpts) => { - const perPresetOpts = Object.assign(Object.create(this.opts), presetOpts); - this.perPresetOpts.push(perPresetOpts); - this.buildPluginsForOptions(perPresetOpts); - }); + for (const pluginPairs of passes) { + for (const [ plugin ] of pluginPairs) { + if (plugin.manipulateOptions) { + plugin.manipulateOptions(opts, this.parserOpts, this); + } + } } this.metadata = { @@ -100,8 +100,7 @@ export default class File extends Store { static helpers: Array; - pluginVisitors: Array; - pluginPasses: Array; + pluginPasses: Array>; parserOpts: BabelParserOptions; log: Logger; opts: Object; @@ -132,7 +131,7 @@ export default class File extends Store { } initOptions(opts) { - opts = new OptionManager(this.log).init(opts); + opts = this.log.wrap(() => new OptionManager().init(opts)); if (opts.inputSourceMap) { opts.sourceMaps = true; @@ -170,31 +169,6 @@ export default class File extends Store { return opts; } - buildPluginsForOptions(opts) { - if (!Array.isArray(opts.plugins)) { - return; - } - - const plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS); - const currentPluginVisitors = []; - const currentPluginPasses = []; - - // init plugins! - for (const ref of plugins) { - const [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug - - currentPluginVisitors.push(plugin.visitor); - currentPluginPasses.push(new PluginPass(this, plugin, pluginOpts)); - - if (plugin.manipulateOptions) { - plugin.manipulateOptions(opts, this.parserOpts, this); - } - } - - this.pluginVisitors.push(currentPluginVisitors); - this.pluginPasses.push(currentPluginPasses); - } - getModuleName(): ?string { const opts = this.opts; if (!opts.moduleIds) { @@ -460,20 +434,25 @@ export default class File extends Store { } transform(): BabelFileResult { - // In the "pass per preset" mode, we have grouped passes. - // Otherwise, there is only one plain pluginPasses array. - for (let i = 0; i < this.pluginPasses.length; i++) { - const pluginPasses = this.pluginPasses[i]; - this.call("pre", pluginPasses); + for (const pluginPairs of this.pluginPasses) { + const passes = []; + const visitors = []; + + for (const [ plugin, pluginOpts ] of pluginPairs.concat(INTERNAL_PLUGINS)) { + const pass = new PluginPass(this, plugin, pluginOpts); + passes.push(pass); + visitors.push(plugin.visitor); + } + + this.call("pre", passes); this.log.debug("Start transform traverse"); // merge all plugin visitors into a single visitor - const visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, - this.opts.wrapPluginVisitorMethod); + const visitor = traverse.visitors.merge(visitors, passes, this.opts.wrapPluginVisitorMethod); traverse(this.ast, visitor, this.scope); this.log.debug("End transform traverse"); - this.call("post", pluginPasses); + this.call("post", passes); } return this.generate(); diff --git a/packages/babel-core/src/transformation/file/logger.js b/packages/babel-core/src/transformation/file/logger.js index aa4a57d71809..6a9503396a6a 100644 --- a/packages/babel-core/src/transformation/file/logger.js +++ b/packages/babel-core/src/transformation/file/logger.js @@ -1,5 +1,5 @@ import type File from "./index"; -import buildDebug from "debug/node"; +import buildDebug from "debug"; const verboseDebug = buildDebug("babel:verbose"); const generalDebug = buildDebug("babel"); @@ -21,6 +21,15 @@ export default class Logger { return parts; } + wrap(callback: () => T): T { + try { + return callback(); + } catch (e) { + e.message = this._buildMessage(e.message); + throw e; + } + } + warn(msg: string) { console.warn(this._buildMessage(msg)); } diff --git a/packages/babel-core/src/transformation/file/options/build-config-chain.js b/packages/babel-core/src/transformation/file/options/build-config-chain.js index 5542072f6909..a5af4e82ba6f 100644 --- a/packages/babel-core/src/transformation/file/options/build-config-chain.js +++ b/packages/babel-core/src/transformation/file/options/build-config-chain.js @@ -1,5 +1,3 @@ - -import type Logger from "../logger"; import resolve from "../../../helpers/resolve"; import json5 from "json5"; import path from "path"; @@ -8,9 +6,10 @@ import fs from "fs"; const existsCache = {}; const jsonCache = {}; -const BABELIGNORE_FILENAME = ".babelignore"; const BABELRC_FILENAME = ".babelrc"; +const BABELRC_JS_FILENAME = ".babelrc.js"; const PACKAGE_FILENAME = "package.json"; +const BABELIGNORE_FILENAME = ".babelignore"; function exists(filename) { const cached = existsCache[filename]; @@ -21,9 +20,9 @@ function exists(filename) { } } -export default function buildConfigChain(opts: Object = {}, log?: Logger) { +export default function buildConfigChain(opts: Object = {}) { const filename = opts.filename; - const builder = new ConfigChainBuilder(log); + const builder = new ConfigChainBuilder(); // resolve all .babelrc files if (opts.babelrc !== false) { @@ -40,13 +39,17 @@ export default function buildConfigChain(opts: Object = {}, log?: Logger) { } class ConfigChainBuilder { - constructor(log?: Logger) { + constructor() { this.resolvedConfigs = []; this.configs = []; - this.log = log; } - findConfigs(loc) { + errorMultipleConfigs(loc1: string, loc2: string) { + throw new Error(`Multiple configuration files found. Please remove one:\n- ${ + loc1}\n- ${loc2}`); + } + + findConfigs(loc: string) { if (!loc) return; if (!path.isAbsolute(loc)) { @@ -59,15 +62,26 @@ class ConfigChainBuilder { while (loc !== (loc = path.dirname(loc))) { if (!foundConfig) { const configLoc = path.join(loc, BABELRC_FILENAME); - if (exists(configLoc)) { - this.addConfig(configLoc); - foundConfig = true; - } - + const configJSLoc = path.join(loc, BABELRC_JS_FILENAME); const pkgLoc = path.join(loc, PACKAGE_FILENAME); - if (!foundConfig && exists(pkgLoc)) { - foundConfig = this.addConfig(pkgLoc, "babel", JSON); - } + const configLocs = [configLoc, configJSLoc, pkgLoc]; + const foundConfigs = configLocs.reduce((arr, config) => { + if (exists(config)) { + const configAdded = config === pkgLoc + ? this.addConfig(config, "babel", JSON) + : this.addConfig(config); + + if (configAdded && arr.length) { + this.errorMultipleConfigs(arr.pop(), config); + } + + arr.push(config); + } + + return arr; + }, []); + + foundConfig = !!foundConfigs.length; } if (!foundIgnore) { @@ -82,7 +96,7 @@ class ConfigChainBuilder { } } - addIgnoreConfig(loc) { + addIgnoreConfig(loc: string) { const file = fs.readFileSync(loc, "utf8"); let lines = file.split("\n"); @@ -106,15 +120,35 @@ class ConfigChainBuilder { this.resolvedConfigs.push(loc); - const content = fs.readFileSync(loc, "utf8"); let options; + if (path.extname(loc) === ".js") { + try { + const configModule = require(loc); + options = configModule && configModule.__esModule ? configModule.default : configModule; + } catch (err) { + err.message = `${loc}: Error while loading config - ${err.message}`; + throw err; + } + + if (!options || typeof options !== "object") { + throw new Error("Configuration should be an exported JavaScript object."); + } + } else { + const content = fs.readFileSync(loc, "utf8"); + try { + options = jsonCache[content] = jsonCache[content] || json.parse(content); + } catch (err) { + err.message = `${loc}: Error while parsing JSON - ${err.message}`; + throw err; + } + } + + if (key) { + if (!options[key]) { + return false; + } - try { - options = jsonCache[content] = jsonCache[content] || json.parse(content); - if (key) options = options[key]; - } catch (err) { - err.message = `${loc}: Error while parsing JSON - ${err.message}`; - throw err; + options = options[key]; } this.mergeConfig({ @@ -147,7 +181,7 @@ class ConfigChainBuilder { if (extendsLoc) { this.addConfig(extendsLoc); } else { - if (this.log) this.log.error(`Couldn't resolve extends clause of ${options.extends} in ${alias}`); + throw new Error(`Couldn't resolve extends clause of ${options.extends} in ${alias}`); } delete options.extends; } diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index 6c63ba32fa3a..762a6437844b 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -1,5 +1,4 @@ import * as context from "../../../index"; -import type Logger from "../logger"; import Plugin from "../../plugin"; import * as messages from "babel-messages"; import { normaliseOptions } from "./index"; @@ -35,15 +34,13 @@ type MergeOptions = { }; export default class OptionManager { - constructor(log?: Logger) { + constructor() { this.resolvedConfigs = []; this.options = OptionManager.createBareOptions(); - this.log = log; } resolvedConfigs: Array; options: Object; - log: ?Logger; static memoisedPlugins: Array<{ container: Function; @@ -158,7 +155,7 @@ export default class OptionManager { // if (typeof rawOpts !== "object" || Array.isArray(rawOpts)) { - this.log.error(`Invalid options type for ${alias}`, TypeError); + throw new TypeError(`Invalid options type for ${alias}`); } // @@ -176,15 +173,14 @@ export default class OptionManager { const option = config[key]; // check for an unknown option - if (!option && this.log) { + if (!option) { if (removed[key]) { - this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, - ReferenceError); + throw new ReferenceError(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`); } else { // eslint-disable-next-line max-len const unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; - this.log.error(unknownOptErr, ReferenceError); + throw new ReferenceError(unknownOptErr); } } } @@ -333,7 +329,7 @@ export default class OptionManager { } init(opts: Object = {}): Object { - for (const config of buildConfigChain(opts, this.log)) { + for (const config of buildConfigChain(opts)) { this.mergeOptions(config); } diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index bf03ff2f463f..097b515b1ac3 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -141,7 +141,7 @@ describe("api", function () { plugins: [__dirname + "/../../babel-plugin-syntax-jsx", false], }); }, - /TypeError: Falsy value found in plugins/ + /TypeError: \[BABEL\] unknown: Falsy value found in plugins/ ); }); diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 5032973e7df6..f317eca7d847 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -294,4 +294,253 @@ describe("buildConfigChain", function () { assert.deepEqual(chain, expected); }); + + it("js-config", function () { + const chain = buildConfigChain({ + filename: fixture("js-config", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config", ".babelrc.js"), + loc: fixture("js-config", ".babelrc.js"), + dirname: fixture("js-config"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("js-config-default - should read transpiled export default", function () { + const chain = buildConfigChain({ + filename: fixture("js-config-default", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config-default", ".babelrc.js"), + loc: fixture("js-config-default", ".babelrc.js"), + dirname: fixture("js-config-default"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config-default", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config-default"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + it("js-config-extended", function () { + const chain = buildConfigChain({ + filename: fixture("js-config-extended", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "extended", + ], + }, + alias: fixture("extended.babelrc.json"), + loc: fixture("extended.babelrc.json"), + dirname: fixture(), + }, + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config-extended", ".babelrc.js"), + loc: fixture("js-config-extended", ".babelrc.js"), + dirname: fixture("js-config-extended"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config-extended", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config-extended"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("json-pkg-config-no-babel - should not throw if" + + " package.json doesn't contain a `babel` field", function () { + const chain = buildConfigChain({ + filename: fixture("json-pkg-config-no-babel", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "json", + ], + }, + alias: fixture("json-pkg-config-no-babel", ".babelrc"), + loc: fixture("json-pkg-config-no-babel", ".babelrc"), + dirname: fixture("json-pkg-config-no-babel"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("json-pkg-config-no-babel", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("json-pkg-config-no-babel"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("js-json-config - should throw an error if both a .babelrc" + + " and a .babelrc.js are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-json-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*\.babelrc\.js/ + ); + }); + + it("js-pkg-config - should throw an error if both a .babelrc.js" + + " and a package.json with a babel field are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-pkg-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc\.js(.|\n)*package\.json/ + ); + }); + + it("json-pkg-config - should throw an error if both a .babelrc" + + " and a package.json with a babel field are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("json-pkg-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*package\.json/ + ); + }); + + it("js-config-error", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error", "src.js"), + }); + }, + /Error while loading config/ + ); + }); + + it("js-config-error2", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error2", "src.js"), + }); + }, + /Configuration should be an exported JavaScript object/ + ); + }); + + it("js-config-error3", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error3", "src.js"), + }); + }, + /Configuration should be an exported JavaScript object/ + ); + }); + + it("json-config-error", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("json-config-error", "src.js"), + }); + }, + /Error while parsing JSON/ + ); + }); }); diff --git a/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js new file mode 100644 index 000000000000..de5f1c0244a0 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js @@ -0,0 +1,10 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var plugins = ["foo", "bar"]; + +exports.default = { + plugins: plugins +}; diff --git a/packages/babel-core/test/fixtures/config/js-config-default/src.js b/packages/babel-core/test/fixtures/config/js-config-default/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-default/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js new file mode 100644 index 000000000000..d14a2b71a829 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js @@ -0,0 +1,2 @@ +throw new Error("Something bad happened!"); +module.exports = {} diff --git a/packages/babel-core/test/fixtures/config/js-config-error/src.js b/packages/babel-core/test/fixtures/config/js-config-error/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js new file mode 100644 index 000000000000..9dc5fc1e4a43 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js @@ -0,0 +1 @@ +module.exports = ''; diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/src.js b/packages/babel-core/test/fixtures/config/js-config-error2/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error2/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js new file mode 100644 index 000000000000..b894a23a24d5 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js @@ -0,0 +1 @@ +module.exports = null; diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/src.js b/packages/babel-core/test/fixtures/config/js-config-error3/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error3/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js new file mode 100644 index 000000000000..05741c6ef8cd --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js @@ -0,0 +1,6 @@ +var plugins = ["foo", "bar"]; + +module.exports = { + extends: "../extended.babelrc.json", + plugins: plugins +} diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/src.js b/packages/babel-core/test/fixtures/config/js-config-extended/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-extended/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config/.babelrc.js new file mode 100644 index 000000000000..e6fa0742df7b --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config/.babelrc.js @@ -0,0 +1,5 @@ +var plugins = ["foo", "bar"]; + +module.exports = { + plugins: plugins +} diff --git a/packages/babel-core/test/fixtures/config/js-config/src.js b/packages/babel-core/test/fixtures/config/js-config/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc new file mode 100644 index 000000000000..c80e833d707a --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js new file mode 100644 index 000000000000..71bb3e5762ff --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + "js" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/src.js b/packages/babel-core/test/fixtures/config/js-json-config/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js new file mode 100644 index 000000000000..71bb3e5762ff --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + "js" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/package.json b/packages/babel-core/test/fixtures/config/js-pkg-config/package.json new file mode 100644 index 000000000000..e25be3ecd260 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/package.json @@ -0,0 +1,3 @@ +{ + "babel": {} +} diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/src.js b/packages/babel-core/test/fixtures/config/js-pkg-config/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-config-error/.babelrc b/packages/babel-core/test/fixtures/config/json-config-error/.babelrc new file mode 100644 index 000000000000..a07fde17a39d --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-config-error/.babelrc @@ -0,0 +1,3 @@ +{ + "bad: "json" +} diff --git a/packages/babel-core/test/fixtures/config/json-config-error/src.js b/packages/babel-core/test/fixtures/config/json-config-error/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-config-error/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc new file mode 100644 index 000000000000..c80e833d707a --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc new file mode 100644 index 000000000000..c80e833d707a --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/package.json b/packages/babel-core/test/fixtures/config/json-pkg-config/package.json new file mode 100644 index 000000000000..e25be3ecd260 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/package.json @@ -0,0 +1,3 @@ +{ + "babel": {} +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config/src.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index a38436d19712..126ed83c278a 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -1,6 +1,5 @@ import assert from "assert"; import OptionManager from "../lib/transformation/file/options/option-manager"; -import Logger from "../lib/transformation/file/logger"; import path from "path"; describe("option-manager", () => { @@ -17,7 +16,7 @@ describe("option-manager", () => { it("throws for removed babel 5 options", () => { return assert.throws( () => { - const opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ "randomOption": true, }); @@ -29,7 +28,7 @@ describe("option-manager", () => { it("throws for removed babel 5 options", () => { return assert.throws( () => { - const opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ "auxiliaryComment": true, "blacklist": true, @@ -43,7 +42,7 @@ describe("option-manager", () => { it("throws for resolved but erroring preset", () => { return assert.throws( () => { - const opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ "presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")], }); @@ -56,7 +55,7 @@ describe("option-manager", () => { describe("presets", function () { function presetTest(name) { it(name, function () { - const opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); const options = opt.init({ "presets": [path.join(__dirname, "fixtures/option-manager/presets", name)], }); @@ -68,7 +67,7 @@ describe("option-manager", () => { function presetThrowsTest(name, msg) { it(name, function () { - const opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); assert.throws(() => opt.init({ "presets": [path.join(__dirname, "fixtures/option-manager/presets", name)], }), msg); diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index 0175a6312dd8..658a84ec06d2 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -51,6 +51,8 @@ export function Binary(node: Object, parent: Object): boolean { ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) || t.isUnaryLike(parent) || (t.isMemberExpression(parent) && parent.object === node) + (t.isMemberExpression(parent) && parent.object === node) || + t.isAwaitExpression(parent) ) { return true; } diff --git a/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js index d4bdc6b74a8d..828926300767 100644 --- a/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js +++ b/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js @@ -5,6 +5,7 @@ async function asdf() { true ? (await 1) : (await 2); await (1 ? 2 : 3); await (await 1); + await (a || b); } async function a(b) { diff --git a/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js index dc2cb361e0c6..271a15791e19 100644 --- a/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js +++ b/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js @@ -5,6 +5,7 @@ async function asdf() { true ? await 1 : await 2; await (1 ? 2 : 3); await await 1; + await (a || b); } async function a(b) { diff --git a/packages/babel-helper-plugin-test-runner/package.json b/packages/babel-helper-plugin-test-runner/package.json index 0729b721506e..ad893637a11b 100644 --- a/packages/babel-helper-plugin-test-runner/package.json +++ b/packages/babel-helper-plugin-test-runner/package.json @@ -1,11 +1,11 @@ { "name": "babel-helper-plugin-test-runner", - "version": "7.0.0-alpha.1", + "version": "7.0.0-alpha.2", "description": "Helper function to support test runner", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.1" + "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.2" } } diff --git a/packages/babel-helper-transform-fixture-test-runner/package.json b/packages/babel-helper-transform-fixture-test-runner/package.json index 83c6a054e686..01f5ab0d4c2c 100644 --- a/packages/babel-helper-transform-fixture-test-runner/package.json +++ b/packages/babel-helper-transform-fixture-test-runner/package.json @@ -1,6 +1,6 @@ { "name": "babel-helper-transform-fixture-test-runner", - "version": "7.0.0-alpha.1", + "version": "7.0.0-alpha.2", "description": "Transform test runner for babel-helper-fixtures module", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,12 +8,13 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner", "main": "lib/index.js", "dependencies": { - "babel-core": "7.0.0-alpha.1", + "babel-code-frame": "7.0.0-alpha.1", + "babel-core": "7.0.0-alpha.2", "babel-polyfill": "7.0.0-alpha.1", "babel-helper-fixtures": "7.0.0-alpha.1", - "source-map": "^0.5.0", - "babel-code-frame": "7.0.0-alpha.1", "chai": "^3.0.0", - "lodash": "^4.2.0" + "lodash": "^4.2.0", + "resolve": "^1.3.2", + "source-map": "^0.5.0" } } diff --git a/packages/babel-helper-transform-fixture-test-runner/src/index.js b/packages/babel-helper-transform-fixture-test-runner/src/index.js index 2b6d1272c452..6afb777bd3c6 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.js @@ -8,12 +8,12 @@ import includes from "lodash/includes"; import * as helpers from "./helpers"; import extend from "lodash/extend"; import merge from "lodash/merge"; +import resolve from "resolve"; import assert from "assert"; import chai from "chai"; import fs from "fs"; import path from "path"; import vm from "vm"; -import Module from "module"; const moduleCache = {}; const testContext = vm.createContext({ @@ -35,13 +35,7 @@ runCodeInTestContext(buildExternalHelpers()); * This allows us to run our unittests */ function runModuleInTestContext(id: string, relativeFilename: string) { - // This code is a gross hack using internal APIs, but we also have the same logic in babel-core - // to resolve presets and plugins, so if this breaks, we'll have even worse issues to deal with. - const relativeMod = new Module(); - relativeMod.id = relativeFilename; - relativeMod.filename = relativeFilename; - relativeMod.paths = Module._nodeModulePaths(path.dirname(relativeFilename)); - const filename = Module._resolveFilename(id, relativeMod); + const filename = resolve.sync(id, { basedir: path.dirname(relativeFilename) }); // Expose Node-internal modules if the tests want them. Note, this will not execute inside // the context's global scope. diff --git a/packages/babel-plugin-check-es2015-constants/package.json b/packages/babel-plugin-check-es2015-constants/package.json index e78c62a45e93..c54d9bb85627 100644 --- a/packages/babel-plugin-check-es2015-constants/package.json +++ b/packages/babel-plugin-check-es2015-constants/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-external-helpers/package.json b/packages/babel-plugin-external-helpers/package.json index 0eaf0bc4371d..2820e253c355 100644 --- a/packages/babel-plugin-external-helpers/package.json +++ b/packages/babel-plugin-external-helpers/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-syntax-trailing-function-commas/package.json b/packages/babel-plugin-syntax-trailing-function-commas/package.json index ded8a1bc5536..fab5f329cd5c 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/package.json +++ b/packages/babel-plugin-syntax-trailing-function-commas/package.json @@ -10,6 +10,6 @@ ], "dependencies": {}, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-functions/package.json b/packages/babel-plugin-transform-async-functions/package.json index 48498c669abf..a6d512ecfd3e 100644 --- a/packages/babel-plugin-transform-async-functions/package.json +++ b/packages/babel-plugin-transform-async-functions/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-async-functions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-generator-functions/package.json b/packages/babel-plugin-transform-async-generator-functions/package.json index a69615a6122c..84e7abcb7d96 100644 --- a/packages/babel-plugin-transform-async-generator-functions/package.json +++ b/packages/babel-plugin-transform-async-generator-functions/package.json @@ -13,6 +13,6 @@ "babel-plugin-syntax-async-generators": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-to-generator/package.json b/packages/babel-plugin-transform-async-to-generator/package.json index 13e0a80166b4..ab6c8a89dd3f 100644 --- a/packages/babel-plugin-transform-async-to-generator/package.json +++ b/packages/babel-plugin-transform-async-to-generator/package.json @@ -13,6 +13,6 @@ "babel-plugin-syntax-async-functions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-to-module-method/package.json b/packages/babel-plugin-transform-async-to-module-method/package.json index 015cc4ba66a7..ed52d249468e 100644 --- a/packages/babel-plugin-transform-async-to-module-method/package.json +++ b/packages/babel-plugin-transform-async-to-module-method/package.json @@ -14,6 +14,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-class-properties/package.json b/packages/babel-plugin-transform-class-properties/package.json index 6ad1e0bf80a9..c8462d610299 100644 --- a/packages/babel-plugin-transform-class-properties/package.json +++ b/packages/babel-plugin-transform-class-properties/package.json @@ -14,6 +14,6 @@ "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-decorators/package.json b/packages/babel-plugin-transform-decorators/package.json index 64c8d416e9d5..0d41ef971e3b 100644 --- a/packages/babel-plugin-transform-decorators/package.json +++ b/packages/babel-plugin-transform-decorators/package.json @@ -17,6 +17,6 @@ "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-do-expressions/package.json b/packages/babel-plugin-transform-do-expressions/package.json index c959080f088f..eea756892cf3 100644 --- a/packages/babel-plugin-transform-do-expressions/package.json +++ b/packages/babel-plugin-transform-do-expressions/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-do-expressions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/package.json b/packages/babel-plugin-transform-es2015-arrow-functions/package.json index accf0a2d4947..769a11ac31cb 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/package.json +++ b/packages/babel-plugin-transform-es2015-arrow-functions/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json index 9cdd5fbf5cf0..9dfc7356b8fb 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/package.json b/packages/babel-plugin-transform-es2015-block-scoping/package.json index 2bf52f76a12a..839997ebe072 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoping/package.json @@ -15,6 +15,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-classes/package.json b/packages/babel-plugin-transform-es2015-classes/package.json index f10b00a9d522..37e45942a708 100644 --- a/packages/babel-plugin-transform-es2015-classes/package.json +++ b/packages/babel-plugin-transform-es2015-classes/package.json @@ -19,6 +19,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-computed-properties/package.json b/packages/babel-plugin-transform-es2015-computed-properties/package.json index aa17e0805489..31b3130408db 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/package.json +++ b/packages/babel-plugin-transform-es2015-computed-properties/package.json @@ -12,6 +12,6 @@ "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-destructuring/package.json b/packages/babel-plugin-transform-es2015-destructuring/package.json index 50e7717c9694..e3eef565a171 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/package.json +++ b/packages/babel-plugin-transform-es2015-destructuring/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-duplicate-keys/package.json b/packages/babel-plugin-transform-es2015-duplicate-keys/package.json index a10312f85390..fd327fb34dfc 100644 --- a/packages/babel-plugin-transform-es2015-duplicate-keys/package.json +++ b/packages/babel-plugin-transform-es2015-duplicate-keys/package.json @@ -12,6 +12,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-for-of/package.json b/packages/babel-plugin-transform-es2015-for-of/package.json index 99753f4eaa66..24c437586b32 100644 --- a/packages/babel-plugin-transform-es2015-for-of/package.json +++ b/packages/babel-plugin-transform-es2015-for-of/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-function-name/package.json b/packages/babel-plugin-transform-es2015-function-name/package.json index d992f0123b15..d2458bf881fc 100644 --- a/packages/babel-plugin-transform-es2015-function-name/package.json +++ b/packages/babel-plugin-transform-es2015-function-name/package.json @@ -13,6 +13,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-instanceof/package.json b/packages/babel-plugin-transform-es2015-instanceof/package.json index 105b87ee1836..d997b4c46734 100644 --- a/packages/babel-plugin-transform-es2015-instanceof/package.json +++ b/packages/babel-plugin-transform-es2015-instanceof/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-literals/package.json b/packages/babel-plugin-transform-es2015-literals/package.json index d9bc93877434..bc81940b1da0 100644 --- a/packages/babel-plugin-transform-es2015-literals/package.json +++ b/packages/babel-plugin-transform-es2015-literals/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/README.md b/packages/babel-plugin-transform-es2015-modules-amd/README.md index 04455655accf..bf54c82a7579 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/README.md +++ b/packages/babel-plugin-transform-es2015-modules-amd/README.md @@ -55,3 +55,7 @@ require("babel-core").transform("code", { plugins: ["transform-es2015-modules-amd"] }); ``` + +### Options + +See options for `babel-plugin-transform-es2015-commonjs`. diff --git a/packages/babel-plugin-transform-es2015-modules-amd/package.json b/packages/babel-plugin-transform-es2015-modules-amd/package.json index 4d26e73f91ac..36969f3150f2 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/package.json +++ b/packages/babel-plugin-transform-es2015-modules-amd/package.json @@ -13,6 +13,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js new file mode 100644 index 000000000000..7d2c9b022e26 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js @@ -0,0 +1 @@ +export { default } from 'foo'; diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js new file mode 100644 index 000000000000..cd5f804ab644 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js @@ -0,0 +1,13 @@ +define(['exports', 'foo'], function (exports, _foo) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, 'default', { + enumerable: true, + get: function () { + return _foo.default; + } + }); +}); diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json new file mode 100644 index 000000000000..096d2b9404ce --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-amd", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js new file mode 100644 index 000000000000..44567cb185be --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +foo; diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js new file mode 100644 index 000000000000..acdfb3b580f5 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js @@ -0,0 +1,5 @@ +define(["foo"], function (_foo) { + "use strict"; + + _foo.default; +}); diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json new file mode 100644 index 000000000000..096d2b9404ce --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-amd", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md index 3a802ab57173..33088cc8682c 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md @@ -82,10 +82,53 @@ Object.defineProperty(exports, "__esModule", { }); ``` -In environments that don't support this you can enable loose mode on `es6.modules` +In environments that don't support this you can enable loose mode on `babel-plugin-transform-es20150-modules-commonjs` and instead of using `Object.defineProperty` an assignment will be used instead. ```javascript var foo = exports.foo = 5; exports.__esModule = true; ``` + +### `strict` + +`boolean`, defaults to `false` + +By default, when using exports with babel a non-enumerable `__esModule` property +is exported. In some cases this property is used to determine if the import _is_ the +default export or if it _contains_ the default export. + +```javascript +var foo = exports.foo = 5; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +``` + +In order to prevent the `__esModule` property from being exported, you can set +the `strict` option to `true`. + +### `noInterop` + +`boolean`, defaults to `false` + +By default, when using exports with babel a non-enumerable `__esModule` property +is exported. This property is then used to determine if the import _is_ the default +export or if it _contains_ the default export. + +```javascript +"use strict"; + +var _foo = require("foo"); + +var _foo2 = _interopRequireDefault(_foo); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +``` + +In cases where the auto-unwrapping of `default` is not needed, you can set the +`noInterop` option to `true` to avoid the usage of the `interopRequireDefault` +helper (shown in inline form above). diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/package.json b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json index 0fc442373c70..fe000208af37 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/package.json +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json @@ -14,6 +14,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index 6c6dc9848e54..a9178da61ee4 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -151,6 +151,7 @@ export default function () { this.ranCommonJS = true; const strict = !!this.opts.strict; + const noInterop = !!this.opts.noInterop; const { scope } = path; @@ -327,7 +328,7 @@ export default function () { } else if (specifier.isExportDefaultSpecifier()) { // todo } else if (specifier.isExportSpecifier()) { - if (specifier.node.local.name === "default") { + if (!noInterop && specifier.node.local.name === "default") { topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression( t.callExpression(this.addHelper("interopRequireDefault"), [ref]), @@ -371,7 +372,7 @@ export default function () { for (let i = 0; i < specifiers.length; i++) { const specifier = specifiers[i]; if (t.isImportNamespaceSpecifier(specifier)) { - if (strict) { + if (strict || noInterop) { remaps[specifier.local.name] = uid; } else { const varDecl = t.variableDeclaration("var", [ @@ -402,7 +403,7 @@ export default function () { if (specifier.imported.name === "default") { if (wildcard) { target = wildcard; - } else { + } else if (!noInterop) { target = wildcard = path.scope.generateUidIdentifier(uid.name); const varDecl = t.variableDeclaration("var", [ t.variableDeclarator( diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js new file mode 100644 index 000000000000..7d2c9b022e26 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js @@ -0,0 +1 @@ +export { default } from 'foo'; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js new file mode 100644 index 000000000000..c986dfedbbef --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _foo = require('foo'); + +Object.defineProperty(exports, 'default', { + enumerable: true, + get: function () { + return _foo.default; + } +}); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js new file mode 100644 index 000000000000..65b75b7293b4 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +foo(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js new file mode 100644 index 000000000000..1bc59ef949a6 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js @@ -0,0 +1,5 @@ +"use strict"; + +var _foo = require("foo"); + +(0, _foo.default)(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js new file mode 100644 index 000000000000..bf67ef46a2d0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js @@ -0,0 +1,4 @@ +import * as foo from 'foo'; + +foo.bar(); +foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js new file mode 100644 index 000000000000..284db9decde0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var _foo = require('foo'); + +_foo.bar(); +_foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json new file mode 100644 index 000000000000..b2a35b9fc8cf --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-commonjs", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js new file mode 100644 index 000000000000..bf67ef46a2d0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js @@ -0,0 +1,4 @@ +import * as foo from 'foo'; + +foo.bar(); +foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js new file mode 100644 index 000000000000..284db9decde0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var _foo = require('foo'); + +_foo.bar(); +_foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/package.json b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json index a5d78cf2e7d1..864028998a36 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/package.json +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json @@ -13,7 +13,7 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1", + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1", "babel-plugin-syntax-dynamic-import": "7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-umd/package.json b/packages/babel-plugin-transform-es2015-modules-umd/package.json index 7d846e75c768..b48322db9383 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/package.json +++ b/packages/babel-plugin-transform-es2015-modules-umd/package.json @@ -13,6 +13,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-object-super/package.json b/packages/babel-plugin-transform-es2015-object-super/package.json index 7731843c6184..4de65e9bb503 100644 --- a/packages/babel-plugin-transform-es2015-object-super/package.json +++ b/packages/babel-plugin-transform-es2015-object-super/package.json @@ -12,6 +12,6 @@ "babel-helper-replace-supers": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-parameters/package.json b/packages/babel-plugin-transform-es2015-parameters/package.json index 01053fdab93c..6347fdbf677d 100644 --- a/packages/babel-plugin-transform-es2015-parameters/package.json +++ b/packages/babel-plugin-transform-es2015-parameters/package.json @@ -16,6 +16,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json index c37be49ab906..d7e7ada68188 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json @@ -12,6 +12,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-spread/package.json b/packages/babel-plugin-transform-es2015-spread/package.json index 60f5c64c57d7..9855e702f5d9 100644 --- a/packages/babel-plugin-transform-es2015-spread/package.json +++ b/packages/babel-plugin-transform-es2015-spread/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/package.json b/packages/babel-plugin-transform-es2015-sticky-regex/package.json index 80670f7ab19f..b8a034217292 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/package.json +++ b/packages/babel-plugin-transform-es2015-sticky-regex/package.json @@ -13,6 +13,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-template-literals/package.json b/packages/babel-plugin-transform-es2015-template-literals/package.json index 703615bc0408..39072ab9ce56 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/package.json +++ b/packages/babel-plugin-transform-es2015-template-literals/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/package.json b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json index b9a94b2a6cea..99caefcdb57f 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/package.json +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/package.json b/packages/babel-plugin-transform-es2015-unicode-regex/package.json index 92c8155f6f67..502acb965ea1 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/package.json +++ b/packages/babel-plugin-transform-es2015-unicode-regex/package.json @@ -13,6 +13,6 @@ "regexpu-core": "^4.0.2" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/package.json b/packages/babel-plugin-transform-es3-member-expression-literals/package.json index 69b056124925..2738735d1ecd 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/package.json +++ b/packages/babel-plugin-transform-es3-member-expression-literals/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es3-property-literals/package.json b/packages/babel-plugin-transform-es3-property-literals/package.json index 19e1aa5f1dd4..66887c68fad2 100644 --- a/packages/babel-plugin-transform-es3-property-literals/package.json +++ b/packages/babel-plugin-transform-es3-property-literals/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es5-property-mutators/package.json b/packages/babel-plugin-transform-es5-property-mutators/package.json index 6faac6bc9863..2b52a92d8a69 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/package.json +++ b/packages/babel-plugin-transform-es5-property-mutators/package.json @@ -12,6 +12,6 @@ "babel-helper-define-map": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-eval/package.json b/packages/babel-plugin-transform-eval/package.json index e7378f82884f..0420fd767cd8 100644 --- a/packages/babel-plugin-transform-eval/package.json +++ b/packages/babel-plugin-transform-eval/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-exponentiation-operator/package.json b/packages/babel-plugin-transform-exponentiation-operator/package.json index 757438a2530e..904ca600b119 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/package.json +++ b/packages/babel-plugin-transform-exponentiation-operator/package.json @@ -13,6 +13,6 @@ "babel-helper-builder-binary-assignment-operator-visitor": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-export-extensions/package.json b/packages/babel-plugin-transform-export-extensions/package.json index 4c9fc99b2736..83b20f22ff94 100644 --- a/packages/babel-plugin-transform-export-extensions/package.json +++ b/packages/babel-plugin-transform-export-extensions/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-export-extensions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-flow-comments/package.json b/packages/babel-plugin-transform-flow-comments/package.json index a44a453c0158..54aad7021924 100644 --- a/packages/babel-plugin-transform-flow-comments/package.json +++ b/packages/babel-plugin-transform-flow-comments/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-flow": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-flow-strip-types/package.json b/packages/babel-plugin-transform-flow-strip-types/package.json index 9ddc454c1366..345e6091f735 100644 --- a/packages/babel-plugin-transform-flow-strip-types/package.json +++ b/packages/babel-plugin-transform-flow-strip-types/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-flow": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-function-bind/package.json b/packages/babel-plugin-transform-function-bind/package.json index b7b3c2b95786..608bcde67100 100644 --- a/packages/babel-plugin-transform-function-bind/package.json +++ b/packages/babel-plugin-transform-function-bind/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-function-bind": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-jscript/package.json b/packages/babel-plugin-transform-jscript/package.json index 2652907040e2..a9e7124dd586 100644 --- a/packages/babel-plugin-transform-jscript/package.json +++ b/packages/babel-plugin-transform-jscript/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-assign/package.json b/packages/babel-plugin-transform-object-assign/package.json index 01e812e89c13..eccbba7b596f 100644 --- a/packages/babel-plugin-transform-object-assign/package.json +++ b/packages/babel-plugin-transform-object-assign/package.json @@ -10,6 +10,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-rest-spread/package.json b/packages/babel-plugin-transform-object-rest-spread/package.json index fd35f3c08ce5..5e8e352239ff 100644 --- a/packages/babel-plugin-transform-object-rest-spread/package.json +++ b/packages/babel-plugin-transform-object-rest-spread/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-object-rest-spread": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json index 9afdc54e1369..599761b63ba3 100644 --- a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json +++ b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-proto-to-assign/package.json b/packages/babel-plugin-transform-proto-to-assign/package.json index 015ded1ab6a8..51b69cc3ad08 100644 --- a/packages/babel-plugin-transform-proto-to-assign/package.json +++ b/packages/babel-plugin-transform-proto-to-assign/package.json @@ -12,6 +12,6 @@ "lodash": "^4.2.0" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-constant-elements/package.json b/packages/babel-plugin-transform-react-constant-elements/package.json index f02d44c5d05d..45b0d6bf057f 100644 --- a/packages/babel-plugin-transform-react-constant-elements/package.json +++ b/packages/babel-plugin-transform-react-constant-elements/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-display-name/package.json b/packages/babel-plugin-transform-react-display-name/package.json index 7660d0fedc9b..84747a6f53c0 100644 --- a/packages/babel-plugin-transform-react-display-name/package.json +++ b/packages/babel-plugin-transform-react-display-name/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-inline-elements/package.json b/packages/babel-plugin-transform-react-inline-elements/package.json index eca600b1398e..f45621051735 100644 --- a/packages/babel-plugin-transform-react-inline-elements/package.json +++ b/packages/babel-plugin-transform-react-inline-elements/package.json @@ -12,6 +12,6 @@ "babel-runtime": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-compat/package.json b/packages/babel-plugin-transform-react-jsx-compat/package.json index 33f3326a2ef6..4788f5e3f0ef 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/package.json +++ b/packages/babel-plugin-transform-react-jsx-compat/package.json @@ -12,6 +12,6 @@ "babel-helper-builder-react-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-self/package.json b/packages/babel-plugin-transform-react-jsx-self/package.json index d1edd9a5e11e..de0fc545ab02 100644 --- a/packages/babel-plugin-transform-react-jsx-self/package.json +++ b/packages/babel-plugin-transform-react-jsx-self/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-source/package.json b/packages/babel-plugin-transform-react-jsx-source/package.json index 2fd0debd44a8..e9b1f0cc598a 100644 --- a/packages/babel-plugin-transform-react-jsx-source/package.json +++ b/packages/babel-plugin-transform-react-jsx-source/package.json @@ -12,6 +12,6 @@ "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx/package.json b/packages/babel-plugin-transform-react-jsx/package.json index 74631ed50450..954bf143601b 100644 --- a/packages/babel-plugin-transform-react-jsx/package.json +++ b/packages/babel-plugin-transform-react-jsx/package.json @@ -13,6 +13,6 @@ "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-regenerator/package.json b/packages/babel-plugin-transform-regenerator/package.json index 9fc402effd34..56b1a5ad7847 100644 --- a/packages/babel-plugin-transform-regenerator/package.json +++ b/packages/babel-plugin-transform-regenerator/package.json @@ -11,6 +11,6 @@ }, "license": "MIT", "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-runtime/package.json b/packages/babel-plugin-transform-runtime/package.json index f21cb2905421..e731d2d8bd83 100644 --- a/packages/babel-plugin-transform-runtime/package.json +++ b/packages/babel-plugin-transform-runtime/package.json @@ -9,6 +9,6 @@ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-strict-mode/package.json b/packages/babel-plugin-transform-strict-mode/package.json index ae48917dc05e..62212a0f171a 100644 --- a/packages/babel-plugin-transform-strict-mode/package.json +++ b/packages/babel-plugin-transform-strict-mode/package.json @@ -12,6 +12,6 @@ "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-preset-es2015/package.json b/packages/babel-preset-es2015/package.json index 2bd7ed0ac5bf..60c1a389e2eb 100644 --- a/packages/babel-preset-es2015/package.json +++ b/packages/babel-preset-es2015/package.json @@ -34,7 +34,7 @@ "babel-plugin-transform-regenerator": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.1", - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-transform-fixture-test-runner": "^7.0.0-alpha.1", + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-preset-latest/package.json b/packages/babel-preset-latest/package.json index 5211461cceeb..582557770ac8 100644 --- a/packages/babel-preset-latest/package.json +++ b/packages/babel-preset-latest/package.json @@ -13,6 +13,6 @@ "babel-preset-es2017": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-alpha.1" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-register/package.json b/packages/babel-register/package.json index 758675973837..f0ab4636f7c1 100644 --- a/packages/babel-register/package.json +++ b/packages/babel-register/package.json @@ -1,6 +1,6 @@ { "name": "babel-register", - "version": "7.0.0-alpha.1", + "version": "7.0.0-alpha.2", "description": "babel require hook", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-register", @@ -8,7 +8,7 @@ "main": "lib/node.js", "browser": "lib/browser.js", "dependencies": { - "babel-core": "7.0.0-alpha.1", + "babel-core": "7.0.0-alpha.2", "core-js": "^2.4.0", "home-or-tmp": "^3.0.0", "lodash": "^4.2.0", diff --git a/packages/babel-traverse/src/path/replacement.js b/packages/babel-traverse/src/path/replacement.js index a2028e6d8bf8..e82bba5b3989 100644 --- a/packages/babel-traverse/src/path/replacement.js +++ b/packages/babel-traverse/src/path/replacement.js @@ -125,7 +125,8 @@ export function replaceWith(replacement) { if (this.isNodeType("Statement") && t.isExpression(replacement)) { if ( !this.canHaveVariableDeclarationOrExpression() && - !this.canSwapBetweenExpressionAndStatement(replacement) + !this.canSwapBetweenExpressionAndStatement(replacement) && + !this.parentPath.isExportDefaultDeclaration() ) { // replacing a statement with an expression so wrap it in an expression statement replacement = t.expressionStatement(replacement); diff --git a/packages/babel-traverse/test/replacement.js b/packages/babel-traverse/test/replacement.js new file mode 100644 index 000000000000..eb29364f2fb4 --- /dev/null +++ b/packages/babel-traverse/test/replacement.js @@ -0,0 +1,28 @@ +import traverse from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; +import * as t from "babel-types"; + +describe("path/replacement", function () { + describe("replaceWith", function () { + const ast = parse("export default function() {};", { sourceType: "module" }); + + it("replaces declaration in ExportDefaultDeclaration node", function() { + traverse(ast, { + FunctionDeclaration(path) { + path.replaceWith(t.arrayExpression([ + t.functionExpression( + path.node.id, + path.node.params, + path.node.body, + path.node.generator, + path.node.async + ), + ])); + }, + }); + + assert(ast.program.body[0].declaration.type == "ArrayExpression"); + }); + }); +});