@@ -25,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).
@@ -38,11 +40,14 @@ Feel free to check out the `#discussion`/`#development` channels on our [slack](
**Note:** Versions `< 5.1.10` can't be built.
-Babel is built for node 0.10 and up but we develop using node 6. Make sure you are on npm 3.
+Babel is built for node 4 and up but we develop using node 6. Make sure you are on npm 3.
You can check this with `node -v` and `npm -v`.
-#### Setup
+In addition, make sure that Yarn is installed.
+Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
+
+### Setup
```sh
$ git clone https://github.com/babel/babel
@@ -72,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:
@@ -103,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
@@ -124,30 +129,31 @@ $ TEST_DEBUG=true make test
To test the code coverage, use:
```sh
-$ make test-cov
+$ 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`.
@@ -180,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.
@@ -196,9 +202,46 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js
- expected.json (will be generated if not created)
```
-#### Internals
+### 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.
+To get a better understanding of what is actually going on for this particular piece of code, we are going to make use of breakpoints.
+
+```diff
+generate() {
++ debugger; // breakpoint
+ return super.generate(this.ast);
+}
+```
+
+To include the changes, we have to make sure to build Babel:
+
+```bash
+$ make build
+```
+
+Next, we need to execute `Generator.generate()`, which can be achieved by running a test case in the `babel-generator` package.
+For example, we can run the test case that tests the generation of class declarations:
+
+```bash
+$ TEST_DEBUG=true TEST_GREP=ClassDeclaration make test-only
+
+./scripts/test.sh
+Debugger listening on port 9229.
+Warning: This is an experimental feature and could change at any time.
+To start debugging, open the following URL in Chrome:
+ chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/3cdaebd2-be88-4e7b-a94b-432950ab72d0
+```
+
+To start the debugging in Chrome DevTools, open the given URL.
+The debugger starts at the first executed line of code, which is Mocha's first line by default.
+Click _Resume script execution_ to jump to the set breakpoint.
+Note that the code shown in Chrome DevTools is compiled code and therefore differs.
+
+## Internals
- AST spec ([babylon/ast/spec.md](https://github.com/babel/babylon/blob/master/ast/spec.md))
-- Versionning ([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/LICENSE b/LICENSE
index 6a5e2b14bd..d6b2e00435 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2014-2016 Sebastian McKenzie
+Copyright (c) 2014-2017 Sebastian McKenzie
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/Makefile b/Makefile
index 561846cef5..3f68e4cb04 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ MAKEFLAGS = -j1
export NODE_ENV = test
-.PHONY: build build-dist watch lint fix clean test-clean test-only test test-cov test-ci publish bootstrap
+.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap
build: clean
./node_modules/.bin/gulp build
@@ -16,7 +16,7 @@ build-dist: build
watch: clean
rm -rf packages/*/lib
- BABEL_ENV=development ./node_modules/.bin/gulp watch
+ ./node_modules/.bin/gulp watch
lint:
./node_modules/.bin/eslint packages/ --format=codeframe
@@ -42,22 +42,19 @@ clean-all:
rm -rf packages/*/node_modules
make clean
-# without lint
test-only:
./scripts/test.sh
make test-clean
test: lint test-only
-test-cov: clean
- # rebuild with test
- rm -rf packages/*/lib
- BABEL_ENV=test ./node_modules/.bin/gulp build
- ./scripts/test-cov.sh
-
test-ci:
- NODE_ENV=test make bootstrap
- make test-cov
+ make bootstrap
+ make test-only
+
+test-ci-coverage:
+ BABEL_ENV=cov make bootstrap
+ ./scripts/test-cov.sh
./node_modules/.bin/codecov -f coverage/coverage-final.json
publish:
@@ -66,15 +63,14 @@ publish:
BABEL_ENV=production make build-dist
make test
# not using lerna independent mode atm, so only update packages that have changed since we use ^
- ./node_modules/.bin/lerna publish --only-explicit-updates
+ # --only-explicit-updates
+ ./node_modules/.bin/lerna publish --npm-tag=next --exact --skip-temp-tag
make clean
- #./scripts/build-website.sh
bootstrap:
make clean-all
- npm install
+ yarn
./node_modules/.bin/lerna bootstrap
make build
cd packages/babel-runtime; \
- npm install; \
node scripts/build-dist.js
diff --git a/README.md b/README.md
index 04057583fe..367565bba1 100644
--- a/README.md
+++ b/README.md
@@ -9,11 +9,12 @@
-
-
-
+
+
+
+
-
+
Babel is a community-driven tool that helps you write the latest version of JavaScript.
@@ -24,13 +25,13 @@ When your supported environments don't support certain features natively, it wil
```js
// ES2015 arrow function
-[1,2,3].map(n => n + 1);
+[1, 2, 3].map((n) => n + 1);
```
**Out**
```js
-[1,2,3].map(function(n) {
+[1, 2, 3].map(function(n) {
return n + 1;
});
```
@@ -46,6 +47,7 @@ Try it out at our [REPL](https://babeljs.io/repl/#?babili=false&evaluate=true&li
- [Transform Plugins](#transform-plugins)
- [Syntax Plugins](#syntax-plugins)
- [Misc Packages](#misc-packages)
+- [Team](#team)
- [License](#license)
# FAQ
@@ -70,7 +72,7 @@ https://phabricator.babeljs.io/T2168 mostly corresponds to https://github.com/ba
## Want to report an issue with [babeljs.io](https://babeljs.io) (the website)?
-For documentation and website issues please visit the [babel/babel.github.io](https://github.com/babel/babel.github.io)repo.
+For documentation and website issues please visit the [babel/babel.github.io](https://github.com/babel/babel.github.io) repo.
## Want to contribute to Babel?
@@ -123,8 +125,8 @@ Check out the [`babel-handbook`](https://github.com/thejameskyle/babel-handbook/
- [`babel-cli`](/packages/babel-cli) is the CLI tool that runs `babel-core` and helps with outputting to a directory, a file, stdout and more (also includes `babel-node`). Check out the [docs](https://babeljs.io/docs/usage/cli/).
- [`babel-types`](/packages/babel-types) is used to validate, build, change AST nodes.
- [`babel-polyfill`](/packages/babel-polyfill) is [literally a wrapper](https://github.com/babel/babel/blob/master/packages/babel-polyfill/src/index.js) around [`core-js`](https://github.com/zloirock/core-js) and [regenerator-runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime). Check out the [docs](https://babeljs.io/docs/usage/polyfill/).
-- [`babel-runtime`](/packages/babel-runtime) is similar to the polyfill except that it doesn't modify the global scope and is to be used with [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) (usually in library/plugin code). Check out the [docs](https://babeljs.io/docs/plugins/transform-runtime/)
-- [`babel-register`](/packages/babel-register) is a way to automatically compile files with babel on the fly by binding to node's require. Check out the [docs](http://babeljs.io/docs/usage/require/)
+- [`babel-runtime`](/packages/babel-runtime) is similar to the polyfill except that it doesn't modify the global scope and is to be used with [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) (usually in library/plugin code). Check out the [docs](https://babeljs.io/docs/plugins/transform-runtime/).
+- [`babel-register`](/packages/babel-register) is a way to automatically compile files with babel on the fly by binding to node's require. Check out the [docs](http://babeljs.io/docs/usage/require/).
- [`babel-template`](/packages/babel-template) is a helper function to make AST nodes. Instead you can pass a string representing the code you want to create rather than tediously building them using `babel-types`.
- [`babel-helpers`](/packages/babel-helpers) is a set of premade `babel-template` functions that are used in some babel plugins.
- [`babel-code-frame`](/packages/babel-code-frame) is a standalone package used to generate errors that prints the source code and points to error locations.
@@ -135,25 +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) | [](https://www.npmjs.com/package/babel-preset-es2015) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2015) |
-| [`babel-preset-es2016`](/packages/babel-preset-es2016) | [](https://www.npmjs.com/package/babel-preset-es2016) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2016) |
-| [`babel-preset-es2017`](/packages/babel-preset-es2017) | [](https://www.npmjs.com/package/babel-preset-es2017) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2017) |
-| [`babel-preset-latest`](/packages/babel-preset-latest) | [](https://www.npmjs.com/package/babel-preset-latest) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-latest) |
-| [`babel-preset-stage-0`](/packages/babel-preset-stage-0) | [](https://www.npmjs.com/package/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) | [](https://www.npmjs.com/package/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) | [](https://www.npmjs.com/package/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) | [](https://www.npmjs.com/package/babel-preset-stage-3) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-3) |
-| [`babel-preset-react`](/packages/babel-preset-react) | [](https://www.npmjs.com/package/babel-preset-react) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-react) |
-
-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.
+| Package | Version | Dependencies | Description |
+|--------|-------|------------|---|
+| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [](https://www.npmjs.com/package/babel-preset-env) | [](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)
@@ -165,79 +151,57 @@ Plugins are the heart of Babel and what make it work.
#### Transform Plugins
-There are many kinds of plugins: ones that convert ES6/ES2015 to ES5, transform to ES3, minification, JSX, flow, experimental features, and more.
-
-| Package | Version | External Deps |
-|--------|-------|------------|
-| [`babel-plugin-check-es2015-constants`](/packages/babel-plugin-check-es2015-constants) | [](https://www.npmjs.com/package/babel-plugin-check-es2015-constants) | |
-| [`babel-plugin-transform-async-functions`](/packages/babel-plugin-transform-async-functions) | [](https://www.npmjs.com/package/babel-plugin-transform-async-functions) | |
-| [`babel-plugin-transform-async-generator-functions`](/packages/babel-plugin-transform-async-generator-functions) | [](https://www.npmjs.com/package/babel-plugin-transform-async-generator-functions) |
-| [`babel-plugin-transform-async-to-generator`](/packages/babel-plugin-transform-async-to-generator) | [](https://www.npmjs.com/package/babel-plugin-transform-async-to-generator) | |
-| [`babel-plugin-transform-async-to-module-method`](/packages/babel-plugin-transform-async-to-module-method) | [](https://www.npmjs.com/package/babel-plugin-transform-async-to-module-method) | |
-| [`babel-plugin-transform-class-properties`](/packages/babel-plugin-transform-class-properties) | [](https://www.npmjs.com/package/babel-plugin-transform-class-properties) | |
-| [`babel-plugin-transform-decorators`](/packages/babel-plugin-transform-decorators) | [](https://www.npmjs.com/package/babel-plugin-transform-decorators) | |
-| [`babel-plugin-transform-do-expressions`](/packages/babel-plugin-transform-do-expressions) | [](https://www.npmjs.com/package/babel-plugin-transform-do-expressions) | |
-| [`babel-plugin-transform-es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-arrow-functions) | |
-| [`babel-plugin-transform-es2015-block-scoped-functions`](/packages/babel-plugin-transform-es2015-block-scoped-functions) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-block-scoped-functions) | |
-| [`babel-plugin-transform-es2015-block-scoping`](/packages/babel-plugin-transform-es2015-block-scoping) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-block-scoping) | [](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-es2015-block-scoping) |
-| [`babel-plugin-transform-es2015-classes`](/packages/babel-plugin-transform-es2015-classes) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-classes) | |
-| [`babel-plugin-transform-es2015-computed-properties`](/packages/babel-plugin-transform-es2015-computed-properties) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-computed-properties) | |
-| [`babel-plugin-transform-es2015-destructuring`](/packages/babel-plugin-transform-es2015-destructuring) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-destructuring) | |
-| [`babel-plugin-transform-es2015-duplicate-keys`](/packages/babel-plugin-transform-es2015-duplicate-keys) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-duplicate-keys) | |
-| [`babel-plugin-transform-es2015-for-of`](/packages/babel-plugin-transform-es2015-for-of) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-for-of) | |
-| [`babel-plugin-transform-es2015-function-name`](/packages/babel-plugin-transform-es2015-function-name) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-function-name) | |
-| [`babel-plugin-transform-es2015-instanceof`](/packages/babel-plugin-transform-es2015-instanceof) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-instanceof) | |
-| [`babel-plugin-transform-es2015-literals`](/packages/babel-plugin-transform-es2015-literals) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-literals) | |
-| [`babel-plugin-transform-es2015-modules-amd`](/packages/babel-plugin-transform-es2015-modules-amd) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-amd) | |
-| [`babel-plugin-transform-es2015-modules-commonjs`](/packages/babel-plugin-transform-es2015-modules-commonjs) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs) | |
-| [`babel-plugin-transform-es2015-modules-systemjs`](/packages/babel-plugin-transform-es2015-modules-systemjs) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-systemjs) | |
-| [`babel-plugin-transform-es2015-modules-umd`](/packages/babel-plugin-transform-es2015-modules-umd) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-umd) | |
-| [`babel-plugin-transform-es2015-object-super`](/packages/babel-plugin-transform-es2015-object-super) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-object-super) | |
-| [`babel-plugin-transform-es2015-parameters`](/packages/babel-plugin-transform-es2015-parameters) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-parameters) | |
-| [`babel-plugin-transform-es2015-shorthand-properties`](/packages/babel-plugin-transform-es2015-shorthand-properties) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-shorthand-properties) | |
-| [`babel-plugin-transform-es2015-spread`](/packages/babel-plugin-transform-es2015-spread) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-spread) | |
-| [`babel-plugin-transform-es2015-sticky-regex`](/packages/babel-plugin-transform-es2015-sticky-regex) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-sticky-regex) | |
-| [`babel-plugin-transform-es2015-template-literals`](/packages/babel-plugin-transform-es2015-template-literals) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-template-literals) | |
-| [`babel-plugin-transform-es2015-typeof-symbol`](/packages/babel-plugin-transform-es2015-typeof-symbol) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-typeof-symbol) | |
-| [`babel-plugin-transform-es2015-unicode-regex`](/packages/babel-plugin-transform-es2015-unicode-regex) | [](https://www.npmjs.com/package/babel-plugin-transform-es2015-unicode-regex) | [](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-es2015-unicode-regex) |
-| [`babel-plugin-transform-es3-member-expression-literals`](/packages/babel-plugin-transform-es3-member-expression-literals) | [](https://www.npmjs.com/package/babel-plugin-transform-es3-member-expression-literals) | |
-| [`babel-plugin-transform-es3-property-literals`](/packages/babel-plugin-transform-es3-property-literals) | [](https://www.npmjs.com/package/babel-plugin-transform-es3-property-literals) | |
-| [`babel-plugin-transform-es5-property-mutators`](/packages/babel-plugin-transform-es5-property-mutators) | [](https://www.npmjs.com/package/babel-plugin-transform-es5-property-mutators) | |
-| [`babel-plugin-transform-eval`](/packages/babel-plugin-transform-eval) | [](https://www.npmjs.com/package/babel-plugin-transform-eval) | |
-| [`babel-plugin-transform-exponentiation-operator`](/packages/babel-plugin-transform-exponentiation-operator) | [](https://www.npmjs.com/package/babel-plugin-transform-exponentiation-operator) | |
-| [`babel-plugin-transform-export-extensions`](/packages/babel-plugin-transform-export-extensions) | [](https://www.npmjs.com/package/babel-plugin-transform-export-extensions) | |
-| [`babel-plugin-transform-flow-comments`](/packages/babel-plugin-transform-flow-comments) | [](https://www.npmjs.com/package/babel-plugin-transform-flow-comments) | |
-| [`babel-plugin-transform-flow-strip-types`](/packages/babel-plugin-transform-flow-strip-types) | [](https://www.npmjs.com/package/babel-plugin-transform-flow-strip-types) | |
-| [`babel-plugin-transform-function-bind`](/packages/babel-plugin-transform-function-bind) | [](https://www.npmjs.com/package/babel-plugin-transform-function-bind) | |
-| [`babel-plugin-transform-jscript`](/packages/babel-plugin-transform-jscript) | [](https://www.npmjs.com/package/babel-plugin-transform-jscript) | |
-| [`babel-plugin-transform-object-assign`](/packages/babel-plugin-transform-object-assign) | [](https://www.npmjs.com/package/babel-plugin-transform-object-assign) | |
-| [`babel-plugin-transform-object-rest-spread`](/packages/babel-plugin-transform-object-rest-spread) | [](https://www.npmjs.com/package/babel-plugin-transform-object-rest-spread) | |
-| [`babel-plugin-transform-object-set-prototype-of-to-assign`](/packages/babel-plugin-transform-object-set-prototype-of-to-assign) | [](https://www.npmjs.com/package/babel-plugin-transform-object-set-prototype-of-to-assign) | |
-| [`babel-plugin-transform-proto-to-assign`](/packages/babel-plugin-transform-proto-to-assign) | [](https://www.npmjs.com/package/babel-plugin-transform-proto-to-assign) | [](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-proto-to-assign) |
-| [`babel-plugin-transform-react-constant-elements`](/packages/babel-plugin-transform-react-constant-elements) | [](https://www.npmjs.com/package/babel-plugin-transform-react-constant-elements) | |
-| [`babel-plugin-transform-react-display-name`](/packages/babel-plugin-transform-react-display-name) | [](https://www.npmjs.com/package/babel-plugin-transform-react-display-name) | |
-| [`babel-plugin-transform-react-inline-elements`](/packages/babel-plugin-transform-react-inline-elements) | [](https://www.npmjs.com/package/babel-plugin-transform-react-inline-elements) | |
-| [`babel-plugin-transform-react-jsx`](/packages/babel-plugin-transform-react-jsx) | [](https://www.npmjs.com/package/babel-plugin-transform-react-jsx) | |
-| [`babel-plugin-transform-react-jsx-compat`](/packages/babel-plugin-transform-react-jsx-compat) | [](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-compat) | |
-| [`babel-plugin-transform-react-jsx-self`](/packages/babel-plugin-transform-react-jsx-self) | [](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-self) | |
-| [`babel-plugin-transform-react-jsx-source`](/packages/babel-plugin-transform-react-jsx-source) | [](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) | |
-| [`babel-plugin-transform-regenerator`](/packages/babel-plugin-transform-regenerator) | [](https://www.npmjs.com/package/babel-plugin-transform-regenerator) | [](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-regenerator) |
-| [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) | [](https://www.npmjs.com/package/babel-plugin-transform-runtime) | |
-| [`babel-plugin-transform-strict-mode`](/packages/babel-plugin-transform-strict-mode) | [](https://www.npmjs.com/package/babel-plugin-transform-strict-mode) | |
+There are many kinds of plugins: ones that convert ES6/ES2015 to ES5, transform to ES3, minification, JSX, flow, experimental features, and more. Check out our [website for more](http://babeljs.io/docs/plugins/#transform-plugins).
#### Syntax Plugins
-These just enable the transform plugins to be able to parse certain features (the transform plugins already include the syntax plugins so you don't need both): `babel-plugin-syntax-x`.
+These just enable the transform plugins to be able to parse certain features (the transform plugins already include the syntax plugins so you don't need both): `babel-plugin-syntax-x`. Check out our [website for more](http://babeljs.io/docs/plugins/#syntax-plugins).
### Helpers
These are mostly for internal use in various plugins: `babel-helper-x`.
-### Misc Packages
+## Team
-- [`babel`](/packages/babel) the deprecated `babel` package on npm that was used in Babel 5.
-- [`babel-messages`](/packages/babel-messages) a package to keep error messages, etc (not always used)
+### Core members
+
+[](https://github.com/babel) | [](https://github.com/danez) | [](https://github.com/loganfsmyth) | [](https://github.com/hzoo) |
+|---|---|---|---|---|
+Babel | Daniel Tschinder | Logan Smyth | Henry Zhu |
+:octocat: [@babel](https://github.com/babel) | [@danez](https://github.com/danez) | [@loganfsmyth](https://github.com/loganfsmyth) | [@hzoo](https://github.com/hzoo) |
+:bird: [@babeljs](https://twitter.com/babeljs) | [@TschinderDaniel](https://twitter.com/TschinderDaniel) | [@loganfsmyth](https://twitter.com/loganfsmyth) | [@left_pad](https://twitter.com/left_pad) |
+
+### Members
+
+[](https://github.com/drewml) | [](https://github.com/boopathi) | [](https://github.com/existentialism) | [](https://github.com/danharper) | [](https://github.com/kovensky) | [](https://github.com/aaronang) | [](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_) |
+
+[](https://github.com/kangax) | [](https://github.com/kaicataldo) | [](https://github.com/motiz88) | [](https://github.com/xtuc) | [](https://github.com/STRML) | [](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
+
+[](https://github.com/babel-bot) |
+|---|
+| Babel Bot |
+| [@babel-bot](https://github.com/babel-bot) |
+| [@babeljs](https://twitter.com/babeljs) |
+
+### Inactive members
+
+[](https://github.com/amasad) | [](https://github.com/thejameskyle) | [](https://github.com/jmm) | [](https://github.com/kittens) (Creator) |
+|---|---|---|---|
+Amjad Masad | James Kyle | Jesse McCarthy | Sebastian McKenzie |
+[@amasad](https://github.com/amasad) | [@thejameskyle](https://github.com/thejameskyle) | [@jmm](https://github.com/jmm) | [@sebmck](https://twitter.com/sebmck) |
+| [@amasad](https://twitter.com/amasad) | [@thejameskyle](https://twitter.com/thejameskyle) | [@mccjm](https://twitter.com/mccjm) | [@kittens](https://github.com/kittens)
## License
[MIT](https://github.com/babel/babel/blob/master/LICENSE)
+
diff --git a/babel.sublime-project b/babel.sublime-project
new file mode 100644
index 0000000000..1f18a8cc50
--- /dev/null
+++ b/babel.sublime-project
@@ -0,0 +1,25 @@
+{
+ "settings": {
+ "rulers": [
+ 110
+ ],
+
+ // Set to false to disable detection of tabs vs. spaces on load
+ "detect_indentation": false,
+
+ "translate_tabs_to_spaces": true,
+
+ "tab_size": 2
+ },
+
+ "folders": [{
+ "path": ".",
+ "folder_exclude_patterns": [
+ "packages/*/lib",
+ "node_modules"
+ ],
+ "file_exclude_patterns": [
+
+ ]
+ }]
+}
diff --git a/circle.yml b/circle.yml
index 8aa7e6da90..df9b1c49ec 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,7 +1,15 @@
machine:
node:
version:
- 0.10.46
+ 6
+
+dependencies:
+ pre:
+ - curl -o- -L https://yarnpkg.com/install.sh | bash
+ cache_directories:
+ - ~/.yarn-cache
+ override:
+ - yarn
test:
override:
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000000..3e31ee1814
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,4 @@
+coverage:
+ parsers:
+ javascript:
+ enable_partials: yes
diff --git a/doc/design/compiler-environment-support.md b/doc/design/compiler-environment-support.md
index 77c01b0878..1d5a867205 100644
--- a/doc/design/compiler-environment-support.md
+++ b/doc/design/compiler-environment-support.md
@@ -2,12 +2,12 @@
**NOTE:** Compiler support does not dictate the runtime requirements of compiled code.
-## Supported environments
+## Officially supported environments
The Babel compiler is **only** supported in these environments:
- Modern browsers such as Chrome, Firefox, Safari, Edge etc.
- - Node 0.10+
+ - Node.js 4 and upper versions
## Unsupported environments
@@ -17,7 +17,6 @@ to:
- Rhino
- Nashorn
- Internet Explorer
- - ...
**NOTE:** If Babel works in any of the unsupported environments, it is purely
coincidental and has no bearing on future compatibility. Use at your own risk.
diff --git a/lerna.json b/lerna.json
index d2ff6578fb..91036a0b36 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,6 +1,6 @@
{
- "lerna": "2.0.0-beta.23",
- "version": "6.21.0",
+ "lerna": "2.0.0-beta.38",
+ "version": "7.0.0-alpha.2",
"changelog": {
"repo": "babel/babel",
"labels": {
@@ -13,13 +13,13 @@
"tag: internal": ":house: Internal"
}
},
- "bootstrapConfig": {
- "ignore": "babel-runtime"
- },
- "publishConfig": {
- "ignore": [
- "*.md",
- "test/**"
- ]
+ "cacheDir": ".changelog",
+ "commands": {
+ "publish": {
+ "ignore": [
+ "*.md",
+ "test/**"
+ ]
+ }
}
}
diff --git a/lib/types.js b/lib/types.js
index e42a516b4a..869cd587f8 100644
--- a/lib/types.js
+++ b/lib/types.js
@@ -581,8 +581,8 @@ declare class BabelNodeDeclareVariable extends BabelNode {
id: any;
}
-declare class BabelNodeExistentialTypeParam extends BabelNode {
- type: "ExistentialTypeParam";
+declare class BabelNodeExistsTypeAnnotation extends BabelNode {
+ type: "ExistsTypeAnnotation";
}
declare class BabelNodeFunctionTypeAnnotation extends BabelNode {
@@ -632,8 +632,8 @@ declare class BabelNodeNullableTypeAnnotation extends BabelNode {
typeAnnotation: any;
}
-declare class BabelNodeNumericLiteralTypeAnnotation extends BabelNode {
- type: "NumericLiteralTypeAnnotation";
+declare class BabelNodeNumberLiteralTypeAnnotation extends BabelNode {
+ type: "NumberLiteralTypeAnnotation";
}
declare class BabelNodeNumberTypeAnnotation extends BabelNode {
@@ -873,7 +873,7 @@ type BabelNodeClass = BabelNodeClassDeclaration | BabelNodeClassExpression;
type BabelNodeModuleDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration | BabelNodeImportDeclaration;
type BabelNodeExportDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration;
type BabelNodeModuleSpecifier = BabelNodeExportSpecifier | BabelNodeImportDefaultSpecifier | BabelNodeImportNamespaceSpecifier | BabelNodeImportSpecifier | BabelNodeExportDefaultSpecifier | BabelNodeExportNamespaceSpecifier;
-type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistentialTypeParam | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumericLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
+type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistsTypeAnnotation | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumberLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
type BabelNodeFlowBaseAnnotation = BabelNodeAnyTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeVoidTypeAnnotation;
type BabelNodeFlowDeclaration = BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeInterfaceDeclaration | BabelNodeTypeAlias;
type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText;
@@ -965,7 +965,7 @@ declare module "babel-types" {
declare function declareModuleExports(typeAnnotation: any): BabelNodeDeclareModuleExports;
declare function declareTypeAlias(id: any, typeParameters: any, right: any): BabelNodeDeclareTypeAlias;
declare function declareVariable(id: any): BabelNodeDeclareVariable;
- declare function existentialTypeParam(): BabelNodeExistentialTypeParam;
+ declare function existsTypeAnnotation(): BabelNodeExistsTypeAnnotation;
declare function functionTypeAnnotation(typeParameters: any, params: any, rest: any, returnType: any): BabelNodeFunctionTypeAnnotation;
declare function functionTypeParam(name: any, typeAnnotation: any): BabelNodeFunctionTypeParam;
declare function genericTypeAnnotation(id: any, typeParameters: any): BabelNodeGenericTypeAnnotation;
@@ -974,7 +974,7 @@ declare module "babel-types" {
declare function intersectionTypeAnnotation(types: any): BabelNodeIntersectionTypeAnnotation;
declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation;
declare function nullableTypeAnnotation(typeAnnotation: any): BabelNodeNullableTypeAnnotation;
- declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation;
+ declare function numberLiteralTypeAnnotation(): BabelNodeNumberLiteralTypeAnnotation;
declare function numberTypeAnnotation(): BabelNodeNumberTypeAnnotation;
declare function stringLiteralTypeAnnotation(): BabelNodeStringLiteralTypeAnnotation;
declare function stringTypeAnnotation(): BabelNodeStringTypeAnnotation;
@@ -1101,7 +1101,7 @@ declare module "babel-types" {
declare function isDeclareModuleExports(node: Object, opts?: Object): boolean;
declare function isDeclareTypeAlias(node: Object, opts?: Object): boolean;
declare function isDeclareVariable(node: Object, opts?: Object): boolean;
- declare function isExistentialTypeParam(node: Object, opts?: Object): boolean;
+ declare function isExistsTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isFunctionTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isFunctionTypeParam(node: Object, opts?: Object): boolean;
declare function isGenericTypeAnnotation(node: Object, opts?: Object): boolean;
@@ -1110,7 +1110,7 @@ declare module "babel-types" {
declare function isIntersectionTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isMixedTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNullableTypeAnnotation(node: Object, opts?: Object): boolean;
- declare function isNumericLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
+ declare function isNumberLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNumberTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isStringLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isStringTypeAnnotation(node: Object, opts?: Object): boolean;
diff --git a/package.json b/package.json
index e62332ff19..b4ebcee5a0 100644
--- a/package.json
+++ b/package.json
@@ -1,4 +1,5 @@
{
+ "name": "babel",
"private": true,
"license": "MIT",
"scripts": {
@@ -14,11 +15,9 @@
"babel-plugin-istanbul": "^2.0.1",
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-plugin-transform-flow-strip-types": "^6.3.13",
- "babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.0.0",
"babel-register": "^6.14.0",
- "babel-runtime": "^6.0.0",
"browserify": "^13.1.1",
"bundle-collapser": "^1.2.1",
"chai": "^3.5.0",
@@ -26,8 +25,7 @@
"codecov": "^1.0.1",
"derequire": "^2.0.2",
"eslint": "^3.9.0",
- "eslint-config-babel": "^2.0.1",
- "eslint-plugin-babel": "^3.3.0",
+ "eslint-config-babel": "^6.0.0",
"eslint-plugin-flowtype": "^2.20.0",
"flow-bin": "^0.34.0",
"gulp": "^3.9.0",
@@ -36,7 +34,7 @@
"gulp-plumber": "^1.0.1",
"gulp-util": "^3.0.7",
"gulp-watch": "^4.3.5",
- "lerna": "2.0.0-beta.23",
+ "lerna": "^2.0.0-beta.38",
"lerna-changelog": "^0.2.0",
"lodash": "^4.2.0",
"mocha": "^3.0.0",
@@ -47,6 +45,10 @@
"through2": "^2.0.0",
"uglify-js": "^2.4.16"
},
+ "devEngines": {
+ "node": ">= 0.10 <= 7.x",
+ "npm": "2.x || 3.x || 4.x"
+ },
"babel": {
"comments": false,
"presets": [
@@ -59,13 +61,11 @@
"stage-0"
],
"plugins": [
- "./scripts/add-module-exports",
- "transform-runtime",
"transform-class-properties",
"transform-flow-strip-types"
],
"env": {
- "test": {
+ "cov": {
"auxiliaryCommentBefore": "istanbul ignore next",
"plugins": [
"istanbul"
diff --git a/packages/babel-cli/package.json b/packages/babel-cli/package.json
index 9dfdd70124..81ca73d32b 100644
--- a/packages/babel-cli/package.json
+++ b/packages/babel-cli/package.json
@@ -1,32 +1,39 @@
{
"name": "babel-cli",
- "version": "6.18.0",
+ "version": "7.0.0-alpha.2",
"description": "Babel command line.",
"author": "Sebastian McKenzie ",
"homepage": "https://babeljs.io/",
"license": "MIT",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-cli",
+ "keywords": [
+ "6to5",
+ "babel",
+ "es6",
+ "transpile",
+ "transpiler",
+ "babel-cli",
+ "compiler"
+ ],
"dependencies": {
- "babel-core": "^6.18.0",
- "babel-register": "^6.18.0",
- "babel-polyfill": "^6.16.0",
- "babel-runtime": "^6.9.0",
+ "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",
"fs-readdir-recursive": "^1.0.0",
- "glob": "^5.0.5",
+ "glob": "^7.0.0",
"lodash": "^4.2.0",
"output-file-sync": "^1.1.0",
- "path-is-absolute": "^1.0.0",
"slash": "^1.0.0",
"source-map": "^0.5.0",
"v8flags": "^2.0.10"
},
"optionalDependencies": {
- "chokidar": "^1.0.0"
+ "chokidar": "^1.6.1"
},
"devDependencies": {
- "babel-helper-fixtures": "^6.18.0"
+ "babel-helper-fixtures": "7.0.0-alpha.1"
},
"bin": {
"babel-doctor": "./bin/babel-doctor.js",
diff --git a/packages/babel-cli/src/_babel-node.js b/packages/babel-cli/src/_babel-node.js
index 3c7c40ed4d..ee6e340c31 100644
--- a/packages/babel-cli/src/_babel-node.js
+++ b/packages/babel-cli/src/_babel-node.js
@@ -1,4 +1,3 @@
-import pathIsAbsolute from "path-is-absolute";
import commander from "commander";
import Module from "module";
import { inspect } from "util";
@@ -7,11 +6,12 @@ import repl from "repl";
import { util } from "babel-core";
import * as babel from "babel-core";
import vm from "vm";
-import _ from "lodash";
import "babel-polyfill";
import register from "babel-register";
-let program = new commander.Command("babel-node");
+import pkg from "../package.json";
+
+const program = new commander.Command("babel-node");
program.option("-e, --eval [script]", "Evaluate script");
program.option("-p, --print [code]", "Evaluate script and print result");
@@ -21,7 +21,6 @@ program.option("-x, --extensions [extensions]", "List of extensions to hook into
program.option("-w, --plugins [string]", "", util.list);
program.option("-b, --presets [string]", "", util.list);
-let pkg = require("../package.json");
program.version(pkg.version);
program.usage("[options] [ -e script | script.js ] [arguments]");
program.parse(process.argv);
@@ -30,15 +29,15 @@ program.parse(process.argv);
register({
extensions: program.extensions,
- ignore: program.ignore,
- only: program.only,
- plugins: program.plugins,
- presets: program.presets,
+ ignore: program.ignore,
+ only: program.only,
+ plugins: program.plugins,
+ presets: program.presets,
});
//
-let replPlugin = ({ types: t }) => ({
+const replPlugin = ({ types: t }) => ({
visitor: {
ModuleDeclaration(path) {
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
@@ -56,24 +55,24 @@ let replPlugin = ({ types: t }) => ({
// If the executed code doesn't evaluate to a value,
// prevent implicit strict mode from printing 'use strict'.
path.pushContainer("body", t.expressionStatement(t.identifier("undefined")));
- }
- }
+ },
+ },
});
//
-let _eval = function (code, filename) {
+const _eval = function (code, filename) {
code = code.trim();
if (!code) return undefined;
code = babel.transform(code, {
filename: filename,
presets: program.presets,
- plugins: (program.plugins || []).concat([replPlugin])
+ plugins: (program.plugins || []).concat([replPlugin]),
}).code;
return vm.runInThisContext(code, {
- filename: filename
+ filename: filename,
});
};
@@ -84,17 +83,17 @@ if (program.eval || program.print) {
global.__filename = "[eval]";
global.__dirname = process.cwd();
- let module = new Module(global.__filename);
+ const module = new Module(global.__filename);
module.filename = global.__filename;
- module.paths = Module._nodeModulePaths(global.__dirname);
+ module.paths = Module._nodeModulePaths(global.__dirname);
global.exports = module.exports;
- global.module = module;
+ global.module = module;
global.require = module.require.bind(module);
- let result = _eval(code, global.__filename);
+ const result = _eval(code, global.__filename);
if (program.print) {
- let output = _.isString(result) ? result : inspect(result);
+ const output = typeof result === "string" ? result : inspect(result);
process.stdout.write(output + "\n");
}
} else {
@@ -104,27 +103,27 @@ if (program.eval || program.print) {
let i = 0;
let ignoreNext = false;
- _.each(args, function (arg, i2) {
+ args.some(function (arg, i2) {
if (ignoreNext) {
ignoreNext = false;
return;
}
if (arg[0] === "-") {
- let parsedArg = program[arg.slice(2)];
+ const parsedArg = program[arg.slice(2)];
if (parsedArg && parsedArg !== true) {
ignoreNext = true;
}
} else {
i = i2;
- return false;
+ return true;
}
});
args = args.slice(i);
// make the filename absolute
- let filename = args[0];
- if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
+ const filename = args[0];
+ if (!path.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
// add back on node and concat the sliced args
process.argv = ["node"].concat(args);
@@ -142,7 +141,7 @@ function replStart() {
input: process.stdin,
output: process.stdout,
eval: replEval,
- useGlobal: true
+ useGlobal: true,
});
}
diff --git a/packages/babel-cli/src/babel-node.js b/packages/babel-cli/src/babel-node.js
index 0830a2313d..3da22997f7 100755
--- a/packages/babel-cli/src/babel-node.js
+++ b/packages/babel-cli/src/babel-node.js
@@ -1,12 +1,10 @@
-/* eslint indent: 0 */
-
/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _babel-node(1) executable.
*/
-let getV8Flags = require("v8flags");
-let path = require("path");
+import getV8Flags from "v8flags";
+import path from "path";
let args = [path.join(__dirname, "_babel-node")];
@@ -14,9 +12,9 @@ let babelArgs = process.argv.slice(2);
let userArgs;
// separate node arguments from script arguments
-let argSeparator = babelArgs.indexOf("--");
+const argSeparator = babelArgs.indexOf("--");
if (argSeparator > -1) {
- userArgs = babelArgs.slice(argSeparator); // including the --
+ userArgs = babelArgs.slice(argSeparator); // including the --
babelArgs = babelArgs.slice(0, argSeparator);
}
@@ -75,13 +73,13 @@ getV8Flags(function (err, v8Flags) {
}
try {
- let kexec = require("kexec");
+ const kexec = require("kexec");
kexec(process.argv[0], args);
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
- let child_process = require("child_process");
- let proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
+ const child_process = require("child_process");
+ const proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function () {
if (signal) {
diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js
index 78be975c88..0316062590 100644
--- a/packages/babel-cli/src/babel/dir.js
+++ b/packages/babel-cli/src/babel/dir.js
@@ -1,26 +1,26 @@
-let outputFileSync = require("output-file-sync");
-let slash = require("slash");
-let path = require("path");
-let util = require("./util");
-let fs = require("fs");
-let _ = require("lodash");
+import outputFileSync from "output-file-sync";
+import slash from "slash";
+import path from "path";
+import fs from "fs";
-module.exports = function (commander, filenames) {
+import * as util from "./util";
+
+export default function (commander, filenames) {
function write(src, relative) {
// remove extension and then append back on .js
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
- let dest = path.join(commander.outDir, relative);
+ const dest = path.join(commander.outDir, relative);
- let data = util.compile(src, {
+ const data = util.compile(src, {
sourceFileName: slash(path.relative(dest + "/..", src)),
- sourceMapTarget: path.basename(relative)
+ sourceMapTarget: path.basename(relative),
});
if (!commander.copyFiles && data.ignored) return;
// we've requested explicit sourcemaps to be written to disk
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
- let mapLoc = dest + ".map";
+ const mapLoc = dest + ".map";
data.code = util.addSourceMappingUrl(data.code, mapLoc);
outputFileSync(mapLoc, JSON.stringify(data.map));
}
@@ -37,7 +37,7 @@ module.exports = function (commander, filenames) {
if (util.canCompile(filename, commander.extensions)) {
write(src, filename);
} else if (commander.copyFiles) {
- let dest = path.join(commander.outDir, filename);
+ const dest = path.join(commander.outDir, filename);
outputFileSync(dest, fs.readFileSync(src));
util.chmod(src, dest);
}
@@ -46,13 +46,13 @@ module.exports = function (commander, filenames) {
function handle(filename) {
if (!fs.existsSync(filename)) return;
- let stat = fs.statSync(filename);
+ const stat = fs.statSync(filename);
if (stat.isDirectory(filename)) {
- let dirname = filename;
+ const dirname = filename;
- _.each(util.readdir(dirname), function (filename) {
- let src = path.join(dirname, filename);
+ util.readdir(dirname).forEach(function (filename) {
+ const src = path.join(dirname, filename);
handleFile(src, filename);
});
} else {
@@ -61,21 +61,25 @@ module.exports = function (commander, filenames) {
}
if (!commander.skipInitialBuild) {
- _.each(filenames, handle);
+ filenames.forEach(handle);
}
if (commander.watch) {
- let chokidar = util.requireChokidar();
+ const chokidar = util.requireChokidar();
- _.each(filenames, function (dirname) {
- let watcher = chokidar.watch(dirname, {
+ filenames.forEach(function (dirname) {
+ const watcher = chokidar.watch(dirname, {
persistent: true,
- ignoreInitial: true
+ ignoreInitial: true,
+ awaitWriteFinish: {
+ stabilityThreshold: 50,
+ pollInterval: 10,
+ },
});
- _.each(["add", "change"], function (type) {
+ ["add", "change"].forEach(function (type) {
watcher.on(type, function (filename) {
- let relative = path.relative(dirname, filename) || filename;
+ const relative = path.relative(dirname, filename) || filename;
try {
handleFile(filename, relative);
} catch (err) {
@@ -85,4 +89,4 @@ module.exports = function (commander, filenames) {
});
});
}
-};
+}
diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js
index 1feb8d2aad..fb4b1f9a0c 100644
--- a/packages/babel-cli/src/babel/file.js
+++ b/packages/babel-cli/src/babel/file.js
@@ -1,33 +1,33 @@
-let convertSourceMap = require("convert-source-map");
-let sourceMap = require("source-map");
-let slash = require("slash");
-let path = require("path");
-let util = require("./util");
-let fs = require("fs");
-let _ = require("lodash");
+import convertSourceMap from "convert-source-map";
+import sourceMap from "source-map";
+import slash from "slash";
+import path from "path";
+import fs from "fs";
-module.exports = function (commander, filenames, opts) {
+import * as util from "./util";
+
+export default function (commander, filenames, opts) {
if (commander.sourceMaps === "inline") {
opts.sourceMaps = true;
}
let results = [];
- let buildResult = function () {
- let map = new sourceMap.SourceMapGenerator({
+ const buildResult = function () {
+ const map = new sourceMap.SourceMapGenerator({
file: path.basename(commander.outFile || "") || "stdout",
- sourceRoot: opts.sourceRoot
+ sourceRoot: opts.sourceRoot,
});
let code = "";
let offset = 0;
- _.each(results, function (result) {
+ results.forEach(function (result) {
code += result.code + "\n";
if (result.map) {
- let consumer = new sourceMap.SourceMapConsumer(result.map);
- let sources = new Set();
+ const consumer = new sourceMap.SourceMapConsumer(result.map);
+ const sources = new Set();
consumer.eachMapping(function (mapping) {
if (mapping.source != null) sources.add(mapping.source);
@@ -46,13 +46,13 @@ module.exports = function (commander, filenames, opts) {
});
sources.forEach((source) => {
- let content = consumer.sourceContentFor(source, true);
+ const content = consumer.sourceContentFor(source, true);
if (content !== null) {
map.setSourceContent(source, content);
}
});
- offset = code.split("\n").length;
+ offset = code.split("\n").length - 1;
}
});
@@ -64,17 +64,17 @@ module.exports = function (commander, filenames, opts) {
return {
map: map,
- code: code
+ code: code,
};
};
- let output = function () {
- let result = buildResult();
+ const output = function () {
+ const result = buildResult();
if (commander.outFile) {
// we've requested for a sourcemap to be written to disk
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
- let mapLoc = commander.outFile + ".map";
+ const mapLoc = commander.outFile + ".map";
result.code = util.addSourceMappingUrl(result.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
}
@@ -85,13 +85,13 @@ module.exports = function (commander, filenames, opts) {
}
};
- let stdin = function () {
+ const stdin = function () {
let code = "";
process.stdin.setEncoding("utf8");
process.stdin.on("readable", function () {
- let chunk = process.stdin.read();
+ const chunk = process.stdin.read();
if (chunk !== null) code += chunk;
});
@@ -103,18 +103,18 @@ module.exports = function (commander, filenames, opts) {
});
};
- let walk = function () {
- let _filenames = [];
+ const walk = function () {
+ const _filenames = [];
results = [];
- _.each(filenames, function (filename) {
+ filenames.forEach(function (filename) {
if (!fs.existsSync(filename)) return;
- let stat = fs.statSync(filename);
+ const stat = fs.statSync(filename);
if (stat.isDirectory()) {
- let dirname = filename;
+ const dirname = filename;
- _.each(util.readdirFilter(filename), function (filename) {
+ util.readdirFilter(filename).forEach(function (filename) {
_filenames.push(path.join(dirname, filename));
});
} else {
@@ -122,7 +122,7 @@ module.exports = function (commander, filenames, opts) {
}
});
- _.each(_filenames, function (filename) {
+ _filenames.forEach(function (filename) {
if (util.shouldIgnore(filename)) return;
let sourceFilename = filename;
@@ -131,7 +131,7 @@ module.exports = function (commander, filenames, opts) {
}
sourceFilename = slash(sourceFilename);
- let data = util.compile(filename, {
+ const data = util.compile(filename, {
sourceFileName: sourceFilename,
});
@@ -142,17 +142,21 @@ module.exports = function (commander, filenames, opts) {
output();
};
- let files = function () {
+ const files = function () {
if (!commander.skipInitialBuild) {
walk();
}
if (commander.watch) {
- let chokidar = util.requireChokidar();
+ const chokidar = util.requireChokidar();
chokidar.watch(filenames, {
persistent: true,
- ignoreInitial: true
+ ignoreInitial: true,
+ awaitWriteFinish: {
+ stabilityThreshold: 50,
+ pollInterval: 10,
+ },
}).on("all", function (type, filename) {
if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return;
@@ -173,4 +177,4 @@ module.exports = function (commander, filenames, opts) {
} else {
stdin();
}
-};
+}
diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js
index 236c2df72a..a96056b3dc 100755
--- a/packages/babel-cli/src/babel/index.js
+++ b/packages/babel-cli/src/babel/index.js
@@ -1,18 +1,19 @@
#!/usr/bin/env node
-/* eslint max-len: 0 */
-require("babel-core");
+import fs from "fs";
+import commander from "commander";
+import kebabCase from "lodash/kebabCase";
+import { options, util, version } from "babel-core";
+import uniq from "lodash/uniq";
+import glob from "glob";
-let fs = require("fs");
-let commander = require("commander");
-let kebabCase = require("lodash/kebabCase");
-let options = require("babel-core").options;
-let util = require("babel-core").util;
-let uniq = require("lodash/uniq");
-let each = require("lodash/each");
-let glob = require("glob");
+import dirCommand from "./dir";
+import fileCommand from "./file";
-each(options, function (option, key) {
+import pkg from "../../package.json";
+
+Object.keys(options).forEach(function (key) {
+ const option = options[key];
if (option.hidden) return;
let arg = kebabCase(key);
@@ -31,13 +32,14 @@ each(options, function (option, key) {
arg = "-" + option.shorthand + ", " + arg;
}
- let desc = [];
+ const desc = [];
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
if (option.description) desc.push(option.description);
commander.option(arg, desc.join(" "));
});
+/* eslint-disable max-len */
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
commander.option("-w, --watch", "Recompile files on changes");
commander.option("--skip-initial-build", "Do not compile files before watching");
@@ -45,9 +47,9 @@ commander.option("-o, --out-file [out]", "Compile all input files into a single
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
commander.option("-q, --quiet", "Don't log anything");
+/* eslint-enable max-len */
-let pkg = require("../../package.json");
-commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
+commander.version(pkg.version + " (babel-core " + version + ")");
commander.usage("[options] ");
commander.parse(process.argv);
@@ -59,7 +61,7 @@ if (commander.extensions) {
//
-let errors = [];
+const errors = [];
let filenames = commander.args.reduce(function (globbed, input) {
let files = glob.sync(input);
@@ -69,7 +71,7 @@ let filenames = commander.args.reduce(function (globbed, input) {
filenames = uniq(filenames);
-each(filenames, function (filename) {
+filenames.forEach(function (filename) {
if (!fs.existsSync(filename)) {
errors.push(filename + " doesn't exist");
}
@@ -104,9 +106,10 @@ if (errors.length) {
//
-let opts = exports.opts = {};
+export const opts = {};
-each(options, function (opt, key) {
+Object.keys(options).forEach(function (key) {
+ const opt = options[key];
if (commander[key] !== undefined && commander[key] !== opt.default) {
opts[key] = commander[key];
}
@@ -118,12 +121,5 @@ if (opts.only) {
opts.only = util.arrayify(opts.only, util.regexify);
}
-let fn;
-
-if (commander.outDir) {
- fn = require("./dir");
-} else {
- fn = require("./file");
-}
-
-fn(commander, filenames, exports.opts);
+const fn = commander.outDir ? dirCommand : fileCommand;
+fn(commander, filenames, opts);
diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js
index fd06aa6ce7..e92b09c671 100644
--- a/packages/babel-cli/src/babel/util.js
+++ b/packages/babel-cli/src/babel/util.js
@@ -1,11 +1,11 @@
-let commander = require("commander");
-let readdir = require("fs-readdir-recursive");
-let index = require("./index");
-let babel = require("babel-core");
-let util = require("babel-core").util;
-let path = require("path");
-let fs = require("fs");
-let _ = require("lodash");
+import commander from "commander";
+import defaults from "lodash/defaults";
+import readdir from "fs-readdir-recursive";
+import * as babel from "babel-core";
+import path from "path";
+import fs from "fs";
+
+import * as index from "./index";
export function chmod(src, dest) {
fs.chmodSync(dest, fs.statSync(src).mode);
@@ -13,16 +13,16 @@ export function chmod(src, dest) {
export function readdirFilter(filename) {
return readdir(filename).filter(function (filename) {
- return util.canCompile(filename);
+ return babel.util.canCompile(filename);
});
}
export { readdir };
-export let canCompile = util.canCompile;
+export const canCompile = babel.util.canCompile;
export function shouldIgnore(loc) {
- return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
+ return babel.util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
}
export function addSourceMappingUrl(code, loc) {
@@ -34,10 +34,10 @@ export function log(msg) {
}
export function transform(filename, code, opts) {
- opts = _.defaults(opts || {}, index.opts);
+ opts = defaults(opts || {}, index.opts);
opts.filename = filename;
- let result = babel.transform(code, opts);
+ const result = babel.transform(code, opts);
result.filename = filename;
result.actual = code;
return result;
@@ -45,7 +45,7 @@ export function transform(filename, code, opts) {
export function compile(filename, opts) {
try {
- let code = fs.readFileSync(filename, "utf8");
+ const code = fs.readFileSync(filename, "utf8");
return transform(filename, code, opts);
} catch (err) {
if (commander.watch) {
diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js
new file mode 100644
index 0000000000..13257ec5e8
--- /dev/null
+++ b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js
@@ -0,0 +1 @@
+console.log(process.argv[2]);
diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/options.json b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json
new file mode 100644
index 0000000000..5aa934d555
--- /dev/null
+++ b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json
@@ -0,0 +1,4 @@
+{
+ "args": ["bar", "foo"],
+ "stdout": "foo"
+}
diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js
index cd0326f68f..5ab4d85cee 100644
--- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js
+++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js
@@ -11,4 +11,4 @@ arr.map(function (x) {
return x * MULTIPLIER;
});
-//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7OztBQ0FOLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map
index 6dc6dd4027..cd5df70d02 100644
--- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map
+++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map
@@ -1 +1 @@
-{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,I;;;;;;ACAN,IAAI,GAAJ,CAAQ;AAAA,SAAK,IAAI,UAAT;AAAA,CAAR","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]}
+{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,I;;;;;ACAN,IAAI,GAAJ,CAAQ;AAAA,SAAK,IAAI,UAAT;AAAA,CAAR","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]}
diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js
index 61cb19aed9..c2bda15c4c 100644
--- a/packages/babel-cli/test/index.js
+++ b/packages/babel-cli/test/index.js
@@ -1,50 +1,53 @@
-let readdir = require("fs-readdir-recursive");
-let helper = require("babel-helper-fixtures");
-let assert = require("assert");
-let rimraf = require("rimraf");
-let outputFileSync = require("output-file-sync");
-let child = require("child_process");
-let path = require("path");
-let chai = require("chai");
-let fs = require("fs");
-let _ = require("lodash");
+const includes = require("lodash/includes");
+const readdir = require("fs-readdir-recursive");
+const helper = require("babel-helper-fixtures");
+const assert = require("assert");
+const rimraf = require("rimraf");
+const outputFileSync = require("output-file-sync");
+const child = require("child_process");
+const merge = require("lodash/merge");
+const path = require("path");
+const chai = require("chai");
+const fs = require("fs");
-let fixtureLoc = path.join(__dirname, "fixtures");
-let tmpLoc = path.join(__dirname, "tmp");
+const fixtureLoc = path.join(__dirname, "fixtures");
+const tmpLoc = path.join(__dirname, "tmp");
-let presetLocs = [
+const presetLocs = [
path.join(__dirname, "../../babel-preset-es2015"),
- path.join(__dirname, "../../babel-preset-react")
+ path.join(__dirname, "../../babel-preset-react"),
].join(",");
-let pluginLocs = [
+const pluginLocs = [
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
].join(",");
-let readDir = function (loc) {
- let files = {};
+const readDir = function (loc) {
+ const files = {};
if (fs.existsSync(loc)) {
- _.each(readdir(loc), function (filename) {
+ readdir(loc).forEach(function (filename) {
files[filename] = helper.readFile(path.join(loc, filename));
});
}
return files;
};
-let saveInFiles = function (files) {
- _.each(files, function (content, filename) {
+const saveInFiles = function (files) {
+ Object.keys(files).forEach(function (filename) {
+ const content = files[filename];
outputFileSync(filename, content);
});
};
-let assertTest = function (stdout, stderr, opts) {
- let expectStderr = opts.stderr.trim();
+const assertTest = function (stdout, stderr, opts) {
+ const expectStderr = opts.stderr.trim();
stderr = stderr.trim();
if (opts.stderr) {
if (opts.stderrContains) {
- assert.ok(_.includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
+ assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) +
+ " didn't contain " + JSON.stringify(expectStderr));
} else {
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
}
@@ -52,13 +55,14 @@ let assertTest = function (stdout, stderr, opts) {
throw new Error("stderr:\n" + stderr);
}
- let expectStdout = opts.stdout.trim();
+ const expectStdout = opts.stdout.trim();
stdout = stdout.trim();
stdout = stdout.replace(/\\/g, "/");
if (opts.stdout) {
if (opts.stdoutContains) {
- assert.ok(_.includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
+ assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) +
+ " didn't contain " + JSON.stringify(expectStdout));
} else {
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
}
@@ -66,14 +70,15 @@ let assertTest = function (stdout, stderr, opts) {
throw new Error("stdout:\n" + stdout);
}
- _.each(opts.outFiles, function (expect, filename) {
- let actual = helper.readFile(filename);
+ Object.keys(opts.outFiles, function (filename) {
+ const expect = opts.outFiles[filename];
+ const actual = helper.readFile(filename);
chai.expect(actual).to.equal(expect, "out-file " + filename);
});
};
-let buildTest = function (binName, testName, opts) {
- let binLoc = path.join(__dirname, "../lib", binName);
+const buildTest = function (binName, testName, opts) {
+ const binLoc = path.join(__dirname, "../lib", binName);
return function (callback) {
clear();
@@ -91,7 +96,7 @@ let buildTest = function (binName, testName, opts) {
args = args.concat(opts.args);
- let spawn = child.spawn(process.execPath, args);
+ const spawn = child.spawn(process.execPath, args);
let stderr = "";
let stdout = "";
@@ -127,32 +132,32 @@ let buildTest = function (binName, testName, opts) {
};
};
-let clear = function () {
+const clear = function () {
process.chdir(__dirname);
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc);
process.chdir(tmpLoc);
};
-_.each(fs.readdirSync(fixtureLoc), function (binName) {
+fs.readdirSync(fixtureLoc).forEach(function (binName) {
if (binName[0] === ".") return;
- let suiteLoc = path.join(fixtureLoc, binName);
+ const suiteLoc = path.join(fixtureLoc, binName);
describe("bin/" + binName, function () {
- _.each(fs.readdirSync(suiteLoc), function (testName) {
+ fs.readdirSync(suiteLoc).forEach(function (testName) {
if (testName[0] === ".") return;
- let testLoc = path.join(suiteLoc, testName);
+ const testLoc = path.join(suiteLoc, testName);
- let opts = {
- args: []
+ const opts = {
+ args: [],
};
- let optionsLoc = path.join(testLoc, "options.json");
- if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
+ const optionsLoc = path.join(testLoc, "options.json");
+ if (fs.existsSync(optionsLoc)) merge(opts, require(optionsLoc));
- _.each(["stdout", "stdin", "stderr"], function (key) {
- let loc = path.join(testLoc, key + ".txt");
+ ["stdout", "stdin", "stderr"].forEach(function (key) {
+ const loc = path.join(testLoc, key + ".txt");
if (fs.existsSync(loc)) {
opts[key] = helper.readFile(loc);
} else {
@@ -161,9 +166,9 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
});
opts.outFiles = readDir(path.join(testLoc, "out-files"));
- opts.inFiles = readDir(path.join(testLoc, "in-files"));
+ opts.inFiles = readDir(path.join(testLoc, "in-files"));
- let babelrcLoc = path.join(testLoc, ".babelrc");
+ const babelrcLoc = path.join(testLoc, ".babelrc");
if (fs.existsSync(babelrcLoc)) {
// copy .babelrc file to tmp directory
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
diff --git a/packages/babel-code-frame/README.md b/packages/babel-code-frame/README.md
index 0257a2da1f..7ef5368d31 100644
--- a/packages/babel-code-frame/README.md
+++ b/packages/babel-code-frame/README.md
@@ -35,9 +35,26 @@ If the column number is not known, you may pass `null` instead.
## Options
-name | type | default | description
------------------------|----------|-----------------|------------------------------------------------------
-highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals
-linesAbove | number | 2 | The number of lines to show above the error
-linesBelow | number | 3 | The number of lines to show below the error
-forceColor | boolean | `false` | Forcibly syntax highlight the code as JavaScript (for non-terminals); overrides highlightCode
+### `highlightCode`
+
+`boolean`, defaults to `false`.
+
+Toggles syntax highlighting the code as JavaScript for terminals.
+
+### `linesAbove`
+
+`number`, defaults to `2`.
+
+Adjust the number of lines to show above the error.
+
+### `linesBelow`
+
+`number`, defaults to `3`.
+
+Adjust the number of lines to show below the error.
+
+### `forceColor`
+
+`boolean`, defaults to `false`.
+
+Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.
diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json
index f480727283..d8ac4d99f0 100644
--- a/packages/babel-code-frame/package.json
+++ b/packages/babel-code-frame/package.json
@@ -1,6 +1,6 @@
{
"name": "babel-code-frame",
- "version": "6.20.0",
+ "version": "7.0.0-alpha.1",
"description": "Generate errors that contain a code frame that point to source locations.",
"author": "Sebastian McKenzie ",
"homepage": "https://babeljs.io/",
@@ -10,6 +10,6 @@
"dependencies": {
"chalk": "^1.1.0",
"esutils": "^2.0.2",
- "js-tokens": "^2.0.0"
+ "js-tokens": "^3.0.0"
}
}
diff --git a/packages/babel-code-frame/src/index.js b/packages/babel-code-frame/src/index.js
index 05637e9e40..5dbf1b8ada 100644
--- a/packages/babel-code-frame/src/index.js
+++ b/packages/babel-code-frame/src/index.js
@@ -1,4 +1,4 @@
-import jsTokens from "js-tokens";
+import jsTokens, { matchToToken } from "js-tokens";
import esutils from "esutils";
import Chalk from "chalk";
@@ -8,18 +8,18 @@ import Chalk from "chalk";
function getDefs(chalk) {
return {
- keyword: chalk.cyan,
+ keyword: chalk.cyan,
capitalized: chalk.yellow,
- jsx_tag: chalk.yellow,
- punctuator: chalk.yellow,
+ jsx_tag: chalk.yellow,
+ punctuator: chalk.yellow,
// bracket: intentionally omitted.
- number: chalk.magenta,
- string: chalk.green,
- regex: chalk.magenta,
- comment: chalk.grey,
- invalid: chalk.white.bgRed.bold,
- gutter: chalk.grey,
- marker: chalk.red.bold,
+ number: chalk.magenta,
+ string: chalk.green,
+ regex: chalk.magenta,
+ comment: chalk.grey,
+ invalid: chalk.white.bgRed.bold,
+ gutter: chalk.grey,
+ marker: chalk.red.bold,
};
}
@@ -46,8 +46,8 @@ const BRACKET = /^[()\[\]{}]$/;
*/
function getTokenType(match) {
- let [offset, text] = match.slice(-2);
- let token = jsTokens.matchToToken(match);
+ const [offset, text] = match.slice(-2);
+ const token = matchToToken(match);
if (token.type === "name") {
if (esutils.keyword.isReservedWordES6(token.value)) {
@@ -79,8 +79,8 @@ function getTokenType(match) {
function highlight(defs: Object, text: string) {
return text.replace(jsTokens, function (...args) {
- let type = getTokenType(args);
- let colorize = defs[type];
+ const type = getTokenType(args);
+ const colorize = defs[type];
if (colorize) {
return args[0].split(NEWLINE).map((str) => colorize(str)).join("\n");
} else {
@@ -101,51 +101,51 @@ export default function (
): string {
colNumber = Math.max(colNumber, 0);
- let highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor;
+ const highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor;
let chalk = Chalk;
if (opts.forceColor) {
chalk = new Chalk.constructor({ enabled: true });
}
- let maybeHighlight = (chalkFn, string) => {
+ const maybeHighlight = (chalkFn, string) => {
return highlighted ? chalkFn(string) : string;
};
- let defs = getDefs(chalk);
+ const defs = getDefs(chalk);
if (highlighted) rawLines = highlight(defs, rawLines);
- let linesAbove = opts.linesAbove || 2;
- let linesBelow = opts.linesBelow || 3;
+ const linesAbove = opts.linesAbove || 2;
+ const linesBelow = opts.linesBelow || 3;
- let lines = rawLines.split(NEWLINE);
+ const lines = rawLines.split(NEWLINE);
let start = Math.max(lineNumber - (linesAbove + 1), 0);
- let end = Math.min(lines.length, lineNumber + linesBelow);
+ let end = Math.min(lines.length, lineNumber + linesBelow);
if (!lineNumber && !colNumber) {
start = 0;
end = lines.length;
}
- let numberMaxWidth = String(end).length;
+ const numberMaxWidth = String(end).length;
- let frame = lines.slice(start, end).map((line, index) => {
- let number = start + 1 + index;
- let paddedNumber = ` ${number}`.slice(-numberMaxWidth);
- let gutter = ` ${paddedNumber} | `;
+ const frame = lines.slice(start, end).map((line, index) => {
+ const number = start + 1 + index;
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
+ const gutter = ` ${paddedNumber} | `;
if (number === lineNumber) {
let markerLine = "";
if (colNumber) {
- let markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
+ const markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
markerLine = [
"\n ",
maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")),
markerSpacing,
- maybeHighlight(defs.marker, "^")
+ maybeHighlight(defs.marker, "^"),
].join("");
}
return [
maybeHighlight(defs.marker, ">"),
maybeHighlight(defs.gutter, gutter),
line,
- markerLine
+ markerLine,
].join("");
} else {
return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
diff --git a/packages/babel-code-frame/test/index.js b/packages/babel-code-frame/test/index.js
index c85d59ddec..fa1455c496 100644
--- a/packages/babel-code-frame/test/index.js
+++ b/packages/babel-code-frame/test/index.js
@@ -1,6 +1,6 @@
-let assert = require("assert");
-let chalk = require("chalk");
-let codeFrame = require("..");
+import assert from "assert";
+import chalk from "chalk";
+import codeFrame from "..";
describe("babel-code-frame", function () {
it("basic usage", function () {
@@ -55,7 +55,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
- "}"
+ "}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2), [
" 5 | * @param b Number",
@@ -80,7 +80,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
- "}"
+ "}",
].join("\n");
assert.equal(codeFrame(rawLines, 6, 2), [
" 4 | * @param a Number",
@@ -109,7 +109,7 @@ describe("babel-code-frame", function () {
it("opts.highlightCode", function () {
const rawLines = "console.log('babel')";
- const result = codeFrame(rawLines, 1, 9, {highlightCode: true});
+ const result = codeFrame(rawLines, 1, 9, { highlightCode: true });
const stripped = chalk.stripColor(result);
assert.ok(result.length > stripped.length);
assert.equal(stripped, [
@@ -119,7 +119,7 @@ describe("babel-code-frame", function () {
});
it("opts.linesAbove", function () {
- let rawLines = [
+ const rawLines = [
"/**",
" * Sums two numbers.",
" *",
@@ -130,7 +130,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
- "}"
+ "}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1 }), [
" 6 | * @returns Number",
@@ -143,7 +143,7 @@ describe("babel-code-frame", function () {
});
it("opts.linesBelow", function () {
- let rawLines = [
+ const rawLines = [
"/**",
" * Sums two numbers.",
" *",
@@ -154,19 +154,19 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
- "}"
+ "}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesBelow: 1 }), [
" 5 | * @param b Number",
" 6 | * @returns Number",
"> 7 | */",
" | ^",
- " 8 | "
+ " 8 | ",
].join("\n"));
});
it("opts.linesAbove and opts.linesBelow", function () {
- let rawLines = [
+ const rawLines = [
"/**",
" * Sums two numbers.",
" *",
@@ -177,30 +177,32 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
- "}"
+ "}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1, linesBelow: 1 }), [
" 6 | * @returns Number",
"> 7 | */",
" | ^",
- " 8 | "
+ " 8 | ",
].join("\n"));
});
it("opts.forceColor", function() {
- let marker = chalk.red.bold;
- let gutter = chalk.grey;
+ const marker = chalk.red.bold;
+ const gutter = chalk.grey;
- let rawLines = [
+ const rawLines = [
+ "",
"",
"",
"",
- ""
].join("\n");
- assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }), chalk.reset([
- " " + gutter(" 2 | "),
- marker(">") + gutter(" 3 | "),
- " " + gutter(" 4 | ")
- ].join("\n")));
+ assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }),
+ chalk.reset([
+ " " + gutter(" 2 | "),
+ marker(">") + gutter(" 3 | "),
+ " " + gutter(" 4 | "),
+ ].join("\n"))
+ );
});
});
diff --git a/packages/babel-core/README.md b/packages/babel-core/README.md
index 3db09945ec..5b2f4d53d1 100644
--- a/packages/babel-core/README.md
+++ b/packages/babel-core/README.md
@@ -9,7 +9,9 @@ import { transform } from 'babel-core';
import * as babel from 'babel-core';
```
-## babel.transform(code: string, [options?](/docs/usage/api/#options): Object)
+All transformations will use your local configuration files (.babelrc or in package.json). See [options](#options) to disable it.
+
+## babel.transform(code: string, [options?](#options): Object)
Transforms the passed in `code`. Returning an object with the generated code,
source map, and AST.
@@ -27,7 +29,7 @@ result.map;
result.ast;
```
-## babel.transformFile(filename: string, [options?](/docs/usage/api/#options): Object, callback: Function)
+## babel.transformFile(filename: string, [options?](#options): Object, callback: Function)
Asynchronously transforms the entire contents of a file.
@@ -43,7 +45,7 @@ babel.transformFile("filename.js", options, function (err, result) {
});
```
-## babel.transformFileSync(filename: string, [options?](/docs/usage/api/#options): Object)
+## babel.transformFileSync(filename: string, [options?](#options): Object)
Synchronous version of `babel.transformFile`. Returns the transformed contents of
the `filename`.
@@ -58,7 +60,7 @@ babel.transformFileSync(filename, options) // => { code, map, ast }
babel.transformFileSync("filename.js", options).code;
```
-## babel.transformFromAst(ast: Object, code?: string, [options?](/docs/usage/api/#options): Object)
+## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object)
Given, an [AST](https://astexplorer.net/), transform it.
@@ -84,34 +86,36 @@ Following is a table of the options you can use:
| Option | Default | Description |
| ------------------------ | -------------------- | ------------------------------- |
+| `ast` | `true` | Include the AST in the returned object |
+| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code. |
+| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code. |
+| `babelrc` | `true` | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/usage/cli/#babel-ignoring-babelrc). |
+| `code` | `true` | Enable code generation |
+| `comments` | `true` | Output comments in generated output. |
+| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB. |
+| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the environment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` |
+| `extends` | `null` | A path to an `.babelrc` file to extend |
| `filename` | `"unknown"` | Filename for use in errors etc. |
| `filenameRelative` | `(filename)` | Filename relative to `sourceRoot`. |
-| `presets` | `[]` | List of [presets](/docs/plugins/#presets) (a set of plugins) to load and use. |
-| `plugins` | `[]` | List of [plugins](/docs/plugins/) to load and use. |
-| `parserOpts` | `{}` | An object containing the options to be passed down to the babel parser, babylon |
| `generatorOpts` | `{}` | An object containing the options to be passed down to the babel code generator, babel-generator |
-| `highlightCode` | `true` | ANSI highlight syntax error code frames |
-| `only` | `null` | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim. |
-| `ignore` | `null` | Opposite to the `only` option. `ignore` is disregarded if `only` is specified. |
-| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code. |
-| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code. |
-| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. |
-| `inputSourceMap` | `null` | A source map object that the output source map will be based on. |
-| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map. |
-| `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map. |
-| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative. |
-| `moduleRoot` | `(sourceRoot)` | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. |
-| `moduleIds` | `false` | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) |
-| `moduleId` | `null` | Specify a custom name for module ids. |
| `getModuleId` | `null` | Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used. |
-| `resolveModuleSource` | `null` | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)`. |
-| `code` | `true` | Enable code generation |
-| `no-babelrc` | [CLI flag](http://babeljs.io/docs/usage/cli/#ignoring-babelrc) | Specify whether or not to use .babelrc and .babelignore files. Only available when using the CLI. |
-| `ast` | `true` | Include the AST in the returned object |
-| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB. |
+| `highlightCode` | `true` | ANSI highlight syntax error code frames |
+| `ignore` | `null` | Opposite to the `only` option. `ignore` is disregarded if `only` is specified. |
+| `inputSourceMap` | `null` | A source map object that the output source map will be based on. |
| `minified` | `false` | Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe) |
-| `comments` | `true` | Output comments in generated output. |
-| `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used. |
-| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the enviroment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` |
+| `moduleId` | `null` | Specify a custom name for module ids. |
+| `moduleIds` | `false` | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) |
+| `moduleRoot` | `(sourceRoot)` | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. |
+| `only` | `null` | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim. |
+| `parserOpts` | `{}` | An object containing the options to be passed down to the babel parser, babylon |
+| `plugins` | `[]` | List of [plugins](/docs/plugins/) to load and use. |
+| `presets` | `[]` | List of [presets](/docs/plugins/#presets) (a set of plugins) to load and use. |
| `retainLines` | `false` | Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE:** This will not retain the columns) |
-| `extends` | `null` | A path to an `.babelrc` file to extend |
+| `resolveModuleSource` | `null` | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)`. |
+| `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used. |
+| `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map. |
+| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. |
+| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map. |
+| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative. |
+| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be either "script" or "module". |
+| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
diff --git a/packages/babel-core/index.js b/packages/babel-core/index.js
index e8f04775a2..07edf9757c 100644
--- a/packages/babel-core/index.js
+++ b/packages/babel-core/index.js
@@ -1 +1 @@
-module.exports = require("./lib/api/node.js");
+module.exports = require("./lib/index.js");
diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json
index cff80e6a2d..0c99b59385 100644
--- a/packages/babel-core/package.json
+++ b/packages/babel-core/package.json
@@ -1,6 +1,6 @@
{
"name": "babel-core",
- "version": "6.21.0",
+ "version": "7.0.0-alpha.2",
"description": "Babel compiler core.",
"author": "Sebastian McKenzie ",
"homepage": "https://babeljs.io/",
@@ -18,36 +18,36 @@
"transpile",
"transpiler",
"var",
- "babel-core"
+ "babel-core",
+ "compiler"
],
"scripts": {
"bench": "make bench",
"test": "make test"
},
"dependencies": {
- "babel-code-frame": "^6.20.0",
- "babel-generator": "^6.21.0",
- "babel-helpers": "^6.16.0",
- "babel-messages": "^6.8.0",
- "babel-template": "^6.16.0",
- "babel-runtime": "^6.20.0",
- "babel-register": "^6.18.0",
- "babel-traverse": "^6.21.0",
- "babel-types": "^6.21.0",
- "babylon": "^6.11.0",
+ "babel-code-frame": "7.0.0-alpha.1",
+ "babel-generator": "7.0.0-alpha.1",
+ "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.2",
+ "babel-traverse": "7.0.0-alpha.1",
+ "babel-types": "7.0.0-alpha.1",
+ "babylon": "7.0.0-beta.4",
"convert-source-map": "^1.1.0",
"debug": "^2.1.1",
"json5": "^0.5.0",
"lodash": "^4.2.0",
"minimatch": "^3.0.2",
- "path-is-absolute": "^1.0.0",
"private": "^0.1.6",
+ "resolve": "^1.3.2",
"slash": "^1.0.0",
"source-map": "^0.5.0"
},
"devDependencies": {
- "babel-helper-fixtures": "^6.20.0",
- "babel-helper-transform-fixture-test-runner": "^6.21.0",
- "babel-polyfill": "^6.20.0"
+ "babel-helper-fixtures": "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/register.js b/packages/babel-core/register.js
index 97d35f276e..2f32d9baaf 100644
--- a/packages/babel-core/register.js
+++ b/packages/babel-core/register.js
@@ -1,3 +1 @@
-/* eslint max-len: 0 */
-// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`");
-module.exports = require("babel-register");
+throw new Error("`babel-core/register` has been moved to `babel-register`.");
diff --git a/packages/babel-core/src/api/browser.js b/packages/babel-core/src/api/browser.js
deleted file mode 100644
index 1c53951acf..0000000000
--- a/packages/babel-core/src/api/browser.js
+++ /dev/null
@@ -1,112 +0,0 @@
-/* eslint max-len: 0 */
-/* eslint no-new-func: 0 */
-
-import { transform } from "./node";
-export {
- File,
- options,
- buildExternalHelpers,
- template,
- version,
- util,
- messages,
- types,
- traverse,
- OptionManager,
- Plugin,
- Pipeline,
- analyse,
- transform,
- transformFromAst,
- transformFile,
- transformFileSync
-} from "./node";
-
-export function run(code: string, opts: Object = {}): any {
- return new Function(transform(code, opts).code)();
-}
-
-export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
- opts.filename = opts.filename || url;
-
- let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
- xhr.open("GET", url, true);
- if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
-
- xhr.onreadystatechange = function () {
- if (xhr.readyState !== 4) return;
-
- let status = xhr.status;
- if (status === 0 || status === 200) {
- let param = [xhr.responseText, opts];
- if (!hold) run(param);
- if (callback) callback(param);
- } else {
- throw new Error(`Could not load ${url}`);
- }
- };
-
- xhr.send(null);
-}
-
-function runScripts() {
- let scripts: Array | Object> = [];
- let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
- let index = 0;
-
- /**
- * Transform and execute script. Ensures correct load order.
- */
-
- function exec() {
- let param = scripts[index];
- if (param instanceof Array) {
- run(param, index);
- index++;
- exec();
- }
- }
-
- /**
- * Load, transform, and execute all scripts.
- */
-
- function run(script: Object, i: number) {
- let opts = {};
-
- if (script.src) {
- load(script.src, function (param) {
- scripts[i] = param;
- exec();
- }, opts, true);
- } else {
- opts.filename = "embedded";
- scripts[i] = [script.innerHTML, opts];
- }
- }
-
- // Collect scripts with Babel `types`.
-
- let _scripts = global.document.getElementsByTagName("script");
-
- for (let i = 0; i < _scripts.length; ++i) {
- let _script = _scripts[i];
- if (types.indexOf(_script.type) >= 0) scripts.push(_script);
- }
-
- for (let i = 0; i < scripts.length; i++) {
- run(scripts[i], i);
- }
-
- exec();
-}
-
-/**
- * Register load event to transform and execute scripts.
- */
-
-if (global.addEventListener) {
- global.addEventListener("DOMContentLoaded", runScripts, false);
-} else if (global.attachEvent) {
- global.attachEvent("onload", runScripts);
-}
diff --git a/packages/babel-core/src/helpers/get-possible-plugin-names.js b/packages/babel-core/src/helpers/get-possible-plugin-names.js
new file mode 100644
index 0000000000..9aa95920a8
--- /dev/null
+++ b/packages/babel-core/src/helpers/get-possible-plugin-names.js
@@ -0,0 +1,3 @@
+export default function getPossiblePluginNames(pluginName: string): Array {
+ return [`babel-plugin-${pluginName}`, pluginName];
+}
diff --git a/packages/babel-core/src/helpers/get-possible-preset-names.js b/packages/babel-core/src/helpers/get-possible-preset-names.js
new file mode 100644
index 0000000000..a2140b9887
--- /dev/null
+++ b/packages/babel-core/src/helpers/get-possible-preset-names.js
@@ -0,0 +1,13 @@
+export default function getPossiblePresetNames(presetName: string): Array {
+ const possibleNames = [`babel-preset-${presetName}`, presetName];
+
+ // trying to resolve @organization shortcat
+ // @foo/es2015 -> @foo/babel-preset-es2015
+ const matches = presetName.match(/^(@[^/]+)\/(.+)$/);
+ if (matches) {
+ const [, orgName, presetPath] = matches;
+ possibleNames.push(`${orgName}/babel-preset-${presetPath}`);
+ }
+
+ return possibleNames;
+}
diff --git a/packages/babel-core/src/helpers/merge.js b/packages/babel-core/src/helpers/merge.js
index 5a695f6afa..1a01e22889 100644
--- a/packages/babel-core/src/helpers/merge.js
+++ b/packages/babel-core/src/helpers/merge.js
@@ -5,9 +5,9 @@ export default function (dest?: Object, src?: Object): ?Object {
return mergeWith(dest, src, function (a, b) {
if (b && Array.isArray(a)) {
- let newArray = b.slice(0);
+ const newArray = b.slice(0);
- for (let item of a) {
+ for (const item of a) {
if (newArray.indexOf(item) < 0) {
newArray.push(item);
}
diff --git a/packages/babel-core/src/helpers/resolve-from-possible-names.js b/packages/babel-core/src/helpers/resolve-from-possible-names.js
new file mode 100644
index 0000000000..e7a34adf01
--- /dev/null
+++ b/packages/babel-core/src/helpers/resolve-from-possible-names.js
@@ -0,0 +1,5 @@
+import resolve from "./resolve";
+
+export default function resolveFromPossibleNames(possibleNames: Array, dirname: string): ?string {
+ return possibleNames.reduce((accum, curr) => accum || resolve(curr, dirname), null);
+}
diff --git a/packages/babel-core/src/helpers/resolve-plugin.js b/packages/babel-core/src/helpers/resolve-plugin.js
new file mode 100644
index 0000000000..65aba0138b
--- /dev/null
+++ b/packages/babel-core/src/helpers/resolve-plugin.js
@@ -0,0 +1,6 @@
+import resolveFromPossibleNames from "./resolve-from-possible-names";
+import getPossiblePluginNames from "./get-possible-plugin-names";
+
+export default function resolvePlugin(pluginName: string, dirname: string = process.cwd()): ?string {
+ return resolveFromPossibleNames(getPossiblePluginNames(pluginName), dirname);
+}
diff --git a/packages/babel-core/src/helpers/resolve-preset.js b/packages/babel-core/src/helpers/resolve-preset.js
new file mode 100644
index 0000000000..417aaf9a01
--- /dev/null
+++ b/packages/babel-core/src/helpers/resolve-preset.js
@@ -0,0 +1,6 @@
+import resolveFromPossibleNames from "./resolve-from-possible-names";
+import getPossiblePresetNames from "./get-possible-preset-names";
+
+export default function resolvePreset(presetName: string, dirname: string = process.cwd()): ?string {
+ return resolveFromPossibleNames(getPossiblePresetNames(presetName), dirname);
+}
diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/helpers/resolve.js
index 623a910cbf..f0c6b27f81 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";
-
-let 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.
- let 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/api/node.js b/packages/babel-core/src/index.js
similarity index 58%
rename from packages/babel-core/src/api/node.js
rename to packages/babel-core/src/index.js
index 72492e95a5..1efc832d1f 100644
--- a/packages/babel-core/src/api/node.js
+++ b/packages/babel-core/src/index.js
@@ -1,13 +1,14 @@
-import isFunction from "lodash/isFunction";
import fs from "fs";
-export { default as File } from "../transformation/file";
-export { default as options } from "../transformation/file/options/config";
-export { default as buildExternalHelpers } from "../tools/build-external-helpers";
+export { default as File } from "./transformation/file";
+export { default as options } from "./transformation/file/options/config";
+export { default as buildExternalHelpers } from "./tools/build-external-helpers";
export { default as template } from "babel-template";
-export { version } from "../../package";
+export { default as resolvePlugin } from "./helpers/resolve-plugin";
+export { default as resolvePreset } from "./helpers/resolve-preset";
+export { version } from "../package";
-import * as util from "../util";
+import * as util from "./util";
export { util };
import * as messages from "babel-messages";
@@ -19,23 +20,18 @@ export { t as types };
import traverse from "babel-traverse";
export { traverse };
-import OptionManager from "../transformation/file/options/option-manager";
+import OptionManager from "./transformation/file/options/option-manager";
export { OptionManager };
export function Plugin(alias) {
throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`);
}
-import Pipeline from "../transformation/pipeline";
-export { Pipeline };
-
-let pipeline = new Pipeline;
-export let analyse = pipeline.analyse.bind(pipeline);
-export let transform = pipeline.transform.bind(pipeline);
-export let transformFromAst = pipeline.transformFromAst.bind(pipeline);
+import { transform, analyse, transformFromAst } from "./transformation/pipeline";
+export { transform, analyse, transformFromAst };
export function transformFile(filename: string, opts?: Object, callback: Function) {
- if (isFunction(opts)) {
+ if (typeof opts === "function") {
callback = opts;
opts = {};
}
diff --git a/packages/babel-core/src/store.js b/packages/babel-core/src/store.js
index fab3d10f34..7f2f4db6e2 100644
--- a/packages/babel-core/src/store.js
+++ b/packages/babel-core/src/store.js
@@ -1,22 +1,24 @@
-export default class Store extends Map {
+export default class Store {
constructor() {
- super();
- this.dynamicData = {};
+ this._map = new Map();
+ this._map.dynamicData = {};
}
- dynamicData: Object;
-
setDynamic(key, fn) {
- this.dynamicData[key] = fn;
+ this._map.dynamicData[key] = fn;
+ }
+
+ set(key: string, val) {
+ this._map.set(key, val);
}
get(key: string): any {
- if (this.has(key)) {
- return super.get(key);
+ if (this._map.has(key)) {
+ return this._map.get(key);
} else {
- if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) {
- let val = this.dynamicData[key]();
- this.set(key, val);
+ if (Object.prototype.hasOwnProperty.call(this._map.dynamicData, key)) {
+ const val = this._map.dynamicData[key]();
+ this._map.set(key, val);
return val;
}
}
diff --git a/packages/babel-core/src/tools/build-external-helpers.js b/packages/babel-core/src/tools/build-external-helpers.js
index a26febd34b..75a00f0fff 100644
--- a/packages/babel-core/src/tools/build-external-helpers.js
+++ b/packages/babel-core/src/tools/build-external-helpers.js
@@ -1,13 +1,10 @@
-/* eslint max-len: 0 */
-
import * as helpers from "babel-helpers";
import generator from "babel-generator";
import * as messages from "babel-messages";
import template from "babel-template";
-import each from "lodash/each";
import * as t from "babel-types";
-let buildUmdWrapper = template(`
+const buildUmdWrapper = template(`
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(AMD_ARGUMENTS, factory);
@@ -22,15 +19,17 @@ let buildUmdWrapper = template(`
`);
function buildGlobal(namespace, builder) {
- let body = [];
- let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
- let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
+ const body = [];
+ const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
+ const tree = t.program([
+ t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
- t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
- )
+ t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace),
+ t.objectExpression([]))
+ ),
]));
builder(body);
@@ -39,9 +38,9 @@ function buildGlobal(namespace, builder) {
}
function buildUmd(namespace, builder) {
- let body = [];
+ const body = [];
body.push(t.variableDeclaration("var", [
- t.variableDeclarator(namespace, t.identifier("global"))
+ t.variableDeclarator(namespace, t.identifier("global")),
]));
builder(body);
@@ -49,23 +48,23 @@ function buildUmd(namespace, builder) {
return t.program([
buildUmdWrapper({
FACTORY_PARAMETERS: t.identifier("global"),
- BROWSER_ARGUMENTS: t.assignmentExpression(
+ BROWSER_ARGUMENTS: t.assignmentExpression(
"=",
t.memberExpression(t.identifier("root"), namespace),
t.objectExpression([])
),
- COMMON_ARGUMENTS: t.identifier("exports"),
- AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
- FACTORY_BODY: body,
- UMD_ROOT: t.identifier("this")
- })
+ COMMON_ARGUMENTS: t.identifier("exports"),
+ AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
+ FACTORY_BODY: body,
+ UMD_ROOT: t.identifier("this"),
+ }),
]);
}
function buildVar(namespace, builder) {
- let body = [];
+ const body = [];
body.push(t.variableDeclaration("var", [
- t.variableDeclarator(namespace, t.objectExpression([]))
+ t.variableDeclarator(namespace, t.objectExpression([])),
]));
builder(body);
body.push(t.expressionStatement(namespace));
@@ -73,10 +72,10 @@ function buildVar(namespace, builder) {
}
function buildHelpers(body, namespace, whitelist) {
- each(helpers.list, function (name) {
+ helpers.list.forEach(function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
- let key = t.identifier(name);
+ const key = t.identifier(name);
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))
));
@@ -86,18 +85,18 @@ export default function (
whitelist?: Array,
outputType: "global" | "umd" | "var" = "global",
) {
- let namespace = t.identifier("babelHelpers");
+ const namespace = t.identifier("babelHelpers");
- let builder = function (body) {
+ const builder = function (body) {
return buildHelpers(body, namespace, whitelist);
};
let tree;
- let build = {
+ const build = {
global: buildGlobal,
- umd: buildUmd,
- var: buildVar,
+ umd: buildUmd,
+ var: buildVar,
}[outputType];
if (build) {
diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js
index 01d5b7efc9..f11e750303 100644
--- a/packages/babel-core/src/transformation/file/index.js
+++ b/packages/babel-core/src/transformation/file/index.js
@@ -1,11 +1,9 @@
/* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
-/* eslint max-len: 0 */
import getHelper from "babel-helpers";
import * as metadataVisitor from "./metadata";
import convertSourceMap from "convert-source-map";
import OptionManager from "./options/option-manager";
-import type Pipeline from "../pipeline";
import PluginPass from "../plugin-pass";
import { NodePath, Hub, Scope } from "babel-traverse";
import sourceMap from "source-map";
@@ -16,7 +14,7 @@ import traverse from "babel-traverse";
import Logger from "./logger";
import Store from "../../store";
import { parse } from "babylon";
-import * as util from "../../util";
+import * as util from "../../util";
import path from "path";
import * as t from "babel-types";
@@ -29,50 +27,48 @@ const shebangRegex = /^#!.*/;
const INTERNAL_PLUGINS = [
[blockHoistPlugin],
- [shadowFunctionsPlugin]
+ [shadowFunctionsPlugin],
];
-let errorVisitor = {
+const errorVisitor = {
enter(path, state) {
- let loc = path.node.loc;
+ const loc = path.node.loc;
if (loc) {
state.loc = loc;
path.stop();
}
- }
+ },
};
export default class File extends Store {
- constructor(opts: Object = {}, pipeline: Pipeline) {
+ constructor(opts: Object = {}) {
super();
- this.pipeline = pipeline;
+ this.log = new Logger(this, opts.filename || "unknown");
- 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,
+ sourceType: this.opts.sourceType,
sourceFileName: this.opts.filename,
- plugins: []
+ 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) => {
- let 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 = {
@@ -82,21 +78,21 @@ export default class File extends Store {
imports: [],
exports: {
exported: [],
- specifiers: []
- }
- }
+ specifiers: [],
+ },
+ },
};
this.dynamicImportTypes = {};
- this.dynamicImportIds = {};
- this.dynamicImports = [];
- this.declarations = {};
- this.usedHelpers = {};
+ this.dynamicImportIds = {};
+ this.dynamicImports = [];
+ this.declarations = {};
+ this.usedHelpers = {};
this.path = null;
- this.ast = {};
+ this.ast = {};
- this.code = "";
+ this.code = "";
this.shebang = "";
this.hub = new Hub(this);
@@ -104,9 +100,7 @@ export default class File extends Store {
static helpers: Array;
- pluginVisitors: Array