Compare commits
112 Commits
v7.0.0-bet
...
v7.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7c9264c79 | ||
|
|
c41eb0d052 | ||
|
|
de5ab72c49 | ||
|
|
607916880d | ||
|
|
8270903ba2 | ||
|
|
95fe785354 | ||
|
|
413aa79711 | ||
|
|
1a3a502f97 | ||
|
|
5761eb0bb4 | ||
|
|
a992d06c41 | ||
|
|
d8bbaaae0a | ||
|
|
9d9710c765 | ||
|
|
18b91a8388 | ||
|
|
0a2a37c31f | ||
|
|
d731acc351 | ||
|
|
fba19295b4 | ||
|
|
8fc8a1f2ee | ||
|
|
18c8d97c3d | ||
|
|
58962c35b5 | ||
|
|
881fc14329 | ||
|
|
7d8932b6be | ||
|
|
6330a152ce | ||
|
|
189c56628a | ||
|
|
8be488652f | ||
|
|
cdf420d4d8 | ||
|
|
cf62908bbd | ||
|
|
66ee192a7f | ||
|
|
c635ff9c32 | ||
|
|
6cb9d20a0a | ||
|
|
b5cb78d33a | ||
|
|
1d0a3d6772 | ||
|
|
18ea5aca51 | ||
|
|
db28c18458 | ||
|
|
a89171910f | ||
|
|
0056fb1cfb | ||
|
|
041dd4a536 | ||
|
|
428e294ded | ||
|
|
0a3c2a0c4c | ||
|
|
917e3ede31 | ||
|
|
6d820a2757 | ||
|
|
1ef7e0f48e | ||
|
|
9206df964d | ||
|
|
c583a04a55 | ||
|
|
edbf5d33dc | ||
|
|
8393a6d089 | ||
|
|
464df13c69 | ||
|
|
80b4b7120b | ||
|
|
ccd7c25174 | ||
|
|
4384d38b90 | ||
|
|
3fae022320 | ||
|
|
70361f1200 | ||
|
|
d72d567d43 | ||
|
|
4a455639e7 | ||
|
|
ba441c5ce4 | ||
|
|
7064b298d7 | ||
|
|
f3004d0d4d | ||
|
|
037b2025a6 | ||
|
|
7d534dc32c | ||
|
|
2b710d0387 | ||
|
|
e67cfc5b31 | ||
|
|
4552ee9962 | ||
|
|
3c64554716 | ||
|
|
cee9ae48e0 | ||
|
|
39dae28d5c | ||
|
|
16e898c692 | ||
|
|
bb89364813 | ||
|
|
57e2c45cbe | ||
|
|
63397d0aad | ||
|
|
48906604f2 | ||
|
|
0f2ab2fe20 | ||
|
|
de3597983a | ||
|
|
aa2d415507 | ||
|
|
4c584ae341 | ||
|
|
74439889d8 | ||
|
|
74ea70718e | ||
|
|
bbff566024 | ||
|
|
3942862a2a | ||
|
|
f3fd2ee3b2 | ||
|
|
6a19c2299a | ||
|
|
6371200215 | ||
|
|
47d5f0c20c | ||
|
|
262d7518bd | ||
|
|
287b485d0e | ||
|
|
9ae23639ad | ||
|
|
3c359698a7 | ||
|
|
056a995dd8 | ||
|
|
84fe8e4181 | ||
|
|
e44cef3473 | ||
|
|
44c2791849 | ||
|
|
0e88156d0c | ||
|
|
394ad93d22 | ||
|
|
82a4919c11 | ||
|
|
186f04a3e9 | ||
|
|
42c740ca0a | ||
|
|
7ae6e1e5a0 | ||
|
|
097ff40001 | ||
|
|
b79e3c0e99 | ||
|
|
88c1b4ef1c | ||
|
|
6b417a8ecb | ||
|
|
cd8a869a18 | ||
|
|
f3f005c67e | ||
|
|
7dfa79f4c8 | ||
|
|
3e34162092 | ||
|
|
b93800d3cb | ||
|
|
233e60c765 | ||
|
|
72a90cb63d | ||
|
|
b51ac5e60a | ||
|
|
8b206b2c3b | ||
|
|
a2ed843636 | ||
|
|
b95810f4b4 | ||
|
|
abb4850709 | ||
|
|
459e289d63 |
@@ -2,3 +2,4 @@
|
||||
packages/*/test/fixtures
|
||||
packages/*/lib
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
|
||||
@@ -32,7 +32,6 @@ function istanbulHacks() {
|
||||
|
||||
let envOpts = {
|
||||
loose: true,
|
||||
exclude: ["transform-typeof-symbol"],
|
||||
};
|
||||
|
||||
const config = {
|
||||
@@ -43,9 +42,9 @@ const config = {
|
||||
],
|
||||
plugins: [
|
||||
["@babel/proposal-class-properties", { loose: true }],
|
||||
"@babel/proposal-export-namespace",
|
||||
"@babel/proposal-export-namespace-from",
|
||||
"@babel/proposal-numeric-separator",
|
||||
["@babel/proposal-object-rest-spread", { useBuiltIns: true}],
|
||||
["@babel/proposal-object-rest-spread", { useBuiltIns: true }],
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -12,12 +12,10 @@ codemods/*/lib
|
||||
codemods/*/dist
|
||||
codemods/*/test/fixtures
|
||||
codemods/*/test/tmp
|
||||
experimental/*/lib
|
||||
experimental/*/node_modules
|
||||
experimental/*/test/fixtures
|
||||
experimental/*/test/tmp
|
||||
experimental/babel-preset-env/data
|
||||
experimental/babel-preset-env/test/debug-fixtures
|
||||
packages/babel-preset-env/data
|
||||
packages/babel-preset-env/test/debug-fixtures
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-standalone/babel.min.js
|
||||
packages/babylon/build
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
{
|
||||
"files": [
|
||||
"packages/*/src/**/*.js",
|
||||
"experimental/*/src/**/*.js",
|
||||
"codemods/*/src/**/*.js"
|
||||
],
|
||||
"rules": {
|
||||
@@ -23,7 +22,11 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [ "packages/*/test/**/*.js", "test/**/*.js" ],
|
||||
"files": [
|
||||
"packages/*/test/**/*.js",
|
||||
"codemods/*/test/**/*.js",
|
||||
"test/**/*.js"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
}
|
||||
|
||||
@@ -4,14 +4,11 @@
|
||||
.*/packages/.*/test
|
||||
.*/codemods/.*/lib
|
||||
.*/codemods/.*/test
|
||||
.*/experimental/.*/lib
|
||||
.*/experimental/.*/test
|
||||
.*/node_modules/conventional-changelog-core/
|
||||
|
||||
[include]
|
||||
packages/*/src
|
||||
codemods/*/src
|
||||
experimental/*/src
|
||||
|
||||
[libs]
|
||||
lib/file.js
|
||||
@@ -20,6 +17,7 @@ lib/types.js
|
||||
lib/third-party-libs.js.flow
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
|
||||
suppress_comment= \\(.\\|\n\\)*\\$FlowIssue
|
||||
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -34,6 +34,9 @@ package-lock.json
|
||||
/babel.sublime-workspace
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-standalone/babel.min.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
/codemods/*/lib
|
||||
/codemods/*/node_modules
|
||||
/packages/babylon/build
|
||||
.idea/
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
"trailingComma": "es5",
|
||||
"overrides": [{
|
||||
"files": [
|
||||
"**/experimental/*/src/**/*.js",
|
||||
"**/experimental/*/test/**/*.js",
|
||||
"**/codemods/*/src/**/*.js",
|
||||
"**/codemods/*/test/**/*.js",
|
||||
"**/packages/*/src/**/*.js",
|
||||
|
||||
@@ -24,7 +24,7 @@ contributing, please read the
|
||||
## Not sure where to start?
|
||||
|
||||
- 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/babel/tree/master/packages/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/babel/tree/master/packages/babylon#output).
|
||||
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babel/blob/master/packages/babylon/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babel/tree/master/packages/babylon#output).
|
||||
- Check out [`/doc`](https://github.com/babel/babel/tree/master/doc) for information about 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
|
||||
@@ -115,7 +115,7 @@ $ TEST_ONLY=babel-cli make test
|
||||
`TEST_ONLY` will also match substrings of the package name:
|
||||
|
||||
```sh
|
||||
# Run tests for the babel-plugin-transform-classes package.
|
||||
# Run tests for the @babel/plugin-transform-classes package.
|
||||
$ TEST_ONLY=es2015-class make test
|
||||
```
|
||||
|
||||
@@ -161,16 +161,16 @@ In case you're locally getting errors which are not on the CI, it may be due to
|
||||
|
||||
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`](https://github.com/babel/babel/tree/master/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](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": ["@babel/transform-exponentiation-operator"] }`.
|
||||
- For this test, we only need the relevant plugin, so it's just `{ "plugins": ["@babel/plugin-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)
|
||||
@@ -205,8 +205,8 @@ If you need to check for an error that is thrown you can add to the `options.jso
|
||||
```js
|
||||
// options.json example
|
||||
{
|
||||
"plugins": [["@babel/proposal-object-rest-spread", { "useBuiltIns": "invalidOption" }]],
|
||||
"throws": "@babel/proposal-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"
|
||||
"plugins": [["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": "invalidOption" }]],
|
||||
"throws": "@babel/plugin-proposal-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -231,9 +231,21 @@ descriptive name, and add the following:
|
||||
|
||||
* Add an `expected.json` file with the expected parser output. For added convenience, if there is no `expected.json` present, the test runner will generate one for you.
|
||||
|
||||
After writing tests for babylon, just build it by running:
|
||||
|
||||
```sh
|
||||
$ make build-babylon
|
||||
```
|
||||
|
||||
Then, to run the tests, use:
|
||||
|
||||
```sh
|
||||
$ TEST_ONLY=babylon make test-only
|
||||
```
|
||||
|
||||
#### 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.
|
||||
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.
|
||||
|
||||
```
|
||||
// Example
|
||||
@@ -267,7 +279,7 @@ To include the changes, we have to make sure to build Babel:
|
||||
$ make build
|
||||
```
|
||||
|
||||
Next, we need to execute `Generator.generate()`, which can be achieved by running a test case in the `babel-generator` package.
|
||||
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
|
||||
@@ -275,7 +287,6 @@ $ 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
|
||||
```
|
||||
@@ -299,7 +310,7 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe
|
||||
|
||||
## Internals
|
||||
- AST spec ([babylon/ast/spec.md](https://github.com/babel/babel/tree/master/packages/babylon/blob/master/ast/spec.md))
|
||||
- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.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))
|
||||
|
||||
156
Gulpfile.js
156
Gulpfile.js
@@ -3,9 +3,6 @@
|
||||
const plumber = require("gulp-plumber");
|
||||
const through = require("through2");
|
||||
const chalk = require("chalk");
|
||||
const pump = require("pump");
|
||||
const uglify = require("gulp-uglify");
|
||||
const rename = require("gulp-rename");
|
||||
const newer = require("gulp-newer");
|
||||
const babel = require("gulp-babel");
|
||||
const watch = require("gulp-watch");
|
||||
@@ -13,13 +10,12 @@ const gutil = require("gulp-util");
|
||||
const filter = require("gulp-filter");
|
||||
const gulp = require("gulp");
|
||||
const path = require("path");
|
||||
const merge = require("merge-stream");
|
||||
const RootMostResolvePlugin = require("webpack-dependency-suite")
|
||||
.RootMostResolvePlugin;
|
||||
const webpack = require("webpack");
|
||||
const webpackStream = require("webpack-stream");
|
||||
const merge = require("merge-stream");
|
||||
const registerStandalonePackageTask = require("./scripts/gulp-tasks")
|
||||
.registerStandalonePackageTask;
|
||||
|
||||
const sources = ["codemods", "packages", "experimental"];
|
||||
const sources = ["codemods", "packages"];
|
||||
|
||||
function swapSrcWithLib(srcPath) {
|
||||
const parts = srcPath.split(path.sep);
|
||||
@@ -81,114 +77,40 @@ gulp.task("watch", ["build"], function() {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task("build-babel-standalone", cb => {
|
||||
pump(
|
||||
[
|
||||
gulp.src(__dirname + "/packages/babel-standalone/src/index.js"),
|
||||
webpackBuild(),
|
||||
gulp.dest(__dirname + "/packages/babel-standalone"),
|
||||
uglify(),
|
||||
rename({ extname: ".min.js" }),
|
||||
gulp.dest(__dirname + "/packages/babel-standalone"),
|
||||
],
|
||||
cb
|
||||
);
|
||||
});
|
||||
registerStandalonePackageTask(
|
||||
gulp,
|
||||
"babel",
|
||||
"Babel",
|
||||
path.join(__dirname, "packages"),
|
||||
require("./packages/babel-core/package.json").version
|
||||
);
|
||||
|
||||
function webpackBuild() {
|
||||
let version = require("./packages/babel-core/package.json").version;
|
||||
const presetEnvWebpackPlugins = [
|
||||
new webpack.NormalModuleReplacementPlugin(
|
||||
/\.\/available-plugins/,
|
||||
require.resolve(
|
||||
path.join(
|
||||
__dirname,
|
||||
"./packages/babel-preset-env-standalone/src/available-plugins"
|
||||
)
|
||||
)
|
||||
),
|
||||
new webpack.NormalModuleReplacementPlugin(
|
||||
/caniuse-lite\/data\/regions\/.+/,
|
||||
require.resolve(
|
||||
path.join(
|
||||
__dirname,
|
||||
"./packages/babel-preset-env-standalone/src/caniuse-lite-regions"
|
||||
)
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
// If this build is part of a pull request, include the pull request number in
|
||||
// the version number.
|
||||
if (process.env.CIRCLE_PR_NUMBER) {
|
||||
version += "+pr." + process.env.CIRCLE_PR_NUMBER;
|
||||
}
|
||||
|
||||
const config = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: /node_modules/,
|
||||
loader: "babel-loader",
|
||||
options: {
|
||||
// Some of the node_modules may have their own "babel" section in
|
||||
// their project.json (or a ".babelrc" file). We need to ignore
|
||||
// those as we're using our own Babel options.
|
||||
babelrc: false,
|
||||
presets: [
|
||||
[
|
||||
"@babel/env",
|
||||
{
|
||||
loose: true,
|
||||
exclude: ["transform-typeof-symbol"],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: "babel-loader",
|
||||
options: {
|
||||
// Some of the node_modules may have their own "babel" section in
|
||||
// their project.json (or a ".babelrc" file). We need to ignore
|
||||
// those as we're using our own Babel options.
|
||||
babelrc: false,
|
||||
presets: [
|
||||
[
|
||||
"@babel/env",
|
||||
{
|
||||
loose: true,
|
||||
exclude: ["transform-typeof-symbol"],
|
||||
},
|
||||
],
|
||||
["@babel/stage-0", { loose: true }],
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
// babylon is already bundled and does not require parsing
|
||||
noParse: [/babylon\/lib/],
|
||||
},
|
||||
node: {
|
||||
// Mock Node.js modules that Babel require()s but that we don't
|
||||
// particularly care about.
|
||||
fs: "empty",
|
||||
module: "empty",
|
||||
net: "empty",
|
||||
},
|
||||
output: {
|
||||
filename: "babel.js",
|
||||
library: "Babel",
|
||||
libraryTarget: "umd",
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
"process.env.NODE_ENV": '"production"',
|
||||
BABEL_VERSION: JSON.stringify(version),
|
||||
VERSION: JSON.stringify(version),
|
||||
}),
|
||||
/*new webpack.NormalModuleReplacementPlugin(
|
||||
/..\/..\/package/,
|
||||
"../../../../src/babel-package-shim"
|
||||
),*/
|
||||
new webpack.optimize.ModuleConcatenationPlugin(),
|
||||
],
|
||||
resolve: {
|
||||
plugins: [
|
||||
// Dedupe packages that are used across multiple plugins.
|
||||
// This replaces DedupePlugin from Webpack 1.x
|
||||
new RootMostResolvePlugin(__dirname, true),
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
return webpackStream(config, webpack);
|
||||
// To write JSON for debugging:
|
||||
/*return webpackStream(config, webpack, (err, stats) => {
|
||||
require('gulp-util').log(stats.toString({colors: true}));
|
||||
require('fs').writeFileSync('webpack-debug.json', JSON.stringify(stats.toJson()));
|
||||
});*/
|
||||
}
|
||||
registerStandalonePackageTask(
|
||||
gulp,
|
||||
"babel-preset-env",
|
||||
"babelPresetEnv",
|
||||
path.join(__dirname, "packages"),
|
||||
require("./packages/babel-preset-env/package.json").version,
|
||||
presetEnvWebpackPlugins
|
||||
);
|
||||
|
||||
19
Makefile
19
Makefile
@@ -1,5 +1,5 @@
|
||||
MAKEFLAGS = -j1
|
||||
FLOW_COMMIT = 4cc2b9f7fadf2e9e445ee9b7b980c65d69d3fbc0
|
||||
FLOW_COMMIT = 0dfdb8bf984205f03e95b71680e39bae6b8f7066
|
||||
TEST262_COMMIT = 1282e842febf418ca27df13fa4b32f7e5021b470
|
||||
|
||||
export NODE_ENV = test
|
||||
@@ -7,7 +7,7 @@ export NODE_ENV = test
|
||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||
export FORCE_COLOR = true
|
||||
|
||||
SOURCES = packages codemods experimental
|
||||
SOURCES = packages codemods
|
||||
|
||||
.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap
|
||||
|
||||
@@ -16,8 +16,12 @@ build: clean
|
||||
# Build babylon before building all other projects
|
||||
make build-babylon
|
||||
./node_modules/.bin/gulp build
|
||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||
# call build again as the generated files might need to be compiled again.
|
||||
./node_modules/.bin/gulp build
|
||||
ifneq ("$(BABEL_ENV)", "cov")
|
||||
make build-standalone
|
||||
make build-preset-env-standalone
|
||||
endif
|
||||
|
||||
build-babylon:
|
||||
@@ -27,6 +31,9 @@ build-babylon:
|
||||
build-standalone:
|
||||
./node_modules/.bin/gulp build-babel-standalone
|
||||
|
||||
build-preset-env-standalone:
|
||||
./node_modules/.bin/gulp build-babel-preset-env-standalone
|
||||
|
||||
build-dist: build
|
||||
cd packages/babel-polyfill; \
|
||||
scripts/build-dist.sh
|
||||
@@ -38,6 +45,10 @@ watch: clean
|
||||
make clean-lib
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
||||
|
||||
watch-babylon:
|
||||
cd packages/babylon; \
|
||||
./node_modules/.bin/rollup -c -w
|
||||
|
||||
flow:
|
||||
./node_modules/.bin/flow check --strip-root
|
||||
|
||||
@@ -50,8 +61,6 @@ fix:
|
||||
clean: test-clean
|
||||
rm -rf packages/babel-polyfill/browser*
|
||||
rm -rf packages/babel-polyfill/dist
|
||||
# rm -rf packages/babel-runtime/helpers
|
||||
# rm -rf packages/babel-runtime/core-js
|
||||
rm -rf coverage
|
||||
rm -rf packages/*/npm-debug*
|
||||
|
||||
@@ -110,6 +119,8 @@ test-test262-update-whitelist:
|
||||
publish:
|
||||
git pull --rebase
|
||||
make clean-lib
|
||||
rm -rf packages/babel-runtime/helpers
|
||||
rm -rf packages/babel-runtime/core-js
|
||||
BABEL_ENV=production make build-dist
|
||||
make test
|
||||
# not using lerna independent mode atm, so only update packages that have changed since we use ^
|
||||
|
||||
16
README.md
16
README.md
@@ -24,9 +24,9 @@
|
||||
<a href="https://medium.com/friendship-dot-js/i-peeked-into-my-node-modules-directory-and-you-wont-believe-what-happened-next-b89f63d21558"><img alt="Business Strategy Status" src="https://img.shields.io/badge/business%20model-flavortown-green.svg"></a>
|
||||
</p>
|
||||
|
||||
Babel is community-driven and thus mostly maintained by a group of [volunteers](https://babeljs.io/team). It has a lot of [companies and projects](http://babeljs.io/users) using it but almost no sponsors/people funded to work on it. If you'd like to help maintain the future of the project, please consider:
|
||||
Babel is community-driven and thus mostly maintained by a group of [volunteers](https://babeljs.io/team). It has a lot of [companies and projects](https://babeljs.io/users) using it but almost no sponsors/people funded to work on it. If you'd like to help maintain the future of the project, please consider:
|
||||
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](slack.babeljs.io))
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/))
|
||||
- [Giving funds by becoming a backer/sponsor on OpenCollective](https://opencollective.com/babel)
|
||||
|
||||
## Intro
|
||||
@@ -63,19 +63,19 @@ Mostly a handful of volunteers! Please check out our [team page](https://babeljs
|
||||
|
||||
### Looking for support?
|
||||
|
||||
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/), ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs/).
|
||||
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||
|
||||
### Where are the docs?
|
||||
|
||||
Check out our website: [babeljs.io](http://babeljs.io/), and report issues/features at [babel/website](https://github.com/babel/website/issues).
|
||||
Check out our website: [babeljs.io](https://babeljs.io/), and report issues/features at [babel/website](https://github.com/babel/website/issues).
|
||||
|
||||
### Want to report a bug or request a feature?
|
||||
|
||||
Please read through our [CONTRIBUTING.md](https://github.com/babel/babel/blob/master/CONTRIBUTING.md) and fill out the issue template at [babel/issues](https://github.com/babel/babel/issues)!
|
||||
Please read through our [CONTRIBUTING.md](CONTRIBUTING.md) and fill out the issue template at [babel/issues](https://github.com/babel/babel/issues)!
|
||||
|
||||
### Want to contribute to Babel?
|
||||
|
||||
Check out our [CONTRIBUTING.md](https://github.com/babel/babel/blob/master/CONTRIBUTING.md) to get started with setting up the repo.
|
||||
Check out our [CONTRIBUTING.md](CONTRIBUTING.md) to get started with setting up the repo.
|
||||
|
||||
- If you have already joined Slack, join our [#development](https://babeljs.slack.com/messages/development) channel and say hi!
|
||||
- Check out the issues with the [good first issue](https://github.com/babel/babel/labels/good%20first%20issue) and [help wanted](https://github.com/babel/babel/labels/help%20wanted) label. We suggest also looking at the closed ones to get a sense of the kinds of issues you can tackle.
|
||||
@@ -84,7 +84,7 @@ Check out our [CONTRIBUTING.md](https://github.com/babel/babel/blob/master/CONTR
|
||||
|
||||
### How is the repo structured?
|
||||
|
||||
The Babel repo is managed as a [monorepo](https://github.com/babel/babel/blob/master/doc/design/monorepo.md) that is composed of many [npm packages](/packages#readme).
|
||||
The Babel repo is managed as a [monorepo](doc/design/monorepo.md) that is composed of many [npm packages](packages/README.md).
|
||||
|
||||
## Backers
|
||||
|
||||
@@ -158,4 +158,4 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/babel/babel/blob/master/LICENSE)
|
||||
[MIT](LICENSE)
|
||||
|
||||
@@ -2,6 +2,8 @@ general:
|
||||
artifacts:
|
||||
- "packages/babel-standalone/babel.js"
|
||||
- "packages/babel-standalone/babel.min.js"
|
||||
- "packages/babel-preset-env-standalone/babel-preset-env.js"
|
||||
- "packages/babel-preset-env-standalone/babel-preset-env.min.js"
|
||||
|
||||
machine:
|
||||
node:
|
||||
@@ -25,3 +27,4 @@ test:
|
||||
# data for a JS file that's several megabytes large is bound to fail. Here,
|
||||
# we just run the babel-standalone test separately.
|
||||
- ./node_modules/mocha/bin/_mocha packages/babel-standalone/test/ --opts test/mocha.opts
|
||||
- ./node_modules/mocha/bin/_mocha packages/babel-preset-env-standalone/test/ --opts test/mocha.opts
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"prettier/prettier": ["error", { "trailingComma": "all" }],
|
||||
"no-undefined-identifier": 2
|
||||
}
|
||||
}
|
||||
@@ -36,21 +36,21 @@ npm install --save-dev @babel/plugin-codemod-optional-catch-binding
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@babel/codemod-optional-catch-binding"]
|
||||
"plugins": ["@babel/plugin-codemod-optional-catch-binding"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins @babel/codemod-optional-catch-binding script.js
|
||||
babel --plugins @babel/plugin-codemod-optional-catch-binding script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["@babel/codemod-optional-catch-binding"]
|
||||
plugins: ["@babel/plugin-codemod-optional-catch-binding"]
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-optional-catch-binding",
|
||||
"version": "7.0.0-beta.32",
|
||||
"version": "7.0.0-beta.34",
|
||||
"description": "Remove unused catch bindings",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding",
|
||||
"license": "MIT",
|
||||
@@ -9,13 +9,13 @@
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.32"
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.34"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.32"
|
||||
"@babel/core": "7.0.0-beta.34"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.32",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.32"
|
||||
"@babel/core": "7.0.0-beta.34",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.34"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"prettier/prettier": ["error", { "trailingComma": "all" }],
|
||||
"no-undefined-identifier": 2
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
/lib
|
||||
debug-fixtures
|
||||
fixtures
|
||||
/data
|
||||
/flow-typed
|
||||
test/tmp
|
||||
@@ -1,63 +0,0 @@
|
||||
{
|
||||
"name": "@babel/preset-env",
|
||||
"version": "7.0.0-beta.32",
|
||||
"description": "A Babel preset for each environment.",
|
||||
"author": "Henry Zhu <hi@henryzoo.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/babel/babel/tree/master/experimental/babel-preset-env",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build-data": "node ./scripts/build-data.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-check-constants": "7.0.0-beta.32",
|
||||
"@babel/plugin-proposal-async-generator-functions": "7.0.0-beta.32",
|
||||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.32",
|
||||
"@babel/plugin-proposal-optional-catch-binding": "7.0.0-beta.32",
|
||||
"@babel/plugin-proposal-unicode-property-regex": "7.0.0-beta.32",
|
||||
"@babel/plugin-syntax-async-generators": "7.0.0-beta.32",
|
||||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.32",
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-arrow-functions": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-async-to-generator": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-block-scoped-functions": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-block-scoping": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-classes": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-computed-properties": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-destructuring": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-duplicate-keys": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-exponentiation-operator": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-for-of": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-function-name": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-literals": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-modules-amd": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-modules-systemjs": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-modules-umd": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-new-target": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-object-super": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-parameters": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-regenerator": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-shorthand-properties": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-spread": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-sticky-regex": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-template-literals": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-typeof-symbol": "7.0.0-beta.32",
|
||||
"@babel/plugin-transform-unicode-regex": "7.0.0-beta.32",
|
||||
"browserslist": "^2.4.0",
|
||||
"invariant": "^2.2.2",
|
||||
"semver": "^5.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.32"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.0.0-beta.32",
|
||||
"@babel/core": "7.0.0-beta.32",
|
||||
"@babel/helper-fixtures": "7.0.0-beta.32",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.32",
|
||||
"compat-table": "kangax/compat-table#957f1ff15972e8fb2892a172f985e9af27bf1c75",
|
||||
"electron-to-chromium": "^1.3.27"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"prettier/prettier": ["error", { "trailingComma": "es5" }]
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"max-len": 0
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _a = _interopRequireDefault(require("a"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
@@ -1 +0,0 @@
|
||||
import a from "a";
|
||||
22
lerna.json
22
lerna.json
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"lerna": "2.0.0-rc.4",
|
||||
"version": "7.0.0-beta.32",
|
||||
"version": "7.0.0-beta.34",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"labels": {
|
||||
"Tag: Spec Compliancy": ":eyeglasses: Spec Compliancy",
|
||||
"Tag: Breaking Change": ":boom: Breaking Change",
|
||||
"Tag: New Feature": ":rocket: New Feature",
|
||||
"Tag: Bug Fix": ":bug: Bug Fix",
|
||||
"Tag: Polish": ":nail_care: Polish",
|
||||
"Tag: Docs": ":memo: Documentation",
|
||||
"Tag: Internal": ":house: Internal"
|
||||
"PR: Spec Compliancy": ":eyeglasses: Spec Compliancy",
|
||||
"PR: Breaking Change": ":boom: Breaking Change",
|
||||
"PR: New Feature": ":rocket: New Feature",
|
||||
"PR: Bug Fix": ":bug: Bug Fix",
|
||||
"PR: Polish": ":nail_care: Polish",
|
||||
"PR: Docs": ":memo: Documentation",
|
||||
"PR: Internal": ":house: Internal"
|
||||
}
|
||||
},
|
||||
"cacheDir": ".changelog",
|
||||
@@ -19,15 +19,13 @@
|
||||
"ignore": [
|
||||
"*.md",
|
||||
"test/**",
|
||||
"codemods/**",
|
||||
"experimental/**"
|
||||
"codemods/**"
|
||||
]
|
||||
}
|
||||
},
|
||||
"packages": [
|
||||
"packages/*",
|
||||
"codemods/*",
|
||||
"experimental/*"
|
||||
"codemods/*"
|
||||
],
|
||||
"npmClient": "yarn",
|
||||
"npmClientArgs": [
|
||||
|
||||
37
lib/types.js
37
lib/types.js
@@ -352,7 +352,7 @@ declare class BabelNodeWhileStatement extends BabelNode {
|
||||
|
||||
declare class BabelNodeWithStatement extends BabelNode {
|
||||
type: "WithStatement";
|
||||
object: any;
|
||||
object: BabelNodeExpression;
|
||||
body: BabelNodeBlockStatement | BabelNodeStatement;
|
||||
}
|
||||
|
||||
@@ -800,7 +800,7 @@ declare class BabelNodeVoidTypeAnnotation extends BabelNode {
|
||||
declare class BabelNodeJSXAttribute extends BabelNode {
|
||||
type: "JSXAttribute";
|
||||
name: BabelNodeJSXIdentifier | BabelNodeJSXNamespacedName;
|
||||
value?: ?BabelNodeJSXElement | BabelNodeStringLiteral | BabelNodeJSXExpressionContainer;
|
||||
value?: ?BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeStringLiteral | BabelNodeJSXExpressionContainer;
|
||||
}
|
||||
|
||||
declare class BabelNodeJSXClosingElement extends BabelNode {
|
||||
@@ -864,6 +864,21 @@ declare class BabelNodeJSXText extends BabelNode {
|
||||
value: string;
|
||||
}
|
||||
|
||||
declare class BabelNodeJSXFragment extends BabelNode {
|
||||
type: "JSXFragment";
|
||||
openingFragment: BabelNodeJSXOpeningFragment;
|
||||
closingFragment: BabelNodeJSXClosingFragment;
|
||||
children: any;
|
||||
}
|
||||
|
||||
declare class BabelNodeJSXOpeningFragment extends BabelNode {
|
||||
type: "JSXOpeningFragment";
|
||||
}
|
||||
|
||||
declare class BabelNodeJSXClosingFragment extends BabelNode {
|
||||
type: "JSXClosingFragment";
|
||||
}
|
||||
|
||||
declare class BabelNodeNoop extends BabelNode {
|
||||
type: "Noop";
|
||||
}
|
||||
@@ -1247,7 +1262,7 @@ declare class BabelNodeTSTypeParameter extends BabelNode {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeParenthesizedExpression | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression;
|
||||
type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXFragment | BabelNodeParenthesizedExpression | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression;
|
||||
type BabelNodeBinary = BabelNodeBinaryExpression | BabelNodeLogicalExpression;
|
||||
type BabelNodeScopable = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeClassDeclaration | BabelNodeClassExpression | BabelNodeForOfStatement | BabelNodeClassMethod;
|
||||
type BabelNodeBlockParent = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeForOfStatement | BabelNodeClassMethod;
|
||||
@@ -1269,7 +1284,7 @@ type BabelNodePatternLike = BabelNodeIdentifier | BabelNodeRestElement | BabelNo
|
||||
type BabelNodeLVal = BabelNodeIdentifier | BabelNodeMemberExpression | BabelNodeRestElement | BabelNodeAssignmentPattern | BabelNodeArrayPattern | BabelNodeObjectPattern | BabelNodeTSParameterProperty;
|
||||
type BabelNodeTSEntityName = BabelNodeIdentifier | BabelNodeTSQualifiedName;
|
||||
type BabelNodeLiteral = BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeTemplateLiteral;
|
||||
type BabelNodeImmutable = BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXExpressionContainer | BabelNodeJSXSpreadChild | BabelNodeJSXOpeningElement | BabelNodeJSXText;
|
||||
type BabelNodeImmutable = BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXExpressionContainer | BabelNodeJSXSpreadChild | BabelNodeJSXOpeningElement | BabelNodeJSXText | BabelNodeJSXFragment | BabelNodeJSXOpeningFragment | BabelNodeJSXClosingFragment;
|
||||
type BabelNodeUserWhitespacable = BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeObjectTypeSpreadProperty;
|
||||
type BabelNodeMethod = BabelNodeObjectMethod | BabelNodeClassMethod;
|
||||
type BabelNodeObjectMember = BabelNodeObjectMethod | BabelNodeObjectProperty;
|
||||
@@ -1284,7 +1299,7 @@ type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation |
|
||||
type BabelNodeFlowBaseAnnotation = BabelNodeAnyTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeEmptyTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeVoidTypeAnnotation;
|
||||
type BabelNodeFlowDeclaration = BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareOpaqueType | BabelNodeDeclareVariable | BabelNodeDeclareExportDeclaration | BabelNodeDeclareExportAllDeclaration | BabelNodeInterfaceDeclaration | BabelNodeOpaqueType | BabelNodeTypeAlias;
|
||||
type BabelNodeFlowPredicate = BabelNodeDeclaredPredicate | BabelNodeInferredPredicate;
|
||||
type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXSpreadChild | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText;
|
||||
type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXSpreadChild | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText | BabelNodeJSXFragment | BabelNodeJSXOpeningFragment | BabelNodeJSXClosingFragment;
|
||||
type BabelNodeTSTypeElement = BabelNodeTSCallSignatureDeclaration | BabelNodeTSConstructSignatureDeclaration | BabelNodeTSPropertySignature | BabelNodeTSMethodSignature | BabelNodeTSIndexSignature;
|
||||
type BabelNodeTSType = BabelNodeTSAnyKeyword | BabelNodeTSNumberKeyword | BabelNodeTSObjectKeyword | BabelNodeTSBooleanKeyword | BabelNodeTSStringKeyword | BabelNodeTSSymbolKeyword | BabelNodeTSVoidKeyword | BabelNodeTSUndefinedKeyword | BabelNodeTSNullKeyword | BabelNodeTSNeverKeyword | BabelNodeTSThisType | BabelNodeTSFunctionType | BabelNodeTSConstructorType | BabelNodeTSTypeReference | BabelNodeTSTypePredicate | BabelNodeTSTypeQuery | BabelNodeTSTypeLiteral | BabelNodeTSArrayType | BabelNodeTSTupleType | BabelNodeTSUnionType | BabelNodeTSIntersectionType | BabelNodeTSParenthesizedType | BabelNodeTSTypeOperator | BabelNodeTSIndexedAccessType | BabelNodeTSMappedType | BabelNodeTSLiteralType | BabelNodeTSExpressionWithTypeArguments;
|
||||
|
||||
@@ -1337,7 +1352,7 @@ declare module "@babel/types" {
|
||||
declare function variableDeclaration(kind: any, declarations: any, declare?: boolean): BabelNodeVariableDeclaration;
|
||||
declare function variableDeclarator(id: BabelNodeLVal, init?: ?BabelNodeExpression): BabelNodeVariableDeclarator;
|
||||
declare function whileStatement(test: BabelNodeExpression, body: BabelNodeBlockStatement | BabelNodeStatement): BabelNodeWhileStatement;
|
||||
declare function withStatement(object: any, body: BabelNodeBlockStatement | BabelNodeStatement): BabelNodeWithStatement;
|
||||
declare function withStatement(object: BabelNodeExpression, body: BabelNodeBlockStatement | BabelNodeStatement): BabelNodeWithStatement;
|
||||
declare function assignmentPattern(left: BabelNodeIdentifier | BabelNodeObjectPattern | BabelNodeArrayPattern, right: BabelNodeExpression, decorators?: any, typeAnnotation?: ?BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop): BabelNodeAssignmentPattern;
|
||||
declare function arrayPattern(elements: any, decorators?: any, typeAnnotation?: ?BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop): BabelNodeArrayPattern;
|
||||
declare function arrowFunctionExpression(params: any, body: BabelNodeBlockStatement | BabelNodeExpression, async?: boolean, expression?: boolean, generator?: boolean, returnType?: ?BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop, typeParameters?: ?BabelNodeTypeParameterDeclaration | BabelNodeNoop): BabelNodeArrowFunctionExpression;
|
||||
@@ -1411,7 +1426,7 @@ declare module "@babel/types" {
|
||||
declare function typeParameterInstantiation(params: any): BabelNodeTypeParameterInstantiation;
|
||||
declare function unionTypeAnnotation(types: any): BabelNodeUnionTypeAnnotation;
|
||||
declare function voidTypeAnnotation(): BabelNodeVoidTypeAnnotation;
|
||||
declare function jSXAttribute(name: BabelNodeJSXIdentifier | BabelNodeJSXNamespacedName, value?: ?BabelNodeJSXElement | BabelNodeStringLiteral | BabelNodeJSXExpressionContainer): BabelNodeJSXAttribute;
|
||||
declare function jSXAttribute(name: BabelNodeJSXIdentifier | BabelNodeJSXNamespacedName, value?: ?BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeStringLiteral | BabelNodeJSXExpressionContainer): BabelNodeJSXAttribute;
|
||||
declare function jSXClosingElement(name: BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression): BabelNodeJSXClosingElement;
|
||||
declare function jSXElement(openingElement: BabelNodeJSXOpeningElement, closingElement?: ?BabelNodeJSXClosingElement, children: any, selfClosing: any): BabelNodeJSXElement;
|
||||
declare function jSXEmptyExpression(): BabelNodeJSXEmptyExpression;
|
||||
@@ -1423,6 +1438,9 @@ declare module "@babel/types" {
|
||||
declare function jSXOpeningElement(name: BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression, attributes: any, selfClosing?: boolean): BabelNodeJSXOpeningElement;
|
||||
declare function jSXSpreadAttribute(argument: BabelNodeExpression): BabelNodeJSXSpreadAttribute;
|
||||
declare function jSXText(value: string): BabelNodeJSXText;
|
||||
declare function jSXFragment(openingFragment: BabelNodeJSXOpeningFragment, closingFragment: BabelNodeJSXClosingFragment, children: any): BabelNodeJSXFragment;
|
||||
declare function jSXOpeningFragment(): BabelNodeJSXOpeningFragment;
|
||||
declare function jSXClosingFragment(): BabelNodeJSXClosingFragment;
|
||||
declare function noop(): BabelNodeNoop;
|
||||
declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression;
|
||||
declare function awaitExpression(argument: BabelNodeExpression): BabelNodeAwaitExpression;
|
||||
@@ -1621,6 +1639,9 @@ declare module "@babel/types" {
|
||||
declare function isJSXOpeningElement(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXOpeningElement)
|
||||
declare function isJSXSpreadAttribute(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXSpreadAttribute)
|
||||
declare function isJSXText(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXText)
|
||||
declare function isJSXFragment(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXFragment)
|
||||
declare function isJSXOpeningFragment(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXOpeningFragment)
|
||||
declare function isJSXClosingFragment(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXClosingFragment)
|
||||
declare function isNoop(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeNoop)
|
||||
declare function isParenthesizedExpression(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeParenthesizedExpression)
|
||||
declare function isAwaitExpression(node: Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeAwaitExpression)
|
||||
@@ -1727,6 +1748,8 @@ declare module "@babel/types" {
|
||||
declare function isTSType(node: Object, opts?: ?Object): boolean
|
||||
declare function isNumberLiteral(node: Object, opts?: ?Object): boolean
|
||||
declare function isRegexLiteral(node: Object, opts?: ?Object): boolean
|
||||
declare function isRestProperty(node: Object, opts?: ?Object): boolean
|
||||
declare function isSpreadProperty(node: Object, opts?: ?Object): boolean
|
||||
declare function validate(n: BabelNode, key: string, value: mixed): void;
|
||||
declare function clone<T>(n: T): T;
|
||||
declare function cloneDeep<T>(n: T): T;
|
||||
|
||||
20
package.json
20
package.json
@@ -10,17 +10,18 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.0.0-beta.5",
|
||||
"@babel/core": "7.0.0-beta.5",
|
||||
"@babel/preset-env": "7.0.0-beta.5",
|
||||
"@babel/preset-flow": "7.0.0-beta.5",
|
||||
"@babel/preset-stage-0": "7.0.0-beta.5",
|
||||
"@babel/register": "7.0.0-beta.5",
|
||||
"@babel/cli": "7.0.0-beta.33",
|
||||
"@babel/core": "7.0.0-beta.33",
|
||||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.33",
|
||||
"@babel/preset-env": "7.0.0-beta.33",
|
||||
"@babel/preset-flow": "7.0.0-beta.33",
|
||||
"@babel/preset-stage-0": "7.0.0-beta.33",
|
||||
"@babel/register": "7.0.0-beta.33",
|
||||
"async": "^1.5.0",
|
||||
"babel-eslint": "^8.0.1",
|
||||
"babel-loader": "8.0.0-beta.0",
|
||||
"babel-plugin-istanbul": "^4.1.4",
|
||||
"babylon": "7.0.0-beta.30",
|
||||
"babylon": "7.0.0-beta.33",
|
||||
"browserify": "^13.1.1",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chai": "^4.1.0",
|
||||
@@ -30,7 +31,7 @@
|
||||
"eslint-config-babel": "^7.0.2",
|
||||
"eslint-plugin-flowtype": "^2.20.0",
|
||||
"eslint-plugin-prettier": "^2.2.0",
|
||||
"flow-bin": "^0.57.3",
|
||||
"flow-bin": "^0.59.0",
|
||||
"graceful-fs": "^4.1.11",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^8.0.0-beta.0",
|
||||
@@ -72,8 +73,7 @@
|
||||
"scripts/*.js",
|
||||
"packages/*/test/**",
|
||||
"packages/babel-standalone/**",
|
||||
"codemods/*/test/**",
|
||||
"experimental/*/test/**"
|
||||
"codemods/*/test/**"
|
||||
],
|
||||
"sourceMap": false,
|
||||
"instrument": false
|
||||
|
||||
@@ -45,7 +45,7 @@ Check out the [`babel-handbook`](https://github.com/thejameskyle/babel-handbook/
|
||||
| [`@babel/helpers`](/packages/babel-helpers) | [](https://www.npmjs.com/package/babel-helpers) | [](https://david-dm.org/babel/babel?path=packages/babel-helpers) |
|
||||
| [`@babel/code-frame`](/packages/babel-code-frame) | [](https://www.npmjs.com/package/babel-code-frame) | [](https://david-dm.org/babel/babel?path=packages/babel-code-frame) |
|
||||
|
||||
- [`@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/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` cli). Check out the [docs](https://babeljs.io/docs/usage/cli/).
|
||||
- [`@babel/types`](/packages/babel-types) is used to validate, build and 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/).
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
In addition, various entry point scripts live in the top-level package at `@babel/cli/bin`.
|
||||
|
||||
There are some shell-executable utility scripts, `babel-external-helpers.js` and `babel-node.js`, and the main Babel cli script, `babel.js`.
|
||||
There is a shell-executable utility script, `babel-external-helpers.js`, and the main Babel cli script, `babel.js`.
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/cli",
|
||||
"version": "7.0.0-beta.32",
|
||||
"version": "7.0.0-beta.34",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -29,11 +29,11 @@
|
||||
"chokidar": "^1.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.32"
|
||||
"@babel/core": "7.0.0-beta.34"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.32",
|
||||
"@babel/helper-fixtures": "7.0.0-beta.32"
|
||||
"@babel/core": "7.0.0-beta.34",
|
||||
"@babel/helper-fixtures": "7.0.0-beta.34"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel.js",
|
||||
|
||||
@@ -49,6 +49,11 @@ commander.option(
|
||||
collect,
|
||||
);
|
||||
commander.option("--config-file [path]", "Path a to .babelrc file to use");
|
||||
commander.option(
|
||||
"--env-name [name]",
|
||||
"The name of the 'env' to use when loading configs and plugins. " +
|
||||
"Defaults to the value of BABEL_ENV, or else NODE_ENV, or else 'development'.",
|
||||
);
|
||||
|
||||
// Basic file input configuration.
|
||||
commander.option("--source-type [script|module]", "");
|
||||
|
||||
@@ -1 +1 @@
|
||||
SyntaxError: test.js: Unexpected token, expected ; (2:10)
|
||||
SyntaxError: test.js: Unexpected token, expected ";" (2:10)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/code-frame",
|
||||
"version": "7.0.0-beta.32",
|
||||
"version": "7.0.0-beta.34",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
@@ -144,10 +144,11 @@ Following is a table of the options you can use:
|
||||
| `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) |
|
||||
| `envName` | env vars | Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"` |
|
||||
| `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"` |
|
||||
| `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 `envName` is `production` |
|
||||
| `extends` | `null` | A path to a `.babelrc` file to extend |
|
||||
| `filename` | `"unknown"` | Filename for use in errors etc |
|
||||
| `filenameRelative` | `(filename)` | Filename relative to `sourceRoot` |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/core",
|
||||
"version": "7.0.0-beta.32",
|
||||
"version": "7.0.0-beta.34",
|
||||
"description": "Babel compiler core.",
|
||||
"main": "./lib/index.js",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
@@ -28,13 +28,13 @@
|
||||
"./lib/transform-file-sync.js": "./lib/transform-file-sync-browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "7.0.0-beta.32",
|
||||
"@babel/generator": "7.0.0-beta.32",
|
||||
"@babel/helpers": "7.0.0-beta.32",
|
||||
"@babel/template": "7.0.0-beta.32",
|
||||
"@babel/traverse": "7.0.0-beta.32",
|
||||
"@babel/types": "7.0.0-beta.32",
|
||||
"babylon": "7.0.0-beta.32",
|
||||
"@babel/code-frame": "7.0.0-beta.34",
|
||||
"@babel/generator": "7.0.0-beta.34",
|
||||
"@babel/helpers": "7.0.0-beta.34",
|
||||
"@babel/template": "7.0.0-beta.34",
|
||||
"@babel/traverse": "7.0.0-beta.34",
|
||||
"@babel/types": "7.0.0-beta.34",
|
||||
"babylon": "7.0.0-beta.34",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"debug": "^3.0.1",
|
||||
"json5": "^0.5.0",
|
||||
@@ -44,7 +44,7 @@
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.32",
|
||||
"@babel/register": "7.0.0-beta.32"
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.34",
|
||||
"@babel/register": "7.0.0-beta.34"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @flow
|
||||
|
||||
import { getEnv } from "./helpers/environment";
|
||||
import path from "path";
|
||||
import micromatch from "micromatch";
|
||||
import buildDebug from "debug";
|
||||
@@ -40,21 +39,22 @@ type ConfigPart =
|
||||
};
|
||||
|
||||
export default function buildConfigChain(
|
||||
cwd: string,
|
||||
opts: ValidatedOptions,
|
||||
envName: string,
|
||||
): Array<ConfigItem> | null {
|
||||
const filename = opts.filename ? path.resolve(opts.filename) : null;
|
||||
const filename = opts.filename ? path.resolve(cwd, opts.filename) : null;
|
||||
const builder = new ConfigChainBuilder(
|
||||
filename ? new LoadedFile(filename) : null,
|
||||
);
|
||||
|
||||
const envKey = getEnv();
|
||||
try {
|
||||
builder.mergeConfigArguments(opts, process.cwd(), envKey);
|
||||
builder.mergeConfigArguments(opts, cwd, envName);
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false && filename) {
|
||||
findConfigs(path.dirname(filename)).forEach(configFile =>
|
||||
builder.mergeConfigFile(configFile, envKey),
|
||||
findConfigs(path.dirname(filename), envName).forEach(configFile =>
|
||||
builder.mergeConfigFile(configFile, envName),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -85,21 +85,21 @@ class ConfigChainBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
mergeConfigFile(file: ConfigFile, envKey: string) {
|
||||
mergeConfigFile(file: ConfigFile, envName: string) {
|
||||
if (this.seenFiles.has(file)) {
|
||||
throw new Error(
|
||||
`Cycle detected in Babel configuration file through "${file.filepath}".`,
|
||||
);
|
||||
}
|
||||
|
||||
const parts = flattenFileOptionsParts(file)(envKey);
|
||||
const parts = flattenFileOptionsParts(file)(envName);
|
||||
|
||||
this.seenFiles.add(file);
|
||||
parts.forEach(part => this._processConfigPart(part, envKey));
|
||||
parts.forEach(part => this._processConfigPart(part, envName));
|
||||
this.seenFiles.delete(file);
|
||||
}
|
||||
|
||||
_processConfigPart(part: ConfigPart, envKey: string) {
|
||||
_processConfigPart(part: ConfigPart, envName: string) {
|
||||
if (part.part === "config") {
|
||||
const { ignore, only } = part;
|
||||
|
||||
@@ -116,7 +116,10 @@ class ConfigChainBuilder {
|
||||
|
||||
this.configs.push(part.config);
|
||||
} else {
|
||||
this.mergeConfigFile(loadConfig(part.path, part.dirname), envKey);
|
||||
this.mergeConfigFile(
|
||||
loadConfig(part.path, part.dirname, envName),
|
||||
envName,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +132,7 @@ class ConfigChainBuilder {
|
||||
function flattenArgumentsOptionsParts(
|
||||
opts: ValidatedOptions,
|
||||
dirname: string,
|
||||
envKey: string,
|
||||
envName: string,
|
||||
): Array<ConfigPart> {
|
||||
const {
|
||||
env,
|
||||
@@ -142,7 +145,7 @@ function flattenArgumentsOptionsParts(
|
||||
|
||||
const raw = [];
|
||||
if (env) {
|
||||
raw.push(...flattenArgumentsEnvOptionsParts(env)(dirname)(envKey));
|
||||
raw.push(...flattenArgumentsEnvOptionsParts(env)(dirname)(envName));
|
||||
}
|
||||
|
||||
if (Object.keys(options).length > 0) {
|
||||
@@ -263,7 +266,7 @@ function flattenOptionsPartsLookup(
|
||||
});
|
||||
}
|
||||
|
||||
return envKey => lookup.get(envKey) || def;
|
||||
return envName => lookup.get(envName) || def;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
// @flow
|
||||
|
||||
type CacheConfigurator = CacheConfiguratorFn & CacheConfiguratorObj;
|
||||
type SimpleCacheConfigurator = SimpleCacheConfiguratorFn &
|
||||
SimpleCacheConfiguratorObj;
|
||||
|
||||
type CacheConfiguratorFn = {
|
||||
type SimpleCacheConfiguratorFn = {
|
||||
(boolean): void,
|
||||
<T>(handler: () => T): T,
|
||||
};
|
||||
type CacheConfiguratorObj = {
|
||||
type SimpleCacheConfiguratorObj = {
|
||||
forever: () => void,
|
||||
never: () => void,
|
||||
using: <T>(handler: () => T) => T,
|
||||
invalidate: <T>(handler: () => T) => T,
|
||||
};
|
||||
|
||||
type CacheEntry<ResultT> = Array<[ResultT, () => boolean]>;
|
||||
type CacheEntry<ResultT, SideChannel> = Array<
|
||||
[ResultT, (SideChannel) => boolean],
|
||||
>;
|
||||
|
||||
export type { CacheConfigurator };
|
||||
|
||||
/**
|
||||
* Given a function with a single argument, cache its results based on its argument and how it
|
||||
* configures its caching behavior. Cached values are stored strongly.
|
||||
*/
|
||||
export function makeStrongCache<ArgT, ResultT>(
|
||||
handler: (ArgT, CacheConfigurator) => ResultT,
|
||||
autoPermacache?: boolean,
|
||||
): ArgT => ResultT {
|
||||
return makeCachedFunction(new Map(), handler, autoPermacache);
|
||||
export function makeStrongCache<ArgT, ResultT, SideChannel>(
|
||||
handler: (ArgT, CacheConfigurator<SideChannel>) => ResultT,
|
||||
): (ArgT, SideChannel) => ResultT {
|
||||
return makeCachedFunction(new Map(), handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,190 +35,182 @@ export function makeStrongCache<ArgT, ResultT>(
|
||||
* configures its caching behavior. Cached values are stored weakly and the function argument must be
|
||||
* an object type.
|
||||
*/
|
||||
export function makeWeakCache<ArgT: {} | Array<*> | $ReadOnlyArray<*>, ResultT>(
|
||||
handler: (ArgT, CacheConfigurator) => ResultT,
|
||||
autoPermacache?: boolean,
|
||||
): ArgT => ResultT {
|
||||
return makeCachedFunction(new WeakMap(), handler, autoPermacache);
|
||||
export function makeWeakCache<
|
||||
ArgT: {} | Array<*> | $ReadOnlyArray<*>,
|
||||
ResultT,
|
||||
SideChannel,
|
||||
>(
|
||||
handler: (ArgT, CacheConfigurator<SideChannel>) => ResultT,
|
||||
): (ArgT, SideChannel) => ResultT {
|
||||
return makeCachedFunction(new WeakMap(), handler);
|
||||
}
|
||||
|
||||
type CacheMap<ArgT, ResultT> =
|
||||
| Map<ArgT, CacheEntry<ResultT>>
|
||||
| WeakMap<ArgT, CacheEntry<ResultT>>;
|
||||
type CacheMap<ArgT, ResultT, SideChannel> =
|
||||
| Map<ArgT, CacheEntry<ResultT, SideChannel>>
|
||||
| WeakMap<ArgT, CacheEntry<ResultT, SideChannel>>;
|
||||
|
||||
function makeCachedFunction<ArgT, ResultT, Cache: CacheMap<ArgT, ResultT>>(
|
||||
function makeCachedFunction<
|
||||
ArgT,
|
||||
ResultT,
|
||||
SideChannel,
|
||||
Cache: CacheMap<ArgT, ResultT, SideChannel>,
|
||||
>(
|
||||
callCache: Cache,
|
||||
handler: (ArgT, CacheConfigurator) => ResultT,
|
||||
autoPermacache: boolean = true,
|
||||
): ArgT => ResultT {
|
||||
return function cachedFunction(arg) {
|
||||
let cachedValue: CacheEntry<ResultT> | void = callCache.get(arg);
|
||||
handler: (ArgT, CacheConfigurator<SideChannel>) => ResultT,
|
||||
): (ArgT, SideChannel) => ResultT {
|
||||
return function cachedFunction(arg, data) {
|
||||
let cachedValue: CacheEntry<ResultT, SideChannel> | void = callCache.get(
|
||||
arg,
|
||||
);
|
||||
|
||||
if (cachedValue) {
|
||||
for (const [value, valid] of cachedValue) {
|
||||
if (valid()) return value;
|
||||
if (valid(data)) return value;
|
||||
}
|
||||
}
|
||||
|
||||
const { cache, result, deactivate } = makeCacheConfig();
|
||||
const cache = new CacheConfigurator(data);
|
||||
|
||||
const value = handler(arg, cache);
|
||||
|
||||
if (autoPermacache && !result.configured) cache.forever();
|
||||
if (!cache.configured()) cache.forever();
|
||||
|
||||
deactivate();
|
||||
cache.deactivate();
|
||||
|
||||
if (!result.configured) {
|
||||
// eslint-disable-next-line max-len
|
||||
throw new Error(
|
||||
[
|
||||
"Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured",
|
||||
"for various types of caching, using the first param of their handler functions:",
|
||||
"",
|
||||
"module.exports = function(api) {",
|
||||
" // The API exposes the following:",
|
||||
"",
|
||||
" // Cache the returned value forever and don't call this function again.",
|
||||
" api.cache(true);",
|
||||
"",
|
||||
" // Don't cache at all. Not recommended because it will be very slow.",
|
||||
" api.cache(false);",
|
||||
"",
|
||||
" // Cached based on the value of some function. If this function returns a value different from",
|
||||
" // a previously-encountered value, the plugins will re-evaluate.",
|
||||
" var env = api.cache(() => process.env.NODE_ENV);",
|
||||
"",
|
||||
" // If testing for a specific env, we recommend specifics to avoid instantiating a plugin for",
|
||||
" // any possible NODE_ENV value that might come up during plugin execution.",
|
||||
' var isProd = api.cache(() => process.env.NODE_ENV === "production");',
|
||||
"",
|
||||
" // .cache(fn) will perform a linear search though instances to find the matching plugin based",
|
||||
" // based on previous instantiated plugins. If you want to recreate the plugin and discard the",
|
||||
" // previous instance whenever something changes, you may use:",
|
||||
' var isProd = api.cache.invalidate(() => process.env.NODE_ENV === "production");',
|
||||
"",
|
||||
" // Note, we also expose the following more-verbose versions of the above examples:",
|
||||
" api.cache.forever(); // api.cache(true)",
|
||||
" api.cache.never(); // api.cache(false)",
|
||||
" api.cache.using(fn); // api.cache(fn)",
|
||||
"",
|
||||
" // Return the value that will be cached.",
|
||||
" return { };",
|
||||
"};",
|
||||
].join("\n"),
|
||||
);
|
||||
}
|
||||
|
||||
if (!result.never) {
|
||||
if (result.forever) {
|
||||
switch (cache.mode()) {
|
||||
case "forever":
|
||||
cachedValue = [[value, () => true]];
|
||||
} else if (result.invalidate) {
|
||||
cachedValue = [[value, result.valid]];
|
||||
} else {
|
||||
cachedValue = cachedValue || [];
|
||||
cachedValue.push([value, result.valid]);
|
||||
}
|
||||
callCache.set(arg, cachedValue);
|
||||
callCache.set(arg, cachedValue);
|
||||
break;
|
||||
case "invalidate":
|
||||
cachedValue = [[value, cache.validator()]];
|
||||
callCache.set(arg, cachedValue);
|
||||
break;
|
||||
case "valid":
|
||||
if (cachedValue) {
|
||||
cachedValue.push([value, cache.validator()]);
|
||||
} else {
|
||||
cachedValue = [[value, cache.validator()]];
|
||||
callCache.set(arg, cachedValue);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
function makeCacheConfig(): {
|
||||
cache: CacheConfigurator,
|
||||
result: *,
|
||||
deactivate: () => void,
|
||||
} {
|
||||
const pairs = [];
|
||||
class CacheConfigurator<SideChannel = void> {
|
||||
_active: boolean = true;
|
||||
_never: boolean = false;
|
||||
_forever: boolean = false;
|
||||
_invalidate: boolean = false;
|
||||
|
||||
const result = {
|
||||
configured: false,
|
||||
never: false,
|
||||
forever: false,
|
||||
invalidate: false,
|
||||
valid: () => pairs.every(([key, fn]) => key === fn()),
|
||||
};
|
||||
_configured: boolean = false;
|
||||
|
||||
let active = true;
|
||||
const deactivate = () => {
|
||||
active = false;
|
||||
};
|
||||
_pairs: Array<[mixed, (SideChannel) => mixed]> = [];
|
||||
|
||||
const cache: CacheConfigurator = Object.assign(
|
||||
(function cacheFn(val) {
|
||||
if (typeof val === "boolean") {
|
||||
if (val) cache.forever();
|
||||
else cache.never();
|
||||
return;
|
||||
}
|
||||
_data: SideChannel;
|
||||
|
||||
return cache.using(val);
|
||||
}: any),
|
||||
({
|
||||
forever() {
|
||||
if (!active) {
|
||||
throw new Error(
|
||||
"Cannot change caching after evaluation has completed.",
|
||||
);
|
||||
}
|
||||
if (result.never) {
|
||||
throw new Error("Caching has already been configured with .never()");
|
||||
}
|
||||
result.forever = true;
|
||||
result.configured = true;
|
||||
},
|
||||
never() {
|
||||
if (!active) {
|
||||
throw new Error(
|
||||
"Cannot change caching after evaluation has completed.",
|
||||
);
|
||||
}
|
||||
if (result.forever) {
|
||||
throw new Error(
|
||||
"Caching has already been configured with .forever()",
|
||||
);
|
||||
}
|
||||
result.never = true;
|
||||
result.configured = true;
|
||||
},
|
||||
using<T>(handler: () => T): T {
|
||||
if (!active) {
|
||||
throw new Error(
|
||||
"Cannot change caching after evaluation has completed.",
|
||||
);
|
||||
}
|
||||
if (result.never || result.forever) {
|
||||
throw new Error(
|
||||
"Caching has already been configured with .never or .forever()",
|
||||
);
|
||||
}
|
||||
result.configured = true;
|
||||
constructor(data: SideChannel) {
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
const key = handler();
|
||||
pairs.push([key, handler]);
|
||||
return key;
|
||||
},
|
||||
invalidate<T>(handler: () => T): T {
|
||||
if (!active) {
|
||||
throw new Error(
|
||||
"Cannot change caching after evaluation has completed.",
|
||||
);
|
||||
}
|
||||
if (result.never || result.forever) {
|
||||
throw new Error(
|
||||
"Caching has already been configured with .never or .forever()",
|
||||
);
|
||||
}
|
||||
result.invalidate = true;
|
||||
result.configured = true;
|
||||
simple() {
|
||||
return makeSimpleConfigurator(this);
|
||||
}
|
||||
|
||||
const key = handler();
|
||||
pairs.push([key, handler]);
|
||||
return key;
|
||||
},
|
||||
}: CacheConfiguratorObj),
|
||||
);
|
||||
mode() {
|
||||
if (this._never) return "never";
|
||||
if (this._forever) return "forever";
|
||||
if (this._invalidate) return "invalidate";
|
||||
return "valid";
|
||||
}
|
||||
|
||||
return { cache, result, deactivate };
|
||||
forever() {
|
||||
if (!this._active) {
|
||||
throw new Error("Cannot change caching after evaluation has completed.");
|
||||
}
|
||||
if (this._never) {
|
||||
throw new Error("Caching has already been configured with .never()");
|
||||
}
|
||||
this._forever = true;
|
||||
this._configured = true;
|
||||
}
|
||||
|
||||
never() {
|
||||
if (!this._active) {
|
||||
throw new Error("Cannot change caching after evaluation has completed.");
|
||||
}
|
||||
if (this._forever) {
|
||||
throw new Error("Caching has already been configured with .forever()");
|
||||
}
|
||||
this._never = true;
|
||||
this._configured = true;
|
||||
}
|
||||
|
||||
using<T>(handler: SideChannel => T): T {
|
||||
if (!this._active) {
|
||||
throw new Error("Cannot change caching after evaluation has completed.");
|
||||
}
|
||||
if (this._never || this._forever) {
|
||||
throw new Error(
|
||||
"Caching has already been configured with .never or .forever()",
|
||||
);
|
||||
}
|
||||
this._configured = true;
|
||||
|
||||
const key = handler(this._data);
|
||||
this._pairs.push([key, handler]);
|
||||
return key;
|
||||
}
|
||||
|
||||
invalidate<T>(handler: SideChannel => T): T {
|
||||
if (!this._active) {
|
||||
throw new Error("Cannot change caching after evaluation has completed.");
|
||||
}
|
||||
if (this._never || this._forever) {
|
||||
throw new Error(
|
||||
"Caching has already been configured with .never or .forever()",
|
||||
);
|
||||
}
|
||||
this._invalidate = true;
|
||||
this._configured = true;
|
||||
|
||||
const key = handler(this._data);
|
||||
this._pairs.push([key, handler]);
|
||||
return key;
|
||||
}
|
||||
|
||||
validator(): SideChannel => boolean {
|
||||
const pairs = this._pairs;
|
||||
return (data: SideChannel) => pairs.every(([key, fn]) => key === fn(data));
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._active = false;
|
||||
}
|
||||
|
||||
configured() {
|
||||
return this._configured;
|
||||
}
|
||||
}
|
||||
|
||||
function makeSimpleConfigurator(
|
||||
cache: CacheConfigurator<any>,
|
||||
): SimpleCacheConfigurator {
|
||||
function cacheFn(val) {
|
||||
if (typeof val === "boolean") {
|
||||
if (val) cache.forever();
|
||||
else cache.never();
|
||||
return;
|
||||
}
|
||||
|
||||
return cache.using(val);
|
||||
}
|
||||
cacheFn.forever = () => cache.forever();
|
||||
cacheFn.never = () => cache.never();
|
||||
cacheFn.using = cb => cache.using(() => cb());
|
||||
cacheFn.invalidate = cb => cache.invalidate(() => cb());
|
||||
|
||||
return (cacheFn: any);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
import json5 from "json5";
|
||||
import resolve from "resolve";
|
||||
import { getEnv } from "../../helpers/environment";
|
||||
import { makeStrongCache } from "../../caching";
|
||||
import { makeStrongCache, type CacheConfigurator } from "../../caching";
|
||||
|
||||
const debug = buildDebug("babel:config:loading:files:configuration");
|
||||
|
||||
@@ -21,7 +20,10 @@ const BABELRC_JS_FILENAME = ".babelrc.js";
|
||||
const PACKAGE_FILENAME = "package.json";
|
||||
const BABELIGNORE_FILENAME = ".babelignore";
|
||||
|
||||
export function findConfigs(dirname: string): Array<ConfigFile> {
|
||||
export function findConfigs(
|
||||
dirname: string,
|
||||
envName: string,
|
||||
): Array<ConfigFile> {
|
||||
let foundConfig = false;
|
||||
let foundIgnore = false;
|
||||
|
||||
@@ -47,7 +49,7 @@ export function findConfigs(dirname: string): Array<ConfigFile> {
|
||||
PACKAGE_FILENAME,
|
||||
].reduce((previousConfig: ConfigFile | null, name) => {
|
||||
const filepath = path.join(loc, name);
|
||||
const config = readConfig(filepath);
|
||||
const config = readConfig(filepath, envName);
|
||||
|
||||
if (config && previousConfig) {
|
||||
throw new Error(
|
||||
@@ -77,10 +79,14 @@ export function findConfigs(dirname: string): Array<ConfigFile> {
|
||||
return confs;
|
||||
}
|
||||
|
||||
export function loadConfig(name: string, dirname: string): ConfigFile {
|
||||
export function loadConfig(
|
||||
name: string,
|
||||
dirname: string,
|
||||
envName: string,
|
||||
): ConfigFile {
|
||||
const filepath = resolve.sync(name, { basedir: dirname });
|
||||
|
||||
const conf = readConfig(filepath);
|
||||
const conf = readConfig(filepath, envName);
|
||||
if (!conf) {
|
||||
throw new Error(`Config file ${filepath} contains no configuration data`);
|
||||
}
|
||||
@@ -93,72 +99,86 @@ export function loadConfig(name: string, dirname: string): ConfigFile {
|
||||
* Read the given config file, returning the result. Returns null if no config was found, but will
|
||||
* throw if there are parsing errors while loading a config.
|
||||
*/
|
||||
function readConfig(filepath) {
|
||||
function readConfig(filepath, envName) {
|
||||
return path.extname(filepath) === ".js"
|
||||
? readConfigJS(filepath)
|
||||
? readConfigJS(filepath, { envName })
|
||||
: readConfigFile(filepath);
|
||||
}
|
||||
|
||||
const LOADING_CONFIGS = new Set();
|
||||
const readConfigJS = makeStrongCache((filepath, cache) => {
|
||||
if (!fs.existsSync(filepath)) {
|
||||
cache.forever();
|
||||
return null;
|
||||
}
|
||||
|
||||
// The `require()` call below can make this code reentrant if a require hook like @babel/register has been
|
||||
// loaded into the system. That would cause Babel to attempt to compile the `.babelrc.js` file as it loads
|
||||
// below. To cover this case, we auto-ignore re-entrant config processing.
|
||||
if (LOADING_CONFIGS.has(filepath)) {
|
||||
cache.never();
|
||||
const readConfigJS = makeStrongCache(
|
||||
(filepath, cache: CacheConfigurator<{ envName: string }>) => {
|
||||
if (!fs.existsSync(filepath)) {
|
||||
cache.forever();
|
||||
return null;
|
||||
}
|
||||
|
||||
// The `require()` call below can make this code reentrant if a require hook like @babel/register has been
|
||||
// loaded into the system. That would cause Babel to attempt to compile the `.babelrc.js` file as it loads
|
||||
// below. To cover this case, we auto-ignore re-entrant config processing.
|
||||
if (LOADING_CONFIGS.has(filepath)) {
|
||||
cache.never();
|
||||
|
||||
debug("Auto-ignoring usage of config %o.", filepath);
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options: {},
|
||||
};
|
||||
}
|
||||
|
||||
let options;
|
||||
try {
|
||||
LOADING_CONFIGS.add(filepath);
|
||||
|
||||
// $FlowIssue
|
||||
const configModule = (require(filepath): mixed);
|
||||
options =
|
||||
configModule && configModule.__esModule
|
||||
? configModule.default || undefined
|
||||
: configModule;
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while loading config - ${err.message}`;
|
||||
throw err;
|
||||
} finally {
|
||||
LOADING_CONFIGS.delete(filepath);
|
||||
}
|
||||
|
||||
if (typeof options === "function") {
|
||||
options = options({
|
||||
cache: cache.simple(),
|
||||
// Expose ".env()" so people can easily get the same env that we expose using the "env" key.
|
||||
env: () => cache.using(data => data.envName),
|
||||
async: () => false,
|
||||
});
|
||||
|
||||
if (!cache.configured()) throwConfigError();
|
||||
}
|
||||
|
||||
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
||||
throw new Error(
|
||||
`${filepath}: Configuration should be an exported JavaScript object.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof options.then === "function") {
|
||||
throw new Error(
|
||||
`You appear to be using an async configuration, ` +
|
||||
`which your current version of Babel does not support. ` +
|
||||
`We may add support for this in the future, ` +
|
||||
`but if you're on the most recent version of @babel/core and still ` +
|
||||
`seeing this error, then you'll need to synchronously return your config.`,
|
||||
);
|
||||
}
|
||||
|
||||
debug("Auto-ignoring usage of config %o.", filepath);
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options: {},
|
||||
options,
|
||||
};
|
||||
}
|
||||
|
||||
let options;
|
||||
try {
|
||||
LOADING_CONFIGS.add(filepath);
|
||||
|
||||
// $FlowIssue
|
||||
const configModule = (require(filepath): mixed);
|
||||
options =
|
||||
configModule && configModule.__esModule
|
||||
? configModule.default || undefined
|
||||
: configModule;
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while loading config - ${err.message}`;
|
||||
throw err;
|
||||
} finally {
|
||||
LOADING_CONFIGS.delete(filepath);
|
||||
}
|
||||
|
||||
if (typeof options === "function") {
|
||||
options = options({
|
||||
cache,
|
||||
// Expose ".env()" so people can easily get the same env that we expose using the "env" key.
|
||||
env: () => cache.using(() => getEnv()),
|
||||
});
|
||||
} else {
|
||||
cache.forever();
|
||||
}
|
||||
|
||||
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
||||
throw new Error(
|
||||
`${filepath}: Configuration should be an exported JavaScript object.`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options,
|
||||
};
|
||||
}, false /* autoPermacache */);
|
||||
},
|
||||
);
|
||||
|
||||
const readConfigFile = makeStaticFileCache((filepath, content) => {
|
||||
let options;
|
||||
@@ -228,3 +248,40 @@ function fileMtime(filepath: string): number | null {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function throwConfigError() {
|
||||
throw new Error(`\
|
||||
Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured
|
||||
for various types of caching, using the first param of their handler functions:
|
||||
|
||||
module.exports = function(api) {
|
||||
// The API exposes the following:
|
||||
|
||||
// Cache the returned value forever and don't call this function again.
|
||||
api.cache(true);
|
||||
|
||||
// Don't cache at all. Not recommended because it will be very slow.
|
||||
api.cache(false);
|
||||
|
||||
// Cached based on the value of some function. If this function returns a value different from
|
||||
// a previously-encountered value, the plugins will re-evaluate.
|
||||
var env = api.cache(() => process.env.NODE_ENV);
|
||||
|
||||
// If testing for a specific env, we recommend specifics to avoid instantiating a plugin for
|
||||
// any possible NODE_ENV value that might come up during plugin execution.
|
||||
var isProd = api.cache(() => process.env.NODE_ENV === "production");
|
||||
|
||||
// .cache(fn) will perform a linear search though instances to find the matching plugin based
|
||||
// based on previous instantiated plugins. If you want to recreate the plugin and discard the
|
||||
// previous instance whenever something changes, you may use:
|
||||
var isProd = api.cache.invalidate(() => process.env.NODE_ENV === "production");
|
||||
|
||||
// Note, we also expose the following more-verbose versions of the above examples:
|
||||
api.cache.forever(); // api.cache(true)
|
||||
api.cache.never(); // api.cache(false)
|
||||
api.cache.using(fn); // api.cache(fn)
|
||||
|
||||
// Return the value that will be cached.
|
||||
return { };
|
||||
};`);
|
||||
}
|
||||
|
||||
@@ -146,16 +146,31 @@ function assertPluginItem(
|
||||
if (value.length === 0) {
|
||||
throw new Error(`.${key}[${index}] must include an object`);
|
||||
}
|
||||
if (value.length > 2) {
|
||||
throw new Error(`.${key}[${index}] may only be a two-tuple`);
|
||||
|
||||
if (value.length > 3) {
|
||||
throw new Error(
|
||||
`.${key}[${index}] may only be a two-tuple or three-tuple`,
|
||||
);
|
||||
}
|
||||
|
||||
assertPluginTarget(key, index, true, value[0]);
|
||||
|
||||
if (value.length === 2) {
|
||||
if (value.length > 1) {
|
||||
const opts = value[1];
|
||||
if (opts != null && (typeof opts !== "object" || Array.isArray(opts))) {
|
||||
throw new Error(`.${key}[${index}][1] must be an object, or undefined`);
|
||||
if (
|
||||
opts !== undefined &&
|
||||
opts !== false &&
|
||||
(typeof opts !== "object" || Array.isArray(opts))
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key}[${index}][1] must be an object, false, or undefined`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (value.length === 3) {
|
||||
const name = value[2];
|
||||
if (name !== undefined && typeof name !== "string") {
|
||||
throw new Error(`.${key}[${index}][2] must be a string, or undefined`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// @flow
|
||||
|
||||
import path from "path";
|
||||
import * as context from "../index";
|
||||
import Plugin, { validatePluginObject } from "./plugin";
|
||||
import merge from "lodash/merge";
|
||||
import buildConfigChain, { type ConfigItem } from "./build-config-chain";
|
||||
import traverse from "@babel/traverse";
|
||||
import clone from "lodash/clone";
|
||||
import { makeWeakCache } from "./caching";
|
||||
import { makeWeakCache, type CacheConfigurator } from "./caching";
|
||||
import { getEnv } from "./helpers/environment";
|
||||
import { validate, type ValidatedOptions, type PluginItem } from "./options";
|
||||
|
||||
@@ -29,13 +30,9 @@ export default function manageOptions(opts: {}): {
|
||||
}
|
||||
|
||||
class OptionManager {
|
||||
constructor() {
|
||||
this.options = {};
|
||||
this.passes = [[]];
|
||||
}
|
||||
|
||||
options: ValidatedOptions;
|
||||
passes: Array<Array<Plugin>>;
|
||||
optionDefaults: ValidatedOptions = {};
|
||||
options: ValidatedOptions = {};
|
||||
passes: Array<Array<Plugin>> = [[]];
|
||||
|
||||
/**
|
||||
* This is called when we want to merge the input `opts` into the
|
||||
@@ -45,32 +42,47 @@ class OptionManager {
|
||||
* - `loc` is used to point to the original config.
|
||||
* - `dirname` is used to resolve plugins relative to it.
|
||||
*/
|
||||
|
||||
mergeOptions(config: MergeOptions, pass?: Array<Plugin>) {
|
||||
const result = loadConfig(config);
|
||||
|
||||
const plugins = result.plugins.map(descriptor =>
|
||||
loadPluginDescriptor(descriptor),
|
||||
mergeOptions(
|
||||
config: {
|
||||
plugins: Array<BasicDescriptor>,
|
||||
presets: Array<BasicDescriptor>,
|
||||
},
|
||||
pass: Array<Plugin>,
|
||||
envName: string,
|
||||
) {
|
||||
const plugins = config.plugins.map(descriptor =>
|
||||
loadPluginDescriptor(descriptor, envName),
|
||||
);
|
||||
const presets = result.presets.map(descriptor =>
|
||||
loadPresetDescriptor(descriptor),
|
||||
);
|
||||
|
||||
const passPerPreset = config.options.passPerPreset;
|
||||
pass = pass || this.passes[0];
|
||||
const presets = config.presets.map(descriptor => {
|
||||
return {
|
||||
preset: loadPresetDescriptor(descriptor, envName),
|
||||
pass: descriptor.ownPass ? [] : pass,
|
||||
};
|
||||
});
|
||||
|
||||
// resolve presets
|
||||
if (presets.length > 0) {
|
||||
let presetPasses = null;
|
||||
if (passPerPreset) {
|
||||
presetPasses = presets.map(() => []);
|
||||
// The passes are created in the same order as the preset list, but are inserted before any
|
||||
// existing additional passes.
|
||||
this.passes.splice(1, 0, ...presetPasses);
|
||||
}
|
||||
// The passes are created in the same order as the preset list, but are inserted before any
|
||||
// existing additional passes.
|
||||
this.passes.splice(
|
||||
1,
|
||||
0,
|
||||
...presets.map(o => o.pass).filter(p => p !== pass),
|
||||
);
|
||||
|
||||
presets.forEach((presetConfig, i) => {
|
||||
this.mergeOptions(presetConfig, presetPasses ? presetPasses[i] : pass);
|
||||
presets.forEach(({ preset, pass }) => {
|
||||
const loadedConfig = loadConfig(preset);
|
||||
this.mergeOptions(
|
||||
{
|
||||
// Call dedupDescriptors() to remove 'false' descriptors.
|
||||
plugins: dedupDescriptors(loadedConfig.plugins),
|
||||
presets: dedupDescriptors(loadedConfig.presets),
|
||||
},
|
||||
pass,
|
||||
envName,
|
||||
);
|
||||
|
||||
merge(this.optionDefaults, normalizeOptions(loadedConfig.options));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,34 +90,36 @@ class OptionManager {
|
||||
if (plugins.length > 0) {
|
||||
pass.unshift(...plugins);
|
||||
}
|
||||
}
|
||||
|
||||
const options = Object.assign({}, result.options);
|
||||
delete options.extends;
|
||||
delete options.env;
|
||||
delete options.plugins;
|
||||
delete options.presets;
|
||||
delete options.passPerPreset;
|
||||
mergeConfigChain(chain: $ReadOnlyArray<MergeOptions>, envName: string) {
|
||||
const config = dedupLoadedConfigs(chain.map(config => loadConfig(config)));
|
||||
|
||||
// "sourceMap" is just aliased to sourceMap, so copy it over as
|
||||
// we merge the options together.
|
||||
if (options.sourceMap) {
|
||||
options.sourceMaps = options.sourceMap;
|
||||
delete options.sourceMap;
|
||||
}
|
||||
this.mergeOptions(
|
||||
{
|
||||
plugins: config.plugins,
|
||||
presets: config.presets,
|
||||
},
|
||||
this.passes[0],
|
||||
envName,
|
||||
);
|
||||
|
||||
merge(this.options, options);
|
||||
config.options.forEach(opts => {
|
||||
merge(this.options, normalizeOptions(opts));
|
||||
});
|
||||
}
|
||||
|
||||
init(inputOpts: {}) {
|
||||
const args = validate("arguments", inputOpts);
|
||||
|
||||
const configChain = buildConfigChain(args);
|
||||
const { envName = getEnv(), cwd = "." } = args;
|
||||
const absoluteCwd = path.resolve(cwd);
|
||||
|
||||
const configChain = buildConfigChain(absoluteCwd, args, envName);
|
||||
if (!configChain) return null;
|
||||
|
||||
try {
|
||||
for (const config of configChain) {
|
||||
this.mergeOptions(config);
|
||||
}
|
||||
this.mergeConfigChain(configChain, envName);
|
||||
} catch (e) {
|
||||
// There are a few case where thrown errors will try to annotate themselves multiple times, so
|
||||
// to keep things simple we just bail out if re-wrapping the message.
|
||||
@@ -116,7 +130,7 @@ class OptionManager {
|
||||
throw e;
|
||||
}
|
||||
|
||||
const opts: Object = this.options;
|
||||
const opts: Object = merge(this.optionDefaults, this.options);
|
||||
|
||||
// Tack the passes onto the object itself so that, if this object is passed back to Babel a second time,
|
||||
// it will be in the right structure to not change behavior.
|
||||
@@ -127,6 +141,8 @@ class OptionManager {
|
||||
.filter(plugins => plugins.length > 0)
|
||||
.map(plugins => ({ plugins }));
|
||||
opts.passPerPreset = opts.presets.length > 0;
|
||||
opts.envName = envName;
|
||||
opts.cwd = absoluteCwd;
|
||||
|
||||
return {
|
||||
options: opts,
|
||||
@@ -135,11 +151,32 @@ class OptionManager {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeOptions(opts: ValidatedOptions): ValidatedOptions {
|
||||
const options = Object.assign({}, opts);
|
||||
delete options.extends;
|
||||
delete options.env;
|
||||
delete options.plugins;
|
||||
delete options.presets;
|
||||
delete options.passPerPreset;
|
||||
delete options.ignore;
|
||||
delete options.only;
|
||||
|
||||
// "sourceMap" is just aliased to sourceMap, so copy it over as
|
||||
// we merge the options together.
|
||||
if (options.sourceMap) {
|
||||
options.sourceMaps = options.sourceMap;
|
||||
delete options.sourceMap;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
type BasicDescriptor = {
|
||||
name: string | void,
|
||||
value: {} | Function,
|
||||
options: {} | void,
|
||||
options: {} | void | false,
|
||||
dirname: string,
|
||||
alias: string,
|
||||
ownPass?: boolean,
|
||||
};
|
||||
|
||||
type LoadedDescriptor = {
|
||||
@@ -149,14 +186,16 @@ type LoadedDescriptor = {
|
||||
alias: string,
|
||||
};
|
||||
|
||||
type LoadedConfig = {
|
||||
options: ValidatedOptions,
|
||||
plugins: Array<BasicDescriptor>,
|
||||
presets: Array<BasicDescriptor>,
|
||||
};
|
||||
|
||||
/**
|
||||
* Load and validate the given config into a set of options, plugins, and presets.
|
||||
*/
|
||||
const loadConfig = makeWeakCache((config: MergeOptions): {
|
||||
options: {},
|
||||
plugins: Array<BasicDescriptor>,
|
||||
presets: Array<BasicDescriptor>,
|
||||
} => {
|
||||
const loadConfig = makeWeakCache((config: MergeOptions): LoadedConfig => {
|
||||
const options = config.options;
|
||||
|
||||
const plugins = (config.options.plugins || []).map((plugin, index) =>
|
||||
@@ -166,29 +205,139 @@ const loadConfig = makeWeakCache((config: MergeOptions): {
|
||||
}),
|
||||
);
|
||||
|
||||
assertNoDuplicates(plugins);
|
||||
|
||||
const presets = (config.options.presets || []).map((preset, index) =>
|
||||
createDescriptor(preset, loadPreset, config.dirname, {
|
||||
index,
|
||||
alias: config.alias,
|
||||
ownPass: options.passPerPreset,
|
||||
}),
|
||||
);
|
||||
|
||||
assertNoDuplicates(presets);
|
||||
|
||||
return { options, plugins, presets };
|
||||
});
|
||||
|
||||
function assertNoDuplicates(items: Array<BasicDescriptor>): void {
|
||||
const map = new Map();
|
||||
|
||||
for (const item of items) {
|
||||
if (typeof item.value !== "function") continue;
|
||||
|
||||
let nameMap = map.get(item.value);
|
||||
if (!nameMap) {
|
||||
nameMap = new Set();
|
||||
map.set(item.value, nameMap);
|
||||
}
|
||||
|
||||
if (nameMap.has(item.name)) {
|
||||
throw new Error(
|
||||
[
|
||||
`Duplicate plugin/preset detected.`,
|
||||
`If you'd like to use two separate instances of a plugin,`,
|
||||
`they neen separate names, e.g.`,
|
||||
``,
|
||||
` plugins: [`,
|
||||
` ['some-plugin', {}],`,
|
||||
` ['some-plugin', {}, 'some unique name'],`,
|
||||
` ]`,
|
||||
].join("\n"),
|
||||
);
|
||||
}
|
||||
|
||||
nameMap.add(item.name);
|
||||
}
|
||||
}
|
||||
|
||||
function dedupLoadedConfigs(
|
||||
items: Array<LoadedConfig>,
|
||||
): {
|
||||
plugins: Array<BasicDescriptor>,
|
||||
presets: Array<BasicDescriptor>,
|
||||
options: Array<ValidatedOptions>,
|
||||
} {
|
||||
const options = [];
|
||||
const plugins = [];
|
||||
const presets = [];
|
||||
|
||||
for (const item of items) {
|
||||
plugins.push(...item.plugins);
|
||||
presets.push(...item.presets);
|
||||
options.push(item.options);
|
||||
}
|
||||
|
||||
return {
|
||||
options,
|
||||
plugins: dedupDescriptors(plugins),
|
||||
presets: dedupDescriptors(presets),
|
||||
};
|
||||
}
|
||||
|
||||
function dedupDescriptors(
|
||||
items: Array<BasicDescriptor>,
|
||||
): Array<BasicDescriptor> {
|
||||
const map: Map<
|
||||
Function,
|
||||
Map<string | void, { value: BasicDescriptor | null }>,
|
||||
> = new Map();
|
||||
|
||||
const descriptors = [];
|
||||
|
||||
for (const item of items) {
|
||||
if (typeof item.value === "function") {
|
||||
const fnKey = item.value;
|
||||
let nameMap = map.get(fnKey);
|
||||
if (!nameMap) {
|
||||
nameMap = new Map();
|
||||
map.set(fnKey, nameMap);
|
||||
}
|
||||
let desc = nameMap.get(item.name);
|
||||
if (!desc) {
|
||||
desc = { value: null };
|
||||
descriptors.push(desc);
|
||||
|
||||
// Treat passPerPreset presets as unique, skipping them
|
||||
// in the merge processing steps.
|
||||
if (!item.ownPass) nameMap.set(item.name, desc);
|
||||
}
|
||||
|
||||
if (item.options === false) {
|
||||
desc.value = null;
|
||||
} else {
|
||||
desc.value = item;
|
||||
}
|
||||
} else {
|
||||
descriptors.push({ value: item });
|
||||
}
|
||||
}
|
||||
|
||||
return descriptors.reduce((acc, desc) => {
|
||||
if (desc.value) acc.push(desc.value);
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a generic plugin/preset from the given descriptor loaded from the config object.
|
||||
*/
|
||||
const loadDescriptor = makeWeakCache(
|
||||
(
|
||||
{ value, options = {}, dirname, alias }: BasicDescriptor,
|
||||
cache,
|
||||
{ value, options, dirname, alias }: BasicDescriptor,
|
||||
cache: CacheConfigurator<{ envName: string }>,
|
||||
): LoadedDescriptor => {
|
||||
// Disabled presets should already have been filtered out
|
||||
if (options === false) throw new Error("Assertion failure");
|
||||
|
||||
options = options || {};
|
||||
|
||||
let item = value;
|
||||
if (typeof value === "function") {
|
||||
const api = Object.assign(Object.create(context), {
|
||||
cache,
|
||||
env: () => cache.using(() => getEnv()),
|
||||
cache: cache.simple(),
|
||||
env: () => cache.using(data => data.envName),
|
||||
async: () => false,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -205,6 +354,15 @@ const loadDescriptor = makeWeakCache(
|
||||
throw new Error("Plugin/Preset did not return an object.");
|
||||
}
|
||||
|
||||
if (typeof item.then === "function") {
|
||||
throw new Error(
|
||||
`You appear to be using an async plugin, ` +
|
||||
`which your current version of Babel does not support.` +
|
||||
`If you're using a published plugin, ` +
|
||||
`you may need to upgrade your @babel/core version.`,
|
||||
);
|
||||
}
|
||||
|
||||
return { value: item, options, dirname, alias };
|
||||
},
|
||||
);
|
||||
@@ -212,7 +370,10 @@ const loadDescriptor = makeWeakCache(
|
||||
/**
|
||||
* Instantiate a plugin for the given descriptor, returning the plugin/options pair.
|
||||
*/
|
||||
function loadPluginDescriptor(descriptor: BasicDescriptor): Plugin {
|
||||
function loadPluginDescriptor(
|
||||
descriptor: BasicDescriptor,
|
||||
envName: string,
|
||||
): Plugin {
|
||||
if (descriptor.value instanceof Plugin) {
|
||||
if (descriptor.options) {
|
||||
throw new Error(
|
||||
@@ -223,11 +384,16 @@ function loadPluginDescriptor(descriptor: BasicDescriptor): Plugin {
|
||||
return descriptor.value;
|
||||
}
|
||||
|
||||
return instantiatePlugin(loadDescriptor(descriptor));
|
||||
return instantiatePlugin(loadDescriptor(descriptor, { envName }), {
|
||||
envName,
|
||||
});
|
||||
}
|
||||
|
||||
const instantiatePlugin = makeWeakCache(
|
||||
({ value, options, dirname, alias }: LoadedDescriptor, cache): Plugin => {
|
||||
(
|
||||
{ value, options, dirname, alias }: LoadedDescriptor,
|
||||
cache: CacheConfigurator<{ envName: string }>,
|
||||
): Plugin => {
|
||||
const pluginObj = validatePluginObject(value);
|
||||
|
||||
const plugin = Object.assign({}, pluginObj);
|
||||
@@ -237,6 +403,7 @@ const instantiatePlugin = makeWeakCache(
|
||||
|
||||
if (plugin.inherits) {
|
||||
const inheritsDescriptor = {
|
||||
name: undefined,
|
||||
alias: `${alias}$inherits`,
|
||||
value: plugin.inherits,
|
||||
options,
|
||||
@@ -244,8 +411,8 @@ const instantiatePlugin = makeWeakCache(
|
||||
};
|
||||
|
||||
// If the inherited plugin changes, reinstantiate this plugin.
|
||||
const inherits = cache.invalidate(() =>
|
||||
loadPluginDescriptor(inheritsDescriptor),
|
||||
const inherits = cache.invalidate(data =>
|
||||
loadPluginDescriptor(inheritsDescriptor, data.envName),
|
||||
);
|
||||
|
||||
plugin.pre = chain(inherits.pre, plugin.pre);
|
||||
@@ -267,8 +434,11 @@ const instantiatePlugin = makeWeakCache(
|
||||
/**
|
||||
* Generate a config object that will act as the root of a new nested config.
|
||||
*/
|
||||
const loadPresetDescriptor = (descriptor: BasicDescriptor): MergeOptions => {
|
||||
return instantiatePreset(loadDescriptor(descriptor));
|
||||
const loadPresetDescriptor = (
|
||||
descriptor: BasicDescriptor,
|
||||
envName: string,
|
||||
): MergeOptions => {
|
||||
return instantiatePreset(loadDescriptor(descriptor, { envName }));
|
||||
};
|
||||
|
||||
const instantiatePreset = makeWeakCache(
|
||||
@@ -292,15 +462,23 @@ function createDescriptor(
|
||||
{
|
||||
index,
|
||||
alias,
|
||||
ownPass,
|
||||
}: {
|
||||
index: number,
|
||||
alias: string,
|
||||
ownPass?: boolean,
|
||||
},
|
||||
): BasicDescriptor {
|
||||
let name;
|
||||
let options;
|
||||
let value = pair;
|
||||
if (Array.isArray(value)) {
|
||||
[value, options] = value;
|
||||
if (value.length === 3) {
|
||||
// $FlowIgnore - Flow doesn't like the multiple tuple types.
|
||||
[value, options, name] = value;
|
||||
} else {
|
||||
[value, options] = value;
|
||||
}
|
||||
}
|
||||
|
||||
let filepath = null;
|
||||
@@ -335,18 +513,13 @@ function createDescriptor(
|
||||
);
|
||||
}
|
||||
|
||||
if (options != null && typeof options !== "object") {
|
||||
throw new Error(
|
||||
"Plugin/Preset options must be an object, null, or undefined",
|
||||
);
|
||||
}
|
||||
options = options || undefined;
|
||||
|
||||
return {
|
||||
name,
|
||||
alias: filepath || `${alias}$${index}`,
|
||||
value,
|
||||
options,
|
||||
dirname,
|
||||
ownPass,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
} from "./option-assertions";
|
||||
|
||||
const ROOT_VALIDATORS: ValidatorSet = {
|
||||
cwd: (assertString: Validator<$PropertyType<ValidatedOptions, "cwd">>),
|
||||
filename: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "filename">,
|
||||
>),
|
||||
@@ -28,6 +29,10 @@ const ROOT_VALIDATORS: ValidatorSet = {
|
||||
>),
|
||||
code: (assertBoolean: Validator<$PropertyType<ValidatedOptions, "code">>),
|
||||
ast: (assertBoolean: Validator<$PropertyType<ValidatedOptions, "ast">>),
|
||||
|
||||
envName: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "envName">,
|
||||
>),
|
||||
};
|
||||
|
||||
const NONPRESET_VALIDATORS: ValidatorSet = {
|
||||
@@ -124,12 +129,14 @@ const COMMON_VALIDATORS: ValidatorSet = {
|
||||
export type InputOptions = ValidatedOptions;
|
||||
|
||||
export type ValidatedOptions = {
|
||||
cwd?: string,
|
||||
filename?: string,
|
||||
filenameRelative?: string,
|
||||
babelrc?: boolean,
|
||||
code?: boolean,
|
||||
ast?: boolean,
|
||||
inputSourceMap?: RootInputSourceMapOption,
|
||||
envName?: string,
|
||||
|
||||
extends?: string,
|
||||
env?: EnvSet<ValidatedOptions>,
|
||||
@@ -180,8 +187,13 @@ export type EnvSet<T> = {
|
||||
export type IgnoreItem = string | Function | RegExp;
|
||||
export type IgnoreList = $ReadOnlyArray<IgnoreItem>;
|
||||
|
||||
export type PluginOptions = {} | void | false;
|
||||
export type PluginTarget = string | {} | Function;
|
||||
export type PluginItem = PluginTarget | [PluginTarget, {} | void];
|
||||
export type PluginItem =
|
||||
| Plugin
|
||||
| PluginTarget
|
||||
| [PluginTarget, PluginOptions]
|
||||
| [PluginTarget, PluginOptions, string];
|
||||
export type PluginList = $ReadOnlyArray<PluginItem>;
|
||||
|
||||
export type SourceMapsOption = boolean | "inline" | "both";
|
||||
@@ -201,6 +213,9 @@ export function validate(type: OptionsType, opts: {}): ValidatedOptions {
|
||||
if (type !== "arguments" && ROOT_VALIDATORS[key]) {
|
||||
throw new Error(`.${key} is only allowed in root programmatic options`);
|
||||
}
|
||||
if (type === "env" && key === "env") {
|
||||
throw new Error(`.${key} is not allowed inside another env block`);
|
||||
}
|
||||
|
||||
const validator =
|
||||
COMMON_VALIDATORS[key] ||
|
||||
|
||||
@@ -8,13 +8,14 @@ export default function transformFileSync(
|
||||
filename: string,
|
||||
opts: ?InputOptions,
|
||||
): FileResult | null {
|
||||
let options;
|
||||
if (opts == null) {
|
||||
opts = { filename };
|
||||
options = { filename };
|
||||
} else if (opts && typeof opts === "object") {
|
||||
opts = Object.assign(opts, { filename });
|
||||
options = Object.assign({}, opts, { filename });
|
||||
}
|
||||
|
||||
const config = loadConfig(opts);
|
||||
const config = loadConfig(options);
|
||||
if (config === null) return null;
|
||||
|
||||
return runSync(config, fs.readFileSync(filename, "utf8"));
|
||||
|
||||
@@ -10,21 +10,22 @@ type TransformFile = {
|
||||
};
|
||||
|
||||
export default ((function transformFile(filename, opts, callback) {
|
||||
let options;
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
opts = undefined;
|
||||
}
|
||||
|
||||
if (opts == null) {
|
||||
opts = { filename };
|
||||
options = { filename };
|
||||
} else if (opts && typeof opts === "object") {
|
||||
opts = Object.assign(opts, { filename });
|
||||
options = Object.assign({}, opts, { filename });
|
||||
}
|
||||
|
||||
process.nextTick(() => {
|
||||
let cfg;
|
||||
try {
|
||||
cfg = loadConfig(opts);
|
||||
cfg = loadConfig(options);
|
||||
if (cfg === null) return callback(null, null);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -38,6 +38,15 @@ export default function generateCode(
|
||||
result = generate(ast, opts.generatorOpts, code);
|
||||
} else if (results.length === 1) {
|
||||
result = results[0];
|
||||
|
||||
if (typeof result.then === "function") {
|
||||
throw new Error(
|
||||
`You appear to be using an async parser plugin, ` +
|
||||
`which your current version of Babel does not support. ` +
|
||||
`If you're using a published plugin, ` +
|
||||
`you may need to upgrade your @babel/core version.`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error("More than one plugin attempted to override codegen.");
|
||||
}
|
||||
|
||||
@@ -86,7 +86,18 @@ function transformFile(file: File, pluginPasses: PluginPasses): void {
|
||||
|
||||
for (const [plugin, pass] of passPairs) {
|
||||
const fn = plugin.pre;
|
||||
if (fn) fn.call(pass, file);
|
||||
if (fn) {
|
||||
const result = fn.call(pass, file);
|
||||
|
||||
if (isThenable(result)) {
|
||||
throw new Error(
|
||||
`You appear to be using an plugin with an async .pre, ` +
|
||||
`which your current version of Babel does not support.` +
|
||||
`If you're using a published plugin, you may need to upgrade ` +
|
||||
`your @babel/core version.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// merge all plugin visitors into a single visitor
|
||||
@@ -99,7 +110,26 @@ function transformFile(file: File, pluginPasses: PluginPasses): void {
|
||||
|
||||
for (const [plugin, pass] of passPairs) {
|
||||
const fn = plugin.post;
|
||||
if (fn) fn.call(pass, file);
|
||||
if (fn) {
|
||||
const result = fn.call(pass, file);
|
||||
|
||||
if (isThenable(result)) {
|
||||
throw new Error(
|
||||
`You appear to be using an plugin with an async .post, ` +
|
||||
`which your current version of Babel does not support.` +
|
||||
`If you're using a published plugin, you may need to upgrade ` +
|
||||
`your @babel/core version.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isThenable(val: mixed): boolean {
|
||||
return (
|
||||
!!val &&
|
||||
(typeof val === "object" || typeof val === "function") &&
|
||||
typeof val.then === "function"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,14 @@ function parser(pluginPasses, options, code) {
|
||||
if (results.length === 0) {
|
||||
return parse(code, options.parserOpts);
|
||||
} else if (results.length === 1) {
|
||||
if (typeof results[0].then === "function") {
|
||||
throw new Error(
|
||||
`You appear to be using an async codegen plugin, ` +
|
||||
`which your current version of Babel does not support. ` +
|
||||
`If you're using a published plugin, you may need to upgrade ` +
|
||||
`your @babel/core version.`,
|
||||
);
|
||||
}
|
||||
return results[0];
|
||||
}
|
||||
throw new Error("More than one plugin attempted to override parsing.");
|
||||
|
||||
@@ -41,9 +41,9 @@ export default function normalizeOptions(config: ResolvedConfig): {} {
|
||||
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
|
||||
retainLines: opts.retainLines,
|
||||
comments,
|
||||
shouldPrintComment: opts.shouldPrintComment,
|
||||
compact,
|
||||
minified: opts.minified,
|
||||
concise: opts.concise,
|
||||
|
||||
// Source-map generation flags.
|
||||
sourceMaps,
|
||||
|
||||
@@ -118,26 +118,33 @@ describe("api", function() {
|
||||
});
|
||||
|
||||
it("transformFile", function(done) {
|
||||
babel.transformFile(
|
||||
__dirname + "/fixtures/api/file.js",
|
||||
{
|
||||
babelrc: false,
|
||||
},
|
||||
function(err, res) {
|
||||
if (err) return done(err);
|
||||
assert.equal(res.code, "foo();");
|
||||
done();
|
||||
},
|
||||
);
|
||||
const options = {
|
||||
babelrc: false,
|
||||
};
|
||||
Object.freeze(options);
|
||||
babel.transformFile(__dirname + "/fixtures/api/file.js", options, function(
|
||||
err,
|
||||
res,
|
||||
) {
|
||||
if (err) return done(err);
|
||||
assert.equal(res.code, "foo();");
|
||||
// keep user options untouched
|
||||
assert.deepEqual(options, { babelrc: false });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("transformFileSync", function() {
|
||||
const options = {
|
||||
babelrc: false,
|
||||
};
|
||||
Object.freeze(options);
|
||||
assert.equal(
|
||||
babel.transformFileSync(__dirname + "/fixtures/api/file.js", {
|
||||
babelrc: false,
|
||||
}).code,
|
||||
babel.transformFileSync(__dirname + "/fixtures/api/file.js", options)
|
||||
.code,
|
||||
"foo();",
|
||||
);
|
||||
assert.deepEqual(options, { babelrc: false });
|
||||
});
|
||||
|
||||
it("options throw on falsy true", function() {
|
||||
@@ -296,12 +303,6 @@ describe("api", function() {
|
||||
development: {
|
||||
passPerPreset: true,
|
||||
presets: [pushPreset("argthree"), pushPreset("argfour")],
|
||||
env: {
|
||||
development: {
|
||||
passPerPreset: true,
|
||||
presets: [pushPreset("argfive"), pushPreset("argsix")],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -309,32 +310,30 @@ describe("api", function() {
|
||||
assert.equal(
|
||||
result.code,
|
||||
[
|
||||
"argtwo;",
|
||||
"argone;",
|
||||
"eleven;",
|
||||
"twelve;",
|
||||
"thirteen;",
|
||||
"fourteen;",
|
||||
"seventeen;",
|
||||
"eighteen;",
|
||||
"one;",
|
||||
"two;",
|
||||
"eleven;",
|
||||
"twelve;",
|
||||
"argtwo;",
|
||||
"argone;",
|
||||
"five;",
|
||||
"six;",
|
||||
"three;",
|
||||
"four;",
|
||||
"seventeen;",
|
||||
"eighteen;",
|
||||
"nineteen;",
|
||||
"twenty;",
|
||||
"thirteen;",
|
||||
"fourteen;",
|
||||
"fifteen;",
|
||||
"sixteen;",
|
||||
"argfive;",
|
||||
"argsix;",
|
||||
"argthree;",
|
||||
"argfour;",
|
||||
"seven;",
|
||||
"eight;",
|
||||
"nine;",
|
||||
"ten;",
|
||||
"argthree;",
|
||||
"argfour;",
|
||||
].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -19,23 +19,6 @@ describe("caching API", () => {
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow permacaching with cache(true)", () => {
|
||||
let count = 0;
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
cache(true);
|
||||
return { arg, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow disabling caching with .never()", () => {
|
||||
let count = 0;
|
||||
|
||||
@@ -55,25 +38,6 @@ describe("caching API", () => {
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow disabling caching with cache(false)", () => {
|
||||
let count = 0;
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
cache(false);
|
||||
return { arg, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 0 });
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 1 });
|
||||
assert.notEqual(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 4 });
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 5 });
|
||||
assert.notEqual(fn("two"), fn("two"));
|
||||
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow caching based on a value with .using(fn)", () => {
|
||||
let count = 0;
|
||||
let other = "default";
|
||||
@@ -115,47 +79,6 @@ describe("caching API", () => {
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow caching based on a value with cache(fn)", () => {
|
||||
let count = 0;
|
||||
let other = "default";
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
const val = cache(() => other);
|
||||
|
||||
return { arg, val, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "default", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "default", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "new";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "new", count: 2 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "new", count: 3 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "default";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "default", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "default", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "new";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "new", count: 2 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "new", count: 3 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow invalidation based on a value with .invalidate(fn)", () => {
|
||||
let count = 0;
|
||||
let other = "default";
|
||||
@@ -298,12 +221,6 @@ describe("caching API", () => {
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
});
|
||||
|
||||
it("should throw if caching is never configured and not defaulting", () => {
|
||||
const fn = makeStrongCache(() => {}, false /* autoPermacache */);
|
||||
|
||||
assert.throws(() => fn(), /Error: Caching was left unconfigured./);
|
||||
});
|
||||
|
||||
it("should auto-permacache by default", () => {
|
||||
let count = 0;
|
||||
|
||||
@@ -410,4 +327,89 @@ describe("caching API", () => {
|
||||
/Cannot change caching after evaluation/,
|
||||
);
|
||||
});
|
||||
|
||||
describe("simple", () => {
|
||||
it("should allow permacaching with cache(true)", () => {
|
||||
let count = 0;
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
cache = cache.simple();
|
||||
|
||||
cache(true);
|
||||
return { arg, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow disabling caching with cache(false)", () => {
|
||||
let count = 0;
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
cache = cache.simple();
|
||||
|
||||
cache(false);
|
||||
return { arg, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 0 });
|
||||
assert.deepEqual(fn("one"), { arg: "one", count: 1 });
|
||||
assert.notEqual(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 4 });
|
||||
assert.deepEqual(fn("two"), { arg: "two", count: 5 });
|
||||
assert.notEqual(fn("two"), fn("two"));
|
||||
|
||||
assert.notEqual(fn("one"), fn("two"));
|
||||
});
|
||||
|
||||
it("should allow caching based on a value with cache(fn)", () => {
|
||||
let count = 0;
|
||||
let other = "default";
|
||||
|
||||
const fn = makeStrongCache((arg, cache) => {
|
||||
cache = cache.simple();
|
||||
|
||||
const val = cache(() => other);
|
||||
|
||||
return { arg, val, count: count++ };
|
||||
});
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "default", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "default", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "new";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "new", count: 2 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "new", count: 3 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "default";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "default", count: 0 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "default", count: 1 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
|
||||
other = "new";
|
||||
|
||||
assert.deepEqual(fn("one"), { arg: "one", val: "new", count: 2 });
|
||||
assert.equal(fn("one"), fn("one"));
|
||||
|
||||
assert.deepEqual(fn("two"), { arg: "two", val: "new", count: 3 });
|
||||
assert.equal(fn("two"), fn("two"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -42,10 +42,10 @@ describe("@babel/core config loading", () => {
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
expect(options1.plugins.map(p => p.key)).to.eql([
|
||||
"plugin6",
|
||||
"plugin5",
|
||||
"plugin1",
|
||||
"plugin2",
|
||||
"plugin6",
|
||||
"plugin5",
|
||||
"plugin4",
|
||||
"plugin3",
|
||||
]);
|
||||
@@ -86,7 +86,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2) {
|
||||
if (i === 0) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -99,7 +99,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options3.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2 || i === 5) {
|
||||
if (i === 0 || i === 5) {
|
||||
expect(options3.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options3.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -150,7 +150,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 2 || i === 3 || i === 4 || i === 5 || i === 6) {
|
||||
if (i === 0 || i === 1 || i === 4 || i === 5 || i === 6) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -185,7 +185,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
if (i === 0) {
|
||||
if (i === 2) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -205,7 +205,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
if (i === 1) {
|
||||
if (i === 3) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -224,7 +224,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 0) {
|
||||
if (i === 2) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
@@ -243,7 +243,7 @@ describe("@babel/core config loading", () => {
|
||||
expect(options2.plugins.length).to.equal(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options1.plugins.length; i++) {
|
||||
if (i === 1) {
|
||||
if (i === 3) {
|
||||
expect(options2.plugins[i]).not.to.equal(options1.plugins[i]);
|
||||
} else {
|
||||
expect(options2.plugins[i]).to.equal(options1.plugins[i]);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
root-ignore
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"plugins": ["root"],
|
||||
"extends": "./extended.babelrc.json"
|
||||
}
|
||||
@@ -18,4 +18,5 @@ seventeen.js
|
||||
eighteen.js
|
||||
nineteen.js
|
||||
twenty.js
|
||||
plugin.js
|
||||
|
||||
**/plugin.js
|
||||
|
||||
@@ -2,6 +2,8 @@ module.exports = function(api) {
|
||||
api.env();
|
||||
|
||||
return {
|
||||
comments: false,
|
||||
plugins: [
|
||||
require("./plugin"),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
comments: false,
|
||||
plugins: ["./plugin"],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"babel": {
|
||||
"comments": false
|
||||
"plugins": ["./plugin"]
|
||||
}
|
||||
}
|
||||
|
||||
3
packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js
vendored
Normal file
3
packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
1
packages/babel-core/test/fixtures/config/config-files/.babelignore
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/.babelignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
# Placeholder so the monorepo ignore isn't accessed
|
||||
1
packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
src.js
|
||||
1
packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{45
|
||||
3
packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
throw new Error("Babelrc threw an error");
|
||||
};
|
||||
3
packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
comments: true,
|
||||
};
|
||||
3
packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
comments: true,
|
||||
}
|
||||
1
packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {};
|
||||
1
packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {};
|
||||
1
packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
3
packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"babel": {235
|
||||
}
|
||||
3
packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
comments: true,
|
||||
}
|
||||
1
packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
5
packages/babel-core/test/fixtures/config/config-files/pkg/package.json
vendored
Normal file
5
packages/babel-core/test/fixtures/config/config-files/pkg/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"babel": {
|
||||
"comments": true
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"dir2"
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
{
|
||||
"name": "application-name",
|
||||
"version": "0.0.1"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"plugins": ["env-base"],
|
||||
"env": {
|
||||
"foo": {
|
||||
"plugins": ["env-foo"]
|
||||
},
|
||||
"bar": {
|
||||
"plugins": ["env-bar"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"extended"
|
||||
]
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
ignore: [
|
||||
"*",
|
||||
"!folder",
|
||||
],
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
# Blank .gitignore to ensure this directory exists.
|
||||
!.gitignore
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
ignore: [
|
||||
"*",
|
||||
"!src.js",
|
||||
],
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var plugins = ["foo", "bar"];
|
||||
|
||||
exports.default = {
|
||||
plugins: plugins
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,2 +0,0 @@
|
||||
throw new Error("Something bad happened!");
|
||||
module.exports = {}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = '';
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = null;
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,6 +0,0 @@
|
||||
var plugins = ["foo", "bar"];
|
||||
|
||||
module.exports = {
|
||||
extends: "../extended.babelrc.json",
|
||||
plugins: plugins
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,7 +0,0 @@
|
||||
module.exports = function(api) {
|
||||
api.cache(true);
|
||||
|
||||
return {
|
||||
compact: true,
|
||||
};
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
var plugins = ["foo", "bar"];
|
||||
|
||||
module.exports = {
|
||||
plugins: plugins
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
// empty
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"plugins": [
|
||||
"json"
|
||||
]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
plugins: [
|
||||
"js"
|
||||
]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user