Compare commits
46 Commits
v7.0.0-rc.
...
v7.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cada040bec | ||
|
|
1f9b2a5c41 | ||
|
|
39fa102ee8 | ||
|
|
e841ccca34 | ||
|
|
4249dbc8ea | ||
|
|
a7cc3325cd | ||
|
|
023044c1d4 | ||
|
|
22bcfbe469 | ||
|
|
47e05d70f3 | ||
|
|
c5e3b6d4bc | ||
|
|
b04de1196a | ||
|
|
d07cef244e | ||
|
|
6c68ca8e0a | ||
|
|
f1d774b34f | ||
|
|
8874c5c481 | ||
|
|
b439013cd4 | ||
|
|
f8b0a5579f | ||
|
|
2a4f162366 | ||
|
|
55295cc545 | ||
|
|
59e9c6322b | ||
|
|
0fd3da110d | ||
|
|
d60c5e1736 | ||
|
|
90bebe7186 | ||
|
|
8d6ed7e0aa | ||
|
|
8f4bae8ea4 | ||
|
|
2c3c12fdf7 | ||
|
|
25d2f59018 | ||
|
|
3a399d1eb9 | ||
|
|
c2a2e24965 | ||
|
|
ef68114d67 | ||
|
|
ca639b4262 | ||
|
|
7a51d72345 | ||
|
|
ab8555a867 | ||
|
|
0136a26af7 | ||
|
|
c75a00bd56 | ||
|
|
ffa8e6cbae | ||
|
|
5043ec78bc | ||
|
|
3989213e37 | ||
|
|
d79b5eeeff | ||
|
|
1e0b649485 | ||
|
|
8c65230258 | ||
|
|
427aff559f | ||
|
|
de16ac08be | ||
|
|
0a958861c9 | ||
|
|
904bcaffe3 | ||
|
|
e855987c51 |
@@ -5,6 +5,7 @@
|
||||
.*/codemods/.*/lib
|
||||
.*/codemods/.*/test
|
||||
.*/node_modules/conventional-changelog-core/
|
||||
.*/node_modules/module-deps/
|
||||
|
||||
[include]
|
||||
packages/*/src
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,9 @@
|
||||
.DS_Store
|
||||
/node_modules
|
||||
/packages/*/node_modules
|
||||
/packages/*/LICENSE
|
||||
!/packages/babel-parser/LICENSE
|
||||
!/packages/babel-plugin-transform-object-assign/LICENSE
|
||||
*.log
|
||||
*.cache
|
||||
/build
|
||||
|
||||
4
Makefile
4
Makefile
@@ -104,6 +104,9 @@ test-test262-ci: bootstrap test-test262
|
||||
test-test262-update-whitelist:
|
||||
node scripts/tests/test262/run_babel_parser_test262.js --update-whitelist
|
||||
|
||||
clone-license:
|
||||
./scripts/clone-license.sh
|
||||
|
||||
publish:
|
||||
git pull --rebase
|
||||
make clean-lib
|
||||
@@ -112,6 +115,7 @@ publish:
|
||||
rm -rf packages/babel-runtime-corejs2/core-js
|
||||
BABEL_ENV=production make build-dist
|
||||
make test
|
||||
make clone-license
|
||||
# not using lerna independent mode atm, so only update packages that have changed since we use ^
|
||||
# --only-explicit-updates
|
||||
./node_modules/.bin/lerna publish --force-publish=* --exact --skip-temp-tag
|
||||
|
||||
@@ -72,6 +72,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
||||
|
||||
<a href="http://teamextension.io/" target="_blank"><img src="https://teamextension.io/dist/img/logo/te-logo-compact.png" height="64"></a>
|
||||
<a href="https://webflow.com/" target="_blank"><img src="https://opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F4a5024b0-8cf2-11e7-b1a2-b30b1de1463c.png&height=64"></a>
|
||||
<a href="https://issue.sh/?utm_medium=github&utm_campaign=babel" target="_blank"><img src="https://user-images.githubusercontent.com/5557143/43912065-c8cdff78-9c33-11e8-829a-0b4166ccc215.png"></a>
|
||||
<p><a href="https://twitter.com/mikesherov">Mike Sherov</a></p>
|
||||
|
||||
## Intro
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-object-assign-to-object-spread",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Transforms Object.assign into object spread syntax",
|
||||
"repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-object-assign-to-object-spread",
|
||||
"license": "MIT",
|
||||
@@ -10,14 +10,14 @@
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-rc.0"
|
||||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-optional-catch-binding",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Remove unused catch bindings",
|
||||
"repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-remove-unused-catch-binding",
|
||||
"license": "MIT",
|
||||
@@ -10,13 +10,13 @@
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-rc.0"
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"lerna": "2.11.0",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"cacheDir": ".changelog",
|
||||
|
||||
32
package.json
32
package.json
@@ -10,33 +10,33 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.0.0-beta.52",
|
||||
"@babel/core": "7.0.0-beta.52",
|
||||
"@babel/plugin-transform-runtime": "7.0.0-beta.52",
|
||||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.52",
|
||||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.52",
|
||||
"@babel/plugin-proposal-numeric-separator": "7.0.0-beta.52",
|
||||
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.52",
|
||||
"@babel/preset-env": "7.0.0-beta.52",
|
||||
"@babel/preset-flow": "7.0.0-beta.52",
|
||||
"@babel/register": "7.0.0-beta.52",
|
||||
"@babel/runtime": "7.0.0-beta.52",
|
||||
"@babel/cli": "7.0.0-rc.2",
|
||||
"@babel/core": "7.0.0-rc.2",
|
||||
"@babel/plugin-transform-runtime": "7.0.0-rc.2",
|
||||
"@babel/plugin-proposal-class-properties": "7.0.0-rc.2",
|
||||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-rc.2",
|
||||
"@babel/plugin-proposal-numeric-separator": "7.0.0-rc.2",
|
||||
"@babel/plugin-transform-modules-commonjs": "7.0.0-rc.2",
|
||||
"@babel/preset-env": "7.0.0-rc.2",
|
||||
"@babel/preset-flow": "7.0.0-rc.2",
|
||||
"@babel/register": "7.0.0-rc.2",
|
||||
"@babel/runtime": "7.0.0-rc.2",
|
||||
"babel-core": "^7.0.0-0",
|
||||
"babel-eslint": "^8.2.6",
|
||||
"babel-jest": "^23.4.0",
|
||||
"babel-loader": "8.0.0-beta.0",
|
||||
"babel-loader": "8.0.0-beta.4",
|
||||
"babel-plugin-transform-charcodes": "^0.1.0",
|
||||
"browserify": "^13.1.1",
|
||||
"browserify": "^16.2.2",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chalk": "^2.3.2",
|
||||
"charcodes": "^0.1.0",
|
||||
"derequire": "^2.0.2",
|
||||
"enhanced-resolve": "^3.0.0",
|
||||
"eslint": "^5.1.0",
|
||||
"eslint": "^5.3.0",
|
||||
"eslint-config-babel": "^7.0.2",
|
||||
"eslint-plugin-flowtype": "^2.50.0",
|
||||
"eslint-plugin-prettier": "^2.6.2",
|
||||
"flow-bin": "^0.76.0",
|
||||
"flow-bin": "^0.79.0",
|
||||
"graceful-fs": "^4.1.11",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-babel": "^8.0.0-beta.2",
|
||||
@@ -72,7 +72,7 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6.9.0 <= 11.0.0-0",
|
||||
"npm": ">= 2.x <= 5.x",
|
||||
"npm": ">= 3.x <= 6.x",
|
||||
"yarn": ">=0.27.5 || >=1.0.0-20170811"
|
||||
},
|
||||
"lint-staged": {
|
||||
|
||||
@@ -14,7 +14,7 @@ A monorepo, muhahahahahaha. See the [monorepo design doc](/doc/design/monorepo.m
|
||||
| Package | Version | Dependencies |
|
||||
|--------|-------|------------|
|
||||
| [`@babel/core`](/packages/babel-core) | [](https://www.npmjs.com/package/@babel/core) | [](https://david-dm.org/babel/babel?path=packages/babel-core) |
|
||||
| [`@babel/parser`](/packages/@babel/parser) | [](https://www.npmjs.com/package/@babel/parser) | [](https://david-dm.org/babel/babel?path=packages/babel-parser) |
|
||||
| [`@babel/parser`](/packages/babel-parser) | [](https://www.npmjs.com/package/@babel/parser) | [](https://david-dm.org/babel/babel?path=packages/babel-parser) |
|
||||
| [`@babel/traverse`](/packages/babel-traverse) | [](https://www.npmjs.com/package/@babel/traverse) | [](https://david-dm.org/babel/babel?path=packages/babel-traverse) |
|
||||
| [`@babel/generator`](/packages/babel-generator) | [](https://www.npmjs.com/package/@babel/generator) | [](https://david-dm.org/babel/babel?path=packages/babel-generator) |
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/cli",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -23,18 +23,18 @@
|
||||
"lodash": "^4.17.10",
|
||||
"mkdirp": "^0.5.1",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"slash": "^2.0.0",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"chokidar": "^2.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.3"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel.js",
|
||||
|
||||
@@ -49,9 +49,14 @@ export function addSourceMappingUrl(code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
}
|
||||
|
||||
const CALLER = {
|
||||
name: "@babel/cli",
|
||||
};
|
||||
|
||||
export function transform(filename, code, opts) {
|
||||
opts = {
|
||||
...opts,
|
||||
caller: CALLER,
|
||||
filename,
|
||||
};
|
||||
|
||||
@@ -64,6 +69,11 @@ export function transform(filename, code, opts) {
|
||||
}
|
||||
|
||||
export function compile(filename, opts) {
|
||||
opts = {
|
||||
...opts,
|
||||
caller: CALLER,
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
babel.transformFile(filename, opts, (err, result) => {
|
||||
if (err) reject(err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/code-frame",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,7 +8,7 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-code-frame",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/highlight": "7.0.0-rc.0"
|
||||
"@babel/highlight": "7.0.0-rc.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chalk": "^2.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/core",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel compiler core.",
|
||||
"main": "lib/index.js",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
@@ -30,13 +30,13 @@
|
||||
"./lib/transform-file.js": "./lib/transform-file-browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "7.0.0-rc.0",
|
||||
"@babel/generator": "7.0.0-rc.0",
|
||||
"@babel/helpers": "7.0.0-rc.0",
|
||||
"@babel/parser": "7.0.0-rc.0",
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"@babel/code-frame": "7.0.0-rc.3",
|
||||
"@babel/generator": "7.0.0-rc.3",
|
||||
"@babel/helpers": "7.0.0-rc.3",
|
||||
"@babel/parser": "7.0.0-rc.3",
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"debug": "^3.1.0",
|
||||
"json5": "^0.5.0",
|
||||
@@ -46,7 +46,7 @@
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.0",
|
||||
"@babel/register": "7.0.0-rc.0"
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.3",
|
||||
"@babel/register": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,12 +206,29 @@ function makeSimpleConfigurator(
|
||||
return;
|
||||
}
|
||||
|
||||
return cache.using(val);
|
||||
return cache.using(() => assertSimpleType(val()));
|
||||
}
|
||||
cacheFn.forever = () => cache.forever();
|
||||
cacheFn.never = () => cache.never();
|
||||
cacheFn.using = cb => cache.using(() => cb());
|
||||
cacheFn.invalidate = cb => cache.invalidate(() => cb());
|
||||
cacheFn.using = cb => cache.using(() => assertSimpleType(cb()));
|
||||
cacheFn.invalidate = cb => cache.invalidate(() => assertSimpleType(cb()));
|
||||
|
||||
return (cacheFn: any);
|
||||
}
|
||||
|
||||
// Types are limited here so that in the future these values can be used
|
||||
// as part of Babel's caching logic.
|
||||
type SimpleType = string | boolean | number | null | void;
|
||||
export function assertSimpleType(value: mixed): SimpleType {
|
||||
if (
|
||||
value != null &&
|
||||
typeof value !== "string" &&
|
||||
typeof value !== "boolean" &&
|
||||
typeof value !== "number"
|
||||
) {
|
||||
throw new Error(
|
||||
"Cache keys must be either string, boolean, number, null, or undefined.",
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type IgnoreList,
|
||||
type ConfigApplicableTest,
|
||||
type BabelrcSearch,
|
||||
type CallerMetadata,
|
||||
} from "./validation/options";
|
||||
import pathPatternToRegex from "./pattern-to-regex";
|
||||
|
||||
@@ -50,12 +51,27 @@ export type ConfigContext = {
|
||||
cwd: string,
|
||||
root: string,
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a config chain for a given preset.
|
||||
*/
|
||||
export const buildPresetChain: (
|
||||
export function buildPresetChain(
|
||||
arg: PresetInstance,
|
||||
context: *,
|
||||
): ConfigChain | null {
|
||||
const chain = buildPresetChainWalker(arg, context);
|
||||
if (!chain) return null;
|
||||
|
||||
return {
|
||||
plugins: dedupDescriptors(chain.plugins),
|
||||
presets: dedupDescriptors(chain.presets),
|
||||
options: chain.options,
|
||||
};
|
||||
}
|
||||
|
||||
export const buildPresetChainWalker: (
|
||||
arg: PresetInstance,
|
||||
context: *,
|
||||
) => * = makeChainWalker({
|
||||
@@ -128,9 +144,14 @@ export function buildRootChain(
|
||||
|
||||
let configFile;
|
||||
if (typeof opts.configFile === "string") {
|
||||
configFile = loadConfig(opts.configFile, context.cwd, context.envName);
|
||||
configFile = loadConfig(
|
||||
opts.configFile,
|
||||
context.cwd,
|
||||
context.envName,
|
||||
context.caller,
|
||||
);
|
||||
} else if (opts.configFile !== false) {
|
||||
configFile = findRootConfig(context.root, context.envName);
|
||||
configFile = findRootConfig(context.root, context.envName, context.caller);
|
||||
}
|
||||
|
||||
let { babelrc, babelrcRoots } = opts;
|
||||
@@ -234,7 +255,7 @@ function babelrcLoadEnabled(
|
||||
if (typeof pat === "string") pat = pathPatternToRegex(pat, context.cwd);
|
||||
|
||||
return pkgData.directories.some(directory => {
|
||||
return matchPattern(pat, context.cwd, directory);
|
||||
return matchPattern(pat, context.cwd, directory, context);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -449,7 +470,12 @@ function mergeExtendsChain(
|
||||
): boolean {
|
||||
if (opts.extends === undefined) return true;
|
||||
|
||||
const file = loadConfig(opts.extends, dirname, context.envName);
|
||||
const file = loadConfig(
|
||||
opts.extends,
|
||||
dirname,
|
||||
context.envName,
|
||||
context.caller,
|
||||
);
|
||||
|
||||
if (files.has(file)) {
|
||||
throw new Error(
|
||||
@@ -527,7 +553,7 @@ function dedupDescriptors(
|
||||
): Array<UnloadedDescriptor> {
|
||||
const map: Map<
|
||||
Function,
|
||||
Map<string | void, { value: UnloadedDescriptor | null }>,
|
||||
Map<string | void, { value: UnloadedDescriptor }>,
|
||||
> = new Map();
|
||||
|
||||
const descriptors = [];
|
||||
@@ -542,16 +568,12 @@ function dedupDescriptors(
|
||||
}
|
||||
let desc = nameMap.get(item.name);
|
||||
if (!desc) {
|
||||
desc = { value: null };
|
||||
desc = { value: item };
|
||||
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;
|
||||
}
|
||||
@@ -561,7 +583,7 @@ function dedupDescriptors(
|
||||
}
|
||||
|
||||
return descriptors.reduce((acc, desc) => {
|
||||
if (desc.value) acc.push(desc.value);
|
||||
acc.push(desc.value);
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
@@ -633,12 +655,23 @@ function matchesPatterns(
|
||||
dirname: string,
|
||||
): boolean {
|
||||
return patterns.some(pattern =>
|
||||
matchPattern(pattern, dirname, context.filename),
|
||||
matchPattern(pattern, dirname, context.filename, context),
|
||||
);
|
||||
}
|
||||
|
||||
function matchPattern(pattern, dirname, pathToTest): boolean {
|
||||
if (typeof pattern === "function") return !!pattern(pathToTest);
|
||||
function matchPattern(
|
||||
pattern,
|
||||
dirname,
|
||||
pathToTest,
|
||||
context: ConfigContext,
|
||||
): boolean {
|
||||
if (typeof pattern === "function") {
|
||||
return !!pattern(pathToTest, {
|
||||
dirname,
|
||||
envName: context.envName,
|
||||
caller: context.caller,
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof pathToTest !== "string") {
|
||||
throw new Error(
|
||||
|
||||
@@ -41,6 +41,22 @@ export type UnloadedDescriptor = {
|
||||
} | void,
|
||||
};
|
||||
|
||||
function isEqualDescriptor(
|
||||
a: UnloadedDescriptor,
|
||||
b: UnloadedDescriptor,
|
||||
): boolean {
|
||||
return (
|
||||
a.name === b.name &&
|
||||
a.value === b.value &&
|
||||
a.options === b.options &&
|
||||
a.dirname === b.dirname &&
|
||||
a.alias === b.alias &&
|
||||
a.ownPass === b.ownPass &&
|
||||
(a.file && a.file.request) === (b.file && b.file.request) &&
|
||||
(a.file && a.file.resolved) === (b.file && b.file.resolved)
|
||||
);
|
||||
}
|
||||
|
||||
export type ValidatedFile = {
|
||||
filepath: string,
|
||||
dirname: string,
|
||||
@@ -50,7 +66,7 @@ export type ValidatedFile = {
|
||||
/**
|
||||
* Create a set of descriptors from a given options object, preserving
|
||||
* descriptor identity based on the identity of the plugin/preset arrays
|
||||
* themselves.
|
||||
* themselves, and potentially on the identity of the plugins/presets + options.
|
||||
*/
|
||||
export function createCachedDescriptors(
|
||||
dirname: string,
|
||||
@@ -113,26 +129,82 @@ export function createUncachedDescriptors(
|
||||
};
|
||||
}
|
||||
|
||||
const PRESET_DESCRIPTOR_CACHE = new WeakMap();
|
||||
const createCachedPresetDescriptors = makeWeakCache(
|
||||
(items: PluginList, cache: CacheConfigurator<string>) => {
|
||||
const dirname = cache.using(dir => dir);
|
||||
return makeStrongCache((alias: string) =>
|
||||
makeStrongCache((passPerPreset: boolean) =>
|
||||
createPresetDescriptors(items, dirname, alias, passPerPreset),
|
||||
createPresetDescriptors(items, dirname, alias, passPerPreset).map(
|
||||
// Items are cached using the overall preset array identity when
|
||||
// possibly, but individual descriptors are also cached if a match
|
||||
// can be found in the previously-used descriptor lists.
|
||||
desc => loadCachedDescriptor(PRESET_DESCRIPTOR_CACHE, desc),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
const PLUGIN_DESCRIPTOR_CACHE = new WeakMap();
|
||||
const createCachedPluginDescriptors = makeWeakCache(
|
||||
(items: PluginList, cache: CacheConfigurator<string>) => {
|
||||
const dirname = cache.using(dir => dir);
|
||||
return makeStrongCache((alias: string) =>
|
||||
createPluginDescriptors(items, dirname, alias),
|
||||
createPluginDescriptors(items, dirname, alias).map(
|
||||
// Items are cached using the overall plugin array identity when
|
||||
// possibly, but individual descriptors are also cached if a match
|
||||
// can be found in the previously-used descriptor lists.
|
||||
desc => loadCachedDescriptor(PLUGIN_DESCRIPTOR_CACHE, desc),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* When no options object is given in a descriptor, this object is used
|
||||
* as a WeakMap key in order to have consistent identity.
|
||||
*/
|
||||
const DEFAULT_OPTIONS = {};
|
||||
|
||||
/**
|
||||
* Given the cache and a descriptor, returns a matching descriptor from the
|
||||
* cache, or else returns the input descriptor and adds it to the cache for
|
||||
* next time.
|
||||
*/
|
||||
function loadCachedDescriptor(
|
||||
cache: WeakMap<{} | Function, WeakMap<{}, Array<UnloadedDescriptor>>>,
|
||||
desc: UnloadedDescriptor,
|
||||
) {
|
||||
const { value, options = DEFAULT_OPTIONS } = desc;
|
||||
if (options === false) return desc;
|
||||
|
||||
let cacheByOptions = cache.get(value);
|
||||
if (!cacheByOptions) {
|
||||
cacheByOptions = new WeakMap();
|
||||
cache.set(value, cacheByOptions);
|
||||
}
|
||||
|
||||
let possibilities = cacheByOptions.get(options);
|
||||
if (!possibilities) {
|
||||
possibilities = [];
|
||||
cacheByOptions.set(options, possibilities);
|
||||
}
|
||||
|
||||
if (possibilities.indexOf(desc) === -1) {
|
||||
const matches = possibilities.filter(possibility =>
|
||||
isEqualDescriptor(possibility, desc),
|
||||
);
|
||||
if (matches.length > 0) {
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
possibilities.push(desc);
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
function createPresetDescriptors(
|
||||
items: PluginList,
|
||||
dirname: string,
|
||||
|
||||
@@ -14,6 +14,7 @@ import makeAPI from "../helpers/config-api";
|
||||
import { makeStaticFileCache } from "./utils";
|
||||
import pathPatternToRegex from "../pattern-to-regex";
|
||||
import type { FilePackageData, RelativeConfig, ConfigFile } from "./types";
|
||||
import type { CallerMetadata } from "../validation/options";
|
||||
|
||||
const debug = buildDebug("babel:config:loading:files:configuration");
|
||||
|
||||
@@ -26,6 +27,7 @@ const BABELIGNORE_FILENAME = ".babelignore";
|
||||
export function findRelativeConfig(
|
||||
packageData: FilePackageData,
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
): RelativeConfig {
|
||||
let config = null;
|
||||
let ignore = null;
|
||||
@@ -37,7 +39,7 @@ export function findRelativeConfig(
|
||||
config = [BABELRC_FILENAME, BABELRC_JS_FILENAME].reduce(
|
||||
(previousConfig: ConfigFile | null, name) => {
|
||||
const filepath = path.join(loc, name);
|
||||
const config = readConfig(filepath, envName);
|
||||
const config = readConfig(filepath, envName, caller);
|
||||
|
||||
if (config && previousConfig) {
|
||||
throw new Error(
|
||||
@@ -91,10 +93,11 @@ export function findRelativeConfig(
|
||||
export function findRootConfig(
|
||||
dirname: string,
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
): ConfigFile | null {
|
||||
const filepath = path.resolve(dirname, BABEL_CONFIG_JS_FILENAME);
|
||||
|
||||
const conf = readConfig(filepath, envName);
|
||||
const conf = readConfig(filepath, envName, caller);
|
||||
if (conf) {
|
||||
debug("Found root config %o in $o.", BABEL_CONFIG_JS_FILENAME, dirname);
|
||||
}
|
||||
@@ -105,10 +108,11 @@ export function loadConfig(
|
||||
name: string,
|
||||
dirname: string,
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
): ConfigFile {
|
||||
const filepath = resolve.sync(name, { basedir: dirname });
|
||||
|
||||
const conf = readConfig(filepath, envName);
|
||||
const conf = readConfig(filepath, envName, caller);
|
||||
if (!conf) {
|
||||
throw new Error(`Config file ${filepath} contains no configuration data`);
|
||||
}
|
||||
@@ -121,16 +125,22 @@ export function loadConfig(
|
||||
* 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, envName): ConfigFile | null {
|
||||
function readConfig(filepath, envName, caller): ConfigFile | null {
|
||||
return path.extname(filepath) === ".js"
|
||||
? readConfigJS(filepath, { envName })
|
||||
? readConfigJS(filepath, { envName, caller })
|
||||
: readConfigJSON5(filepath);
|
||||
}
|
||||
|
||||
const LOADING_CONFIGS = new Set();
|
||||
|
||||
const readConfigJS = makeStrongCache(
|
||||
(filepath, cache: CacheConfigurator<{ envName: string }>) => {
|
||||
(
|
||||
filepath,
|
||||
cache: CacheConfigurator<{
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
}>,
|
||||
) => {
|
||||
if (!fs.existsSync(filepath)) {
|
||||
cache.forever();
|
||||
return null;
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
FilePackageData,
|
||||
} from "./types";
|
||||
|
||||
import type { CallerMetadata } from "../validation/options";
|
||||
|
||||
export type { ConfigFile, IgnoreFile, RelativeConfig, FilePackageData };
|
||||
|
||||
export function findPackageData(filepath: string): FilePackageData {
|
||||
@@ -21,6 +23,7 @@ export function findPackageData(filepath: string): FilePackageData {
|
||||
export function findRelativeConfig(
|
||||
pkgData: FilePackageData, // eslint-disable-line no-unused-vars
|
||||
envName: string, // eslint-disable-line no-unused-vars
|
||||
caller: CallerMetadata | void, // eslint-disable-line no-unused-vars
|
||||
): RelativeConfig {
|
||||
return { pkg: null, config: null, ignore: null };
|
||||
}
|
||||
@@ -28,6 +31,7 @@ export function findRelativeConfig(
|
||||
export function findRootConfig(
|
||||
dirname: string, // eslint-disable-line no-unused-vars
|
||||
envName: string, // eslint-disable-line no-unused-vars
|
||||
caller: CallerMetadata | void, // eslint-disable-line no-unused-vars
|
||||
): ConfigFile | null {
|
||||
return null;
|
||||
}
|
||||
@@ -36,6 +40,7 @@ export function loadConfig(
|
||||
name: string,
|
||||
dirname: string,
|
||||
envName: string, // eslint-disable-line no-unused-vars
|
||||
caller: CallerMetadata | void, // eslint-disable-line no-unused-vars
|
||||
): ConfigFile {
|
||||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
|
||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
||||
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
|
||||
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
|
||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-plugin(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/;
|
||||
|
||||
export function resolvePlugin(name: string, dirname: string): string | null {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import type { UnloadedDescriptor } from "./config-descriptors";
|
||||
import traverse from "@babel/traverse";
|
||||
import { makeWeakCache, type CacheConfigurator } from "./caching";
|
||||
import { validate } from "./validation/options";
|
||||
import { validate, type CallerMetadata } from "./validation/options";
|
||||
import { validatePluginObject } from "./validation/plugins";
|
||||
import makeAPI from "./helpers/config-api";
|
||||
|
||||
@@ -41,6 +41,7 @@ export type PluginPasses = Array<PluginPassList>;
|
||||
// process 'ignore'/'only' and other filename-based logic.
|
||||
type SimpleContext = {
|
||||
envName: string,
|
||||
caller: CallerMetadata | void,
|
||||
};
|
||||
|
||||
export default function loadFullConfig(
|
||||
@@ -68,15 +69,21 @@ export default function loadFullConfig(
|
||||
},
|
||||
pass: Array<Plugin>,
|
||||
) {
|
||||
const plugins = config.plugins.map(descriptor => {
|
||||
return loadPluginDescriptor(descriptor, context);
|
||||
});
|
||||
const presets = config.presets.map(descriptor => {
|
||||
return {
|
||||
preset: loadPresetDescriptor(descriptor, context),
|
||||
pass: descriptor.ownPass ? [] : pass,
|
||||
};
|
||||
});
|
||||
const plugins = config.plugins.reduce((acc, descriptor) => {
|
||||
if (descriptor.options !== false) {
|
||||
acc.push(loadPluginDescriptor(descriptor, context));
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
const presets = config.presets.reduce((acc, descriptor) => {
|
||||
if (descriptor.options !== false) {
|
||||
acc.push({
|
||||
preset: loadPresetDescriptor(descriptor, context),
|
||||
pass: descriptor.ownPass ? [] : pass,
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
// resolve presets
|
||||
if (presets.length > 0) {
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
import semver from "semver";
|
||||
import { version as coreVersion } from "../../";
|
||||
import type { CacheConfigurator, SimpleCacheConfigurator } from "../caching";
|
||||
import {
|
||||
assertSimpleType,
|
||||
type CacheConfigurator,
|
||||
type SimpleCacheConfigurator,
|
||||
} from "../caching";
|
||||
|
||||
import type { CallerMetadata } from "../validation/options";
|
||||
|
||||
type EnvFunction = {
|
||||
(): string,
|
||||
@@ -20,12 +26,14 @@ export type PluginAPI = {
|
||||
};
|
||||
|
||||
export default function makeAPI(
|
||||
cache: CacheConfigurator<{ envName: string }>,
|
||||
cache: CacheConfigurator<{ envName: string, caller: CallerMetadata | void }>,
|
||||
): PluginAPI {
|
||||
const env: any = value =>
|
||||
cache.using(data => {
|
||||
if (typeof value === "undefined") return data.envName;
|
||||
if (typeof value === "function") return value(data.envName);
|
||||
if (typeof value === "function") {
|
||||
return assertSimpleType(value(data.envName));
|
||||
}
|
||||
if (!Array.isArray(value)) value = [value];
|
||||
|
||||
return value.some(entry => {
|
||||
@@ -36,12 +44,16 @@ export default function makeAPI(
|
||||
});
|
||||
});
|
||||
|
||||
const caller: any = cb =>
|
||||
cache.using(data => assertSimpleType(cb(data.caller)));
|
||||
|
||||
return {
|
||||
version: coreVersion,
|
||||
cache: cache.simple(),
|
||||
// Expose ".env()" so people can easily get the same env that we expose using the "env" key.
|
||||
env,
|
||||
async: () => false,
|
||||
caller,
|
||||
assertVersion,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -71,9 +71,11 @@ class ConfigItem {
|
||||
|
||||
/**
|
||||
* The options, if any, that were passed to the item.
|
||||
* Mutating this will lead to undefined behavior. If you need
|
||||
* Mutating this will lead to undefined behavior.
|
||||
*
|
||||
* "false" means that this item has been disabled.
|
||||
*/
|
||||
options: {} | void;
|
||||
options: {} | void | false;
|
||||
|
||||
/**
|
||||
* The directory that the options for this item are relative to.
|
||||
@@ -103,10 +105,6 @@ class ConfigItem {
|
||||
this._descriptor = descriptor;
|
||||
Object.defineProperty(this, "_descriptor", ({ enumerable: false }: any));
|
||||
|
||||
if (this._descriptor.options === false) {
|
||||
throw new Error("Assertion failure - unexpected false options");
|
||||
}
|
||||
|
||||
this.value = this._descriptor.value;
|
||||
this.options = this._descriptor.options;
|
||||
this.dirname = this._descriptor.dirname;
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function loadPrivatePartialConfig(
|
||||
|
||||
const args = inputOpts ? validate("arguments", inputOpts) : {};
|
||||
|
||||
const { envName = getEnv(), cwd = ".", root: rootDir = "." } = args;
|
||||
const { envName = getEnv(), cwd = ".", root: rootDir = ".", caller } = args;
|
||||
const absoluteCwd = path.resolve(cwd);
|
||||
const absoluteRootDir = path.resolve(absoluteCwd, rootDir);
|
||||
|
||||
@@ -40,6 +40,7 @@ export default function loadPrivatePartialConfig(
|
||||
cwd: absoluteCwd,
|
||||
root: absoluteRootDir,
|
||||
envName,
|
||||
caller,
|
||||
};
|
||||
|
||||
const configChain = buildRootChain(args, context);
|
||||
|
||||
@@ -13,16 +13,55 @@ import type {
|
||||
SourceTypeOption,
|
||||
CompactOption,
|
||||
RootInputSourceMapOption,
|
||||
NestingPath,
|
||||
CallerMetadata,
|
||||
} from "./options";
|
||||
|
||||
export type ValidatorSet = {
|
||||
[string]: Validator<any>,
|
||||
};
|
||||
|
||||
export type Validator<T> = (string, mixed) => T;
|
||||
export type Validator<T> = (OptionPath, mixed) => T;
|
||||
|
||||
export function msg(loc: NestingPath | GeneralPath) {
|
||||
switch (loc.type) {
|
||||
case "root":
|
||||
return ``;
|
||||
case "env":
|
||||
return `${msg(loc.parent)}.env["${loc.name}"]`;
|
||||
case "overrides":
|
||||
return `${msg(loc.parent)}.overrides[${loc.index}]`;
|
||||
case "option":
|
||||
return `${msg(loc.parent)}.${loc.name}`;
|
||||
case "access":
|
||||
return `${msg(loc.parent)}[${JSON.stringify(loc.name)}]`;
|
||||
default:
|
||||
throw new Error(`Assertion failure: Unknown type ${loc.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function access(loc: GeneralPath, name: string | number): AccessPath {
|
||||
return {
|
||||
type: "access",
|
||||
name,
|
||||
parent: loc,
|
||||
};
|
||||
}
|
||||
|
||||
export type OptionPath = $ReadOnly<{
|
||||
type: "option",
|
||||
name: string,
|
||||
parent: NestingPath,
|
||||
}>;
|
||||
type AccessPath = $ReadOnly<{
|
||||
type: "access",
|
||||
name: string | number,
|
||||
parent: GeneralPath,
|
||||
}>;
|
||||
type GeneralPath = OptionPath | AccessPath;
|
||||
|
||||
export function assertSourceMaps(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): SourceMapsOption | void {
|
||||
if (
|
||||
@@ -32,21 +71,24 @@ export function assertSourceMaps(
|
||||
value !== "both"
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key} must be a boolean, "inline", "both", or undefined`,
|
||||
`${msg(loc)} must be a boolean, "inline", "both", or undefined`,
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertCompact(key: string, value: mixed): CompactOption | void {
|
||||
export function assertCompact(
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): CompactOption | void {
|
||||
if (value !== undefined && typeof value !== "boolean" && value !== "auto") {
|
||||
throw new Error(`.${key} must be a boolean, "auto", or undefined`);
|
||||
throw new Error(`${msg(loc)} must be a boolean, "auto", or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertSourceType(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): SourceTypeOption | void {
|
||||
if (
|
||||
@@ -56,14 +98,49 @@ export function assertSourceType(
|
||||
value !== "unambiguous"
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key} must be "module", "script", "unambiguous", or undefined`,
|
||||
`${msg(loc)} must be "module", "script", "unambiguous", or undefined`,
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertCallerMetadata(
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): CallerMetadata | void {
|
||||
const obj = assertObject(loc, value);
|
||||
if (obj) {
|
||||
if (typeof obj[("name": string)] !== "string") {
|
||||
throw new Error(
|
||||
`${msg(loc)} set but does not contain "name" property string`,
|
||||
);
|
||||
}
|
||||
|
||||
for (const prop of Object.keys(obj)) {
|
||||
const propLoc = access(loc, prop);
|
||||
const value = obj[prop];
|
||||
if (
|
||||
value != null &&
|
||||
typeof value !== "boolean" &&
|
||||
typeof value !== "string" &&
|
||||
typeof value !== "number"
|
||||
) {
|
||||
// NOTE(logan): I'm limiting the type here so that we can guarantee that
|
||||
// the "caller" value will serialize to JSON nicely. We can always
|
||||
// allow more complex structures later though.
|
||||
throw new Error(
|
||||
`${msg(
|
||||
propLoc,
|
||||
)} must be null, undefined, a boolean, a string, or a number.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (value: any);
|
||||
}
|
||||
|
||||
export function assertInputSourceMap(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): RootInputSourceMapOption | void {
|
||||
if (
|
||||
@@ -71,75 +148,82 @@ export function assertInputSourceMap(
|
||||
typeof value !== "boolean" &&
|
||||
(typeof value !== "object" || !value)
|
||||
) {
|
||||
throw new Error(".inputSourceMap must be a boolean, object, or undefined");
|
||||
throw new Error(`${msg(loc)} must be a boolean, object, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertString(key: string, value: mixed): string | void {
|
||||
export function assertString(loc: GeneralPath, value: mixed): string | void {
|
||||
if (value !== undefined && typeof value !== "string") {
|
||||
throw new Error(`.${key} must be a string, or undefined`);
|
||||
throw new Error(`${msg(loc)} must be a string, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertFunction(key: string, value: mixed): Function | void {
|
||||
export function assertFunction(
|
||||
loc: GeneralPath,
|
||||
value: mixed,
|
||||
): Function | void {
|
||||
if (value !== undefined && typeof value !== "function") {
|
||||
throw new Error(`.${key} must be a function, or undefined`);
|
||||
throw new Error(`${msg(loc)} must be a function, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertBoolean(key: string, value: mixed): boolean | void {
|
||||
export function assertBoolean(loc: GeneralPath, value: mixed): boolean | void {
|
||||
if (value !== undefined && typeof value !== "boolean") {
|
||||
throw new Error(`.${key} must be a boolean, or undefined`);
|
||||
throw new Error(`${msg(loc)} must be a boolean, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertObject(key: string, value: mixed): {} | void {
|
||||
export function assertObject(loc: GeneralPath, value: mixed): {} | void {
|
||||
if (
|
||||
value !== undefined &&
|
||||
(typeof value !== "object" || Array.isArray(value) || !value)
|
||||
) {
|
||||
throw new Error(`.${key} must be an object, or undefined`);
|
||||
throw new Error(`${msg(loc)} must be an object, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertArray(key: string, value: mixed): ?$ReadOnlyArray<mixed> {
|
||||
export function assertArray(
|
||||
loc: GeneralPath,
|
||||
value: mixed,
|
||||
): ?$ReadOnlyArray<mixed> {
|
||||
if (value != null && !Array.isArray(value)) {
|
||||
throw new Error(`.${key} must be an array, or undefined`);
|
||||
throw new Error(`${msg(loc)} must be an array, or undefined`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertIgnoreList(key: string, value: mixed): IgnoreList | void {
|
||||
const arr = assertArray(key, value);
|
||||
export function assertIgnoreList(
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): IgnoreList | void {
|
||||
const arr = assertArray(loc, value);
|
||||
if (arr) {
|
||||
arr.forEach((item, i) => assertIgnoreItem(key, i, item));
|
||||
arr.forEach((item, i) => assertIgnoreItem(access(loc, i), item));
|
||||
}
|
||||
return (arr: any);
|
||||
}
|
||||
function assertIgnoreItem(
|
||||
key: string,
|
||||
index: number,
|
||||
value: mixed,
|
||||
): IgnoreItem {
|
||||
function assertIgnoreItem(loc: GeneralPath, value: mixed): IgnoreItem {
|
||||
if (
|
||||
typeof value !== "string" &&
|
||||
typeof value !== "function" &&
|
||||
!(value instanceof RegExp)
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key}[${index}] must be an array of string/Funtion/RegExp values, or undefined`,
|
||||
`${msg(
|
||||
loc,
|
||||
)} must be an array of string/Funtion/RegExp values, or undefined`,
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertConfigApplicableTest(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): ConfigApplicableTest | void {
|
||||
if (value === undefined) return value;
|
||||
@@ -147,12 +231,14 @@ export function assertConfigApplicableTest(
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item, i) => {
|
||||
if (!checkValidTest(item)) {
|
||||
throw new Error(`.${key}[${i}] must be a string/Function/RegExp.`);
|
||||
throw new Error(
|
||||
`${msg(access(loc, i))} must be a string/Function/RegExp.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (!checkValidTest(value)) {
|
||||
throw new Error(
|
||||
`.${key} must be a string/Function/RegExp, or an array of those`,
|
||||
`${msg(loc)} must be a string/Function/RegExp, or an array of those`,
|
||||
);
|
||||
}
|
||||
return (value: any);
|
||||
@@ -167,7 +253,7 @@ function checkValidTest(value: mixed): boolean {
|
||||
}
|
||||
|
||||
export function assertConfigFileSearch(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): ConfigFileSearch | void {
|
||||
if (
|
||||
@@ -176,7 +262,7 @@ export function assertConfigFileSearch(
|
||||
typeof value !== "string"
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key} must be a undefined, a boolean, a string, ` +
|
||||
`${msg(loc)} must be a undefined, a boolean, a string, ` +
|
||||
`got ${JSON.stringify(value)}`,
|
||||
);
|
||||
}
|
||||
@@ -185,7 +271,7 @@ export function assertConfigFileSearch(
|
||||
}
|
||||
|
||||
export function assertBabelrcSearch(
|
||||
key: string,
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): BabelrcSearch | void {
|
||||
if (value === undefined || typeof value === "boolean") return value;
|
||||
@@ -193,44 +279,43 @@ export function assertBabelrcSearch(
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item, i) => {
|
||||
if (!checkValidTest(item)) {
|
||||
throw new Error(`.${key}[${i}] must be a string/Function/RegExp.`);
|
||||
throw new Error(
|
||||
`${msg(access(loc, i))} must be a string/Function/RegExp.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (!checkValidTest(value)) {
|
||||
throw new Error(
|
||||
`.${key} must be a undefined, a boolean, a string/Function/RegExp ` +
|
||||
`${msg(loc)} must be a undefined, a boolean, a string/Function/RegExp ` +
|
||||
`or an array of those, got ${JSON.stringify(value)}`,
|
||||
);
|
||||
}
|
||||
return (value: any);
|
||||
}
|
||||
|
||||
export function assertPluginList(key: string, value: mixed): PluginList | void {
|
||||
const arr = assertArray(key, value);
|
||||
export function assertPluginList(
|
||||
loc: OptionPath,
|
||||
value: mixed,
|
||||
): PluginList | void {
|
||||
const arr = assertArray(loc, value);
|
||||
if (arr) {
|
||||
// Loop instead of using `.map` in order to preserve object identity
|
||||
// for plugin array for use during config chain processing.
|
||||
arr.forEach((item, i) => assertPluginItem(key, i, item));
|
||||
arr.forEach((item, i) => assertPluginItem(access(loc, i), item));
|
||||
}
|
||||
return (arr: any);
|
||||
}
|
||||
function assertPluginItem(
|
||||
key: string,
|
||||
index: number,
|
||||
value: mixed,
|
||||
): PluginItem {
|
||||
function assertPluginItem(loc: GeneralPath, value: mixed): PluginItem {
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length === 0) {
|
||||
throw new Error(`.${key}[${index}] must include an object`);
|
||||
throw new Error(`${msg(loc)} must include an object`);
|
||||
}
|
||||
|
||||
if (value.length > 3) {
|
||||
throw new Error(
|
||||
`.${key}[${index}] may only be a two-tuple or three-tuple`,
|
||||
);
|
||||
throw new Error(`${msg(loc)} may only be a two-tuple or three-tuple`);
|
||||
}
|
||||
|
||||
assertPluginTarget(key, index, true, value[0]);
|
||||
assertPluginTarget(access(loc, 0), value[0]);
|
||||
|
||||
if (value.length > 1) {
|
||||
const opts = value[1];
|
||||
@@ -240,38 +325,31 @@ function assertPluginItem(
|
||||
(typeof opts !== "object" || Array.isArray(opts))
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key}[${index}][1] must be an object, false, or undefined`,
|
||||
`${msg(access(loc, 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`);
|
||||
throw new Error(
|
||||
`${msg(access(loc, 2))} must be a string, or undefined`,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assertPluginTarget(key, index, false, value);
|
||||
assertPluginTarget(loc, value);
|
||||
}
|
||||
|
||||
return (value: any);
|
||||
}
|
||||
function assertPluginTarget(
|
||||
key: string,
|
||||
index: number,
|
||||
inArray: boolean,
|
||||
value: mixed,
|
||||
): PluginTarget {
|
||||
function assertPluginTarget(loc: GeneralPath, value: mixed): PluginTarget {
|
||||
if (
|
||||
(typeof value !== "object" || !value) &&
|
||||
typeof value !== "string" &&
|
||||
typeof value !== "function"
|
||||
) {
|
||||
throw new Error(
|
||||
`.${key}[${index}]${
|
||||
inArray ? `[0]` : ""
|
||||
} must be a string, object, function`,
|
||||
);
|
||||
throw new Error(`${msg(loc)} must be a string, object, function`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,13 @@ import Plugin from "../plugin";
|
||||
|
||||
import removed from "./removed";
|
||||
import {
|
||||
msg,
|
||||
access,
|
||||
assertString,
|
||||
assertBoolean,
|
||||
assertObject,
|
||||
assertArray,
|
||||
assertCallerMetadata,
|
||||
assertInputSourceMap,
|
||||
assertIgnoreList,
|
||||
assertPluginList,
|
||||
@@ -21,6 +24,7 @@ import {
|
||||
assertSourceType,
|
||||
type ValidatorSet,
|
||||
type Validator,
|
||||
type OptionPath,
|
||||
} from "./option-assertions";
|
||||
|
||||
const ROOT_VALIDATORS: ValidatorSet = {
|
||||
@@ -30,6 +34,9 @@ const ROOT_VALIDATORS: ValidatorSet = {
|
||||
$PropertyType<ValidatedOptions, "configFile">,
|
||||
>),
|
||||
|
||||
caller: (assertCallerMetadata: Validator<
|
||||
$PropertyType<ValidatedOptions, "caller">,
|
||||
>),
|
||||
filename: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "filename">,
|
||||
>),
|
||||
@@ -173,6 +180,7 @@ export type ValidatedOptions = {
|
||||
ast?: boolean,
|
||||
inputSourceMap?: RootInputSourceMapOption,
|
||||
envName?: string,
|
||||
caller?: CallerMetadata,
|
||||
|
||||
extends?: string,
|
||||
env?: EnvSet<ValidatedOptions>,
|
||||
@@ -222,6 +230,11 @@ export type ValidatedOptions = {
|
||||
generatorOpts?: {},
|
||||
};
|
||||
|
||||
export type CallerMetadata = {
|
||||
// If 'caller' is specified, require that the name is given for debugging
|
||||
// messages.
|
||||
name: string,
|
||||
};
|
||||
export type EnvSet<T> = {
|
||||
[string]: ?T,
|
||||
};
|
||||
@@ -248,24 +261,62 @@ export type SourceTypeOption = "module" | "script" | "unambiguous";
|
||||
export type CompactOption = boolean | "auto";
|
||||
export type RootInputSourceMapOption = {} | boolean;
|
||||
|
||||
export type OptionsType =
|
||||
export type OptionsSource =
|
||||
| "arguments"
|
||||
| "env"
|
||||
| "preset"
|
||||
| "override"
|
||||
| "configfile"
|
||||
| "babelrcfile"
|
||||
| "extendsfile";
|
||||
| "extendsfile"
|
||||
| "preset";
|
||||
|
||||
type RootPath = $ReadOnly<{
|
||||
type: "root",
|
||||
source: OptionsSource,
|
||||
}>;
|
||||
type OverridesPath = $ReadOnly<{
|
||||
type: "overrides",
|
||||
index: number,
|
||||
parent: RootPath,
|
||||
}>;
|
||||
type EnvPath = $ReadOnly<{
|
||||
type: "env",
|
||||
name: string,
|
||||
parent: RootPath | OverridesPath,
|
||||
}>;
|
||||
export type NestingPath = RootPath | OverridesPath | EnvPath;
|
||||
|
||||
function getSource(loc: NestingPath): OptionsSource {
|
||||
return loc.type === "root" ? loc.source : getSource(loc.parent);
|
||||
}
|
||||
|
||||
export function validate(type: OptionsSource, opts: {}): ValidatedOptions {
|
||||
return validateNested(
|
||||
{
|
||||
type: "root",
|
||||
source: type,
|
||||
},
|
||||
opts,
|
||||
);
|
||||
}
|
||||
|
||||
function validateNested(loc: NestingPath, opts: {}) {
|
||||
const type = getSource(loc);
|
||||
|
||||
export function validate(type: OptionsType, opts: {}): ValidatedOptions {
|
||||
assertNoDuplicateSourcemap(opts);
|
||||
|
||||
Object.keys(opts).forEach(key => {
|
||||
const optLoc = {
|
||||
type: "option",
|
||||
name: key,
|
||||
parent: loc,
|
||||
};
|
||||
|
||||
if (type === "preset" && NONPRESET_VALIDATORS[key]) {
|
||||
throw new Error(`.${key} is not allowed in preset options`);
|
||||
throw new Error(`${msg(optLoc)} is not allowed in preset options`);
|
||||
}
|
||||
if (type !== "arguments" && ROOT_VALIDATORS[key]) {
|
||||
throw new Error(`.${key} is only allowed in root programmatic options`);
|
||||
throw new Error(
|
||||
`${msg(optLoc)} is only allowed in root programmatic options`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
type !== "arguments" &&
|
||||
@@ -274,48 +325,47 @@ export function validate(type: OptionsType, opts: {}): ValidatedOptions {
|
||||
) {
|
||||
if (type === "babelrcfile" || type === "extendsfile") {
|
||||
throw new Error(
|
||||
`.${key} is not allowed in .babelrc or "extend"ed files, only in root programmatic options, ` +
|
||||
`${msg(
|
||||
optLoc,
|
||||
)} is not allowed in .babelrc or "extends"ed files, only in root programmatic options, ` +
|
||||
`or babel.config.js/config file options`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`.${key} is only allowed in root programmatic options, or babel.config.js/config file options`,
|
||||
`${msg(
|
||||
optLoc,
|
||||
)} is only allowed in root programmatic options, or babel.config.js/config file options`,
|
||||
);
|
||||
}
|
||||
if (type === "env" && key === "env") {
|
||||
throw new Error(`.${key} is not allowed inside another env block`);
|
||||
}
|
||||
if (type === "env" && key === "overrides") {
|
||||
throw new Error(`.${key} is not allowed inside an env block`);
|
||||
}
|
||||
if (type === "override" && key === "overrides") {
|
||||
throw new Error(`.${key} is not allowed inside an overrides block`);
|
||||
}
|
||||
|
||||
const validator =
|
||||
COMMON_VALIDATORS[key] ||
|
||||
NONPRESET_VALIDATORS[key] ||
|
||||
BABELRC_VALIDATORS[key] ||
|
||||
ROOT_VALIDATORS[key];
|
||||
ROOT_VALIDATORS[key] ||
|
||||
throwUnknownError;
|
||||
|
||||
if (validator) validator(key, opts[key]);
|
||||
else throw buildUnknownError(key);
|
||||
validator(optLoc, opts[key]);
|
||||
});
|
||||
|
||||
return (opts: any);
|
||||
}
|
||||
|
||||
function buildUnknownError(key: string) {
|
||||
function throwUnknownError(loc: OptionPath) {
|
||||
const key = loc.name;
|
||||
|
||||
if (removed[key]) {
|
||||
const { message, version = 5 } = removed[key];
|
||||
|
||||
throw new ReferenceError(
|
||||
`Using removed Babel ${version} option: .${key} - ${message}`,
|
||||
`Using removed Babel ${version} option: ${msg(loc)} - ${message}`,
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line max-len
|
||||
const unknownOptErr = `Unknown option: .${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
const unknownOptErr = `Unknown option: ${msg(
|
||||
loc,
|
||||
)}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
|
||||
throw new ReferenceError(unknownOptErr);
|
||||
}
|
||||
@@ -331,27 +381,53 @@ function assertNoDuplicateSourcemap(opts: {}): void {
|
||||
}
|
||||
}
|
||||
|
||||
function assertEnvSet(key: string, value: mixed): EnvSet<ValidatedOptions> {
|
||||
const obj = assertObject(key, value);
|
||||
function assertEnvSet(loc: OptionPath, value: mixed): EnvSet<ValidatedOptions> {
|
||||
if (loc.parent.type === "env") {
|
||||
throw new Error(`${msg(loc)} is not allowed inside of another .env block`);
|
||||
}
|
||||
const parent: RootPath | OverridesPath = loc.parent;
|
||||
|
||||
const obj = assertObject(loc, value);
|
||||
if (obj) {
|
||||
// Validate but don't copy the .env object in order to preserve
|
||||
// object identity for use during config chain processing.
|
||||
for (const key of Object.keys(obj)) {
|
||||
const env = assertObject(key, obj[key]);
|
||||
if (env) validate("env", env);
|
||||
for (const envName of Object.keys(obj)) {
|
||||
const env = assertObject(access(loc, envName), obj[envName]);
|
||||
if (!env) continue;
|
||||
|
||||
const envLoc = {
|
||||
type: "env",
|
||||
name: envName,
|
||||
parent,
|
||||
};
|
||||
validateNested(envLoc, env);
|
||||
}
|
||||
}
|
||||
return (obj: any);
|
||||
}
|
||||
|
||||
function assertOverridesList(key: string, value: mixed): OverridesList {
|
||||
const arr = assertArray(key, value);
|
||||
function assertOverridesList(loc: OptionPath, value: mixed): OverridesList {
|
||||
if (loc.parent.type === "env") {
|
||||
throw new Error(`${msg(loc)} is not allowed inside an .env block`);
|
||||
}
|
||||
if (loc.parent.type === "overrides") {
|
||||
throw new Error(`${msg(loc)} is not allowed inside an .overrides block`);
|
||||
}
|
||||
const parent: RootPath = loc.parent;
|
||||
|
||||
const arr = assertArray(loc, value);
|
||||
if (arr) {
|
||||
for (const [index, item] of arr.entries()) {
|
||||
const env = assertObject(`${index}`, item);
|
||||
if (!env) throw new Error(`.${key}[${index}] must be an object`);
|
||||
const objLoc = access(loc, index);
|
||||
const env = assertObject(objLoc, item);
|
||||
if (!env) throw new Error(`${msg(objLoc)} must be an object`);
|
||||
|
||||
validate("override", env);
|
||||
const overridesLoc = {
|
||||
type: "overrides",
|
||||
index,
|
||||
parent,
|
||||
};
|
||||
validateNested(overridesLoc, env);
|
||||
}
|
||||
}
|
||||
return (arr: any);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import * as helpers from "@babel/helpers";
|
||||
import { NodePath, Hub, Scope } from "@babel/traverse";
|
||||
import { NodePath, Scope, type HubInterface } from "@babel/traverse";
|
||||
import { codeFrameColumns } from "@babel/code-frame";
|
||||
import traverse from "@babel/traverse";
|
||||
import * as t from "@babel/types";
|
||||
@@ -27,10 +27,18 @@ export default class File {
|
||||
ast: Object = {};
|
||||
scope: Scope;
|
||||
metadata: {} = {};
|
||||
hub: Hub = new Hub(this);
|
||||
code: string = "";
|
||||
inputMap: Object | null = null;
|
||||
|
||||
hub: HubInterface = {
|
||||
// keep it for the usage in babel-core, ex: path.hub.file.opts.filename
|
||||
file: this,
|
||||
getCode: () => this.code,
|
||||
getScope: () => this.scope,
|
||||
addHelper: this.addHelper.bind(this),
|
||||
buildError: this.buildCodeFrameError.bind(this),
|
||||
};
|
||||
|
||||
constructor(options: {}, { code, ast, inputMap }: NormalizedFile) {
|
||||
this.opts = options;
|
||||
this.code = code;
|
||||
@@ -132,12 +140,6 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this before 7.x's official release. Leaving it in for now to
|
||||
// prevent unnecessary breakage between beta versions.
|
||||
resolveModuleSource(source: string): string {
|
||||
return source;
|
||||
}
|
||||
|
||||
addImport() {
|
||||
throw new Error(
|
||||
"This API has been removed. If you're looking for this " +
|
||||
|
||||
@@ -293,7 +293,7 @@ function findInsertionLocation<T>(
|
||||
// Ensure the value is the start of any set of matches.
|
||||
let i = left;
|
||||
if (i < array.length) {
|
||||
while (i > 0 && callback(array[i]) >= 0) {
|
||||
while (i >= 0 && callback(array[i]) >= 0) {
|
||||
i--;
|
||||
}
|
||||
return i + 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import loadConfig from "../lib/config";
|
||||
import loadConfig, { loadPartialConfig } from "../lib/config";
|
||||
import path from "path";
|
||||
|
||||
describe("@babel/core config loading", () => {
|
||||
@@ -29,13 +29,53 @@ describe("@babel/core config loading", () => {
|
||||
filename: FILEPATH,
|
||||
presets: skipProgrammatic
|
||||
? null
|
||||
: [require("./fixtures/config-loading/preset3")],
|
||||
: [[require("./fixtures/config-loading/preset3"), {}]],
|
||||
plugins: skipProgrammatic
|
||||
? null
|
||||
: [require("./fixtures/config-loading/plugin6")],
|
||||
: [[require("./fixtures/config-loading/plugin6"), {}]],
|
||||
};
|
||||
}
|
||||
|
||||
describe("loadPartialConfig", () => {
|
||||
it("should preserve disabled plugins in the partial config", () => {
|
||||
const plugin = function() {
|
||||
return {};
|
||||
};
|
||||
|
||||
const opts = loadPartialConfig({
|
||||
...makeOpts(true),
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
plugins: [[plugin, false]],
|
||||
});
|
||||
|
||||
expect(opts.options.plugins.length).toBe(1);
|
||||
const item = opts.options.plugins[0];
|
||||
|
||||
expect(item.value).toBe(plugin);
|
||||
expect(item.options).toBe(false);
|
||||
});
|
||||
|
||||
it("should preserve disabled presets in the partial config", () => {
|
||||
const preset = function() {
|
||||
return {};
|
||||
};
|
||||
|
||||
const opts = loadPartialConfig({
|
||||
...makeOpts(true),
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
presets: [[preset, false]],
|
||||
});
|
||||
|
||||
expect(opts.options.presets.length).toBe(1);
|
||||
const item = opts.options.presets[0];
|
||||
|
||||
expect(item.value).toBe(preset);
|
||||
expect(item.options).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("config file", () => {
|
||||
it("should load and cache the config with plugins and presets", () => {
|
||||
const opts = makeOpts();
|
||||
@@ -173,7 +213,7 @@ describe("@babel/core config loading", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("should invalidate the plugins when given a fresh arrays", () => {
|
||||
it("should not invalidate the plugins when given a fresh arrays", () => {
|
||||
const opts = makeOpts();
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
@@ -184,6 +224,38 @@ describe("@babel/core config loading", () => {
|
||||
}).options;
|
||||
expect(options2.plugins.length).toBe(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
expect(options2.plugins[i]).toBe(options1.plugins[i]);
|
||||
}
|
||||
});
|
||||
|
||||
it("should not invalidate the presets when given a fresh arrays", () => {
|
||||
const opts = makeOpts();
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
|
||||
const options2 = loadConfig({
|
||||
...opts,
|
||||
presets: opts.presets.slice(),
|
||||
}).options;
|
||||
expect(options2.plugins.length).toBe(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
expect(options2.plugins[i]).toBe(options1.plugins[i]);
|
||||
}
|
||||
});
|
||||
|
||||
it("should invalidate the plugins when given a fresh options", () => {
|
||||
const opts = makeOpts();
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
|
||||
const options2 = loadConfig({
|
||||
...opts,
|
||||
plugins: opts.plugins.map(([plg, opt]) => [plg, { ...opt }]),
|
||||
}).options;
|
||||
expect(options2.plugins.length).toBe(options1.plugins.length);
|
||||
|
||||
for (let i = 0; i < options2.plugins.length; i++) {
|
||||
if (i === 2) {
|
||||
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
|
||||
@@ -193,14 +265,14 @@ describe("@babel/core config loading", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("should invalidate the presets when given a fresh arrays", () => {
|
||||
it("should invalidate the presets when given a fresh options", () => {
|
||||
const opts = makeOpts();
|
||||
|
||||
const options1 = loadConfig(opts).options;
|
||||
|
||||
const options2 = loadConfig({
|
||||
...opts,
|
||||
presets: opts.presets.slice(),
|
||||
presets: opts.presets.map(([plg, opt]) => [plg, { ...opt }]),
|
||||
}).options;
|
||||
expect(options2.plugins.length).toBe(options1.plugins.length);
|
||||
|
||||
@@ -251,4 +323,51 @@ describe("@babel/core config loading", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("caller metadata", () => {
|
||||
it("should pass caller data through", () => {
|
||||
const options1 = loadConfig({
|
||||
...makeOpts(),
|
||||
caller: {
|
||||
name: "babel-test",
|
||||
someFlag: true,
|
||||
},
|
||||
}).options;
|
||||
|
||||
expect(options1.caller.name).toBe("babel-test");
|
||||
expect(options1.caller.someFlag).toBe(true);
|
||||
});
|
||||
|
||||
it("should pass unknown caller data through", () => {
|
||||
const options1 = loadConfig({
|
||||
...makeOpts(),
|
||||
caller: undefined,
|
||||
}).options;
|
||||
|
||||
expect(options1.caller).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should pass caller data to test functions", () => {
|
||||
const options1 = loadConfig({
|
||||
...makeOpts(),
|
||||
caller: {
|
||||
name: "babel-test",
|
||||
someFlag: true,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
test: (filename, { caller }) => caller.name === "babel-test",
|
||||
comments: false,
|
||||
},
|
||||
{
|
||||
test: (filename, { caller }) => caller.name !== "babel-test",
|
||||
ast: false,
|
||||
},
|
||||
],
|
||||
}).options;
|
||||
|
||||
expect(options1.comments).toBe(false);
|
||||
expect(options1.ast).not.toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing-babel-plugin/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing-babel-plugin/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing-babel-preset/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing-babel-preset/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing.babel-plugin-convert/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing.babel-plugin-convert/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing.babel-preset-convert/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/thing.babel-preset-convert/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function() {
|
||||
return {};
|
||||
};
|
||||
@@ -23,7 +23,9 @@ describe("parse", function() {
|
||||
const output = require(fixture("output.json"));
|
||||
|
||||
const result = parse(input, {
|
||||
parserOpts: { plugins: ["decorators"] },
|
||||
parserOpts: {
|
||||
plugins: [["decorators", { decoratorsBeforeExport: false }]],
|
||||
},
|
||||
cwd: fixture(),
|
||||
});
|
||||
expect(JSON.parse(JSON.stringify(result))).toEqual(output);
|
||||
|
||||
@@ -134,6 +134,46 @@ describe("addon resolution", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("should find @foo scoped presets with an inner babel-preset", function() {
|
||||
process.chdir("foo-org-paths");
|
||||
|
||||
babel.transform("", {
|
||||
filename: "filename.js",
|
||||
babelrc: false,
|
||||
presets: ["@foo/thing.babel-preset-convert"],
|
||||
});
|
||||
});
|
||||
|
||||
it("should find @foo scoped plugins with an inner babel-plugin", function() {
|
||||
process.chdir("foo-org-paths");
|
||||
|
||||
babel.transform("", {
|
||||
filename: "filename.js",
|
||||
babelrc: false,
|
||||
plugins: ["@foo/thing.babel-plugin-convert"],
|
||||
});
|
||||
});
|
||||
|
||||
it("should find @foo scoped presets with an babel-preset suffix", function() {
|
||||
process.chdir("foo-org-paths");
|
||||
|
||||
babel.transform("", {
|
||||
filename: "filename.js",
|
||||
babelrc: false,
|
||||
presets: ["@foo/thing-babel-preset"],
|
||||
});
|
||||
});
|
||||
|
||||
it("should find @foo scoped plugins with an babel-plugin suffix", function() {
|
||||
process.chdir("foo-org-paths");
|
||||
|
||||
babel.transform("", {
|
||||
filename: "filename.js",
|
||||
babelrc: false,
|
||||
plugins: ["@foo/thing-babel-plugin"],
|
||||
});
|
||||
});
|
||||
|
||||
it("should find @foo scoped presets with an existing prefix", function() {
|
||||
process.chdir("foo-org-paths");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/generator",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Turns an AST into code.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -11,14 +11,14 @@
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.3",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.17.10",
|
||||
"source-map": "^0.5.0",
|
||||
"trim-right": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-fixtures": "7.0.0-rc.0",
|
||||
"@babel/parser": "7.0.0-rc.0"
|
||||
"@babel/helper-fixtures": "7.0.0-rc.3",
|
||||
"@babel/parser": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
5
packages/babel-generator/test/fixtures/harmony-edgecase/import-with-break/input.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/harmony-edgecase/import-with-break/input.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import foo from "foo";
|
||||
|
||||
foo: {
|
||||
break foo;
|
||||
}
|
||||
5
packages/babel-generator/test/fixtures/harmony-edgecase/import-with-break/output.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/harmony-edgecase/import-with-break/output.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import foo from "foo";
|
||||
|
||||
foo: {
|
||||
break foo;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-annotate-as-pure",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to annotate paths and nodes with #__PURE__ comment",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-annotate-as-pure",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@babel/helper-bindify-decorators",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to bindify decorators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-bindify-decorators",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@babel/helper-builder-binary-assignment-operator-visitor",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to build binary assignment operator visitors",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-binary-assignment-operator-visitor",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-explode-assignable-expression": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-explode-assignable-expression": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@babel/helper-builder-react-jsx",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to build react jsx",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.3",
|
||||
"esutils": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@babel/helper-call-delegate",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to call delegate",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-call-delegate",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-hoist-variables": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-hoist-variables": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@babel/helper-define-map",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to define a map",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-define-map",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-function-name": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"@babel/helper-function-name": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3",
|
||||
"lodash": "^4.17.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@babel/helper-explode-assignable-expression",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to explode an assignable expression",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-assignable-expression",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@babel/helper-explode-class",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to explode class",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-class",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-bindify-decorators": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-bindify-decorators": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-fixtures",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to support fixtures",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@babel/helper-function-name",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to change the property 'name' of every function",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-function-name",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-get-function-arity": "7.0.0-rc.0",
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-get-function-arity": "7.0.0-rc.3",
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-get-function-arity",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to get function arity",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-get-function-arity",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-hoist-variables",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to hoist variables",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-hoist-variables",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@babel/helper-member-expression-to-functions",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to replace certain member expressions with function calls",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-member-expression-to-functions",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"author": "Justin Ridgewell <justin@ridgewell.name>",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-module-imports",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel helper functions for inserting module loads",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,10 +8,9 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-module-imports",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"lodash": "^4.17.10"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ export default class ImportBuilder {
|
||||
_resultName = null;
|
||||
|
||||
_scope = null;
|
||||
_file = null;
|
||||
_hub = null;
|
||||
|
||||
constructor(importedSource, scope, file) {
|
||||
constructor(importedSource, scope, hub) {
|
||||
this._scope = scope;
|
||||
this._file = file;
|
||||
this._hub = hub;
|
||||
this._importedSource = importedSource;
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ export default class ImportBuilder {
|
||||
}
|
||||
|
||||
defaultInterop() {
|
||||
return this._interop(this._file.addHelper("interopRequireDefault"));
|
||||
return this._interop(this._hub.addHelper("interopRequireDefault"));
|
||||
}
|
||||
wildcardInterop() {
|
||||
return this._interop(this._file.addHelper("interopRequireWildcard"));
|
||||
return this._interop(this._hub.addHelper("interopRequireWildcard"));
|
||||
}
|
||||
|
||||
_interop(callee) {
|
||||
|
||||
@@ -108,7 +108,7 @@ export default class ImportInjector {
|
||||
/**
|
||||
* The file used to inject helpers and resolve paths.
|
||||
*/
|
||||
_file;
|
||||
_hub;
|
||||
|
||||
/**
|
||||
* The default options to use with this instance when imports are added.
|
||||
@@ -127,7 +127,7 @@ export default class ImportInjector {
|
||||
|
||||
this._programPath = programPath;
|
||||
this._programScope = programPath.scope;
|
||||
this._file = programPath.hub.file;
|
||||
this._hub = programPath.hub;
|
||||
|
||||
this._defaultOpts = this._applyDefaults(importedSource, opts, true);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ export default class ImportInjector {
|
||||
const builder = new ImportBuilder(
|
||||
importedSource,
|
||||
this._programScope,
|
||||
this._file,
|
||||
this._hub,
|
||||
);
|
||||
|
||||
if (importedType === "es6") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-module-transforms",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel helper functions for implementing ES6 module transformations",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,11 +8,11 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-module-transforms",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-module-imports": "7.0.0-rc.0",
|
||||
"@babel/helper-simple-access": "7.0.0-rc.0",
|
||||
"@babel/helper-split-export-declaration": "7.0.0-rc.0",
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"@babel/helper-module-imports": "7.0.0-rc.3",
|
||||
"@babel/helper-simple-access": "7.0.0-rc.3",
|
||||
"@babel/helper-split-export-declaration": "7.0.0-rc.3",
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3",
|
||||
"lodash": "^4.17.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ export function wrapInterop(
|
||||
throw new Error(`Unknown interop: ${type}`);
|
||||
}
|
||||
|
||||
return t.callExpression(programPath.hub.file.addHelper(helper), [expr]);
|
||||
return t.callExpression(programPath.hub.addHelper(helper), [expr]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-optimise-call-expression",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to optimise call expression",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-optimise-call-expression",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-plugin-test-runner",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to support test runner",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.0"
|
||||
"@babel/helper-transform-fixture-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-plugin-utils",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "General utilities for plugins to use",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-regex",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to check for literal RegEx",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-regex",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "@babel/helper-remap-async-to-generator",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to remap async functions to generators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-remap-async-to-generator",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-annotate-as-pure": "7.0.0-rc.0",
|
||||
"@babel/helper-wrap-function": "7.0.0-rc.0",
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-annotate-as-pure": "7.0.0-rc.3",
|
||||
"@babel/helper-wrap-function": "7.0.0-rc.3",
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "@babel/helper-replace-supers",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper function to replace supers",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-member-expression-to-functions": "7.0.0-rc.0",
|
||||
"@babel/helper-optimise-call-expression": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-member-expression-to-functions": "7.0.0-rc.3",
|
||||
"@babel/helper-optimise-call-expression": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-simple-access",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel helper for ensuring that access to a given value is performed through simple accesses",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,8 +8,7 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-simple-access",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0",
|
||||
"lodash": "^4.17.10"
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@babel/helper-split-export-declaration",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-split-export-declaration",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-transform-fixture-test-runner",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Transform test runner for @babel/helper-fixtures module",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,10 +8,10 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "7.0.0-rc.0",
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.0",
|
||||
"@babel/polyfill": "7.0.0-rc.0",
|
||||
"@babel/code-frame": "7.0.0-rc.3",
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.3",
|
||||
"@babel/polyfill": "7.0.0-rc.3",
|
||||
"jest": "^22.4.2",
|
||||
"jest-diff": "^22.4.0",
|
||||
"lodash": "^4.17.10",
|
||||
|
||||
@@ -6,6 +6,7 @@ import sourceMap from "source-map";
|
||||
import { codeFrameColumns } from "@babel/code-frame";
|
||||
import defaults from "lodash/defaults";
|
||||
import includes from "lodash/includes";
|
||||
import escapeRegExp from "lodash/escapeRegExp";
|
||||
import * as helpers from "./helpers";
|
||||
import extend from "lodash/extend";
|
||||
import merge from "lodash/merge";
|
||||
@@ -180,7 +181,7 @@ function run(task) {
|
||||
function getOpts(self) {
|
||||
const newOpts = merge(
|
||||
{
|
||||
cwd: path.dirname(self.filename),
|
||||
cwd: path.dirname(self.loc),
|
||||
filename: self.loc,
|
||||
filenameRelative: self.filename,
|
||||
sourceFileName: self.filename,
|
||||
@@ -235,10 +236,15 @@ function run(task) {
|
||||
const expectCode = expected.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = babel.transform(actualCode, getOpts(actual));
|
||||
const expectedCode = result.code.replace(
|
||||
escapeRegExp(path.resolve(__dirname, "../../../")),
|
||||
"<CWD>",
|
||||
);
|
||||
|
||||
checkDuplicatedNodes(result.ast);
|
||||
if (
|
||||
!expected.code &&
|
||||
result.code &&
|
||||
expectedCode &&
|
||||
!opts.throws &&
|
||||
fs.statSync(path.dirname(expected.loc)).isDirectory() &&
|
||||
!process.env.CI
|
||||
@@ -249,7 +255,7 @@ function run(task) {
|
||||
);
|
||||
|
||||
console.log(`New test file created: ${expectedFile}`);
|
||||
fs.writeFileSync(expectedFile, `${result.code}\n`);
|
||||
fs.writeFileSync(expectedFile, `${expectedCode}\n`);
|
||||
|
||||
if (expected.loc !== expectedFile) {
|
||||
try {
|
||||
@@ -257,7 +263,7 @@ function run(task) {
|
||||
} catch (e) {}
|
||||
}
|
||||
} else {
|
||||
actualCode = result.code.trim();
|
||||
actualCode = expectedCode.trim();
|
||||
try {
|
||||
expect(actualCode).toEqualFile({
|
||||
filename: expected.loc,
|
||||
@@ -267,7 +273,7 @@ function run(task) {
|
||||
if (!process.env.OVERWRITE) throw e;
|
||||
|
||||
console.log(`Updated test file: ${expected.loc}`);
|
||||
fs.writeFileSync(expected.loc, `${result.code}\n`);
|
||||
fs.writeFileSync(expected.loc, `${expectedCode}\n`);
|
||||
}
|
||||
|
||||
if (actualCode) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "@babel/helper-wrap-function",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Helper to wrap functions inside a function call.",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-wrap-function",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-function-name": "7.0.0-rc.0",
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/helper-function-name": "7.0.0-rc.3",
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helpers",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Collection of helper functions used by Babel transforms.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,11 +8,11 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "7.0.0-rc.0",
|
||||
"@babel/traverse": "7.0.0-rc.0",
|
||||
"@babel/types": "7.0.0-rc.0"
|
||||
"@babel/template": "7.0.0-rc.3",
|
||||
"@babel/traverse": "7.0.0-rc.3",
|
||||
"@babel/types": "7.0.0-rc.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,6 +483,8 @@ helpers.construct = helper("7.0.0-beta.0")`
|
||||
if (isNativeReflectConstruct()) {
|
||||
_construct = Reflect.construct;
|
||||
} else {
|
||||
// NOTE: If Parent !== Class, the correct __proto__ is set *after*
|
||||
// calling the constructor.
|
||||
_construct = function _construct(Parent, args, Class) {
|
||||
var a = [null];
|
||||
a.push.apply(a, args);
|
||||
@@ -498,17 +500,25 @@ helpers.construct = helper("7.0.0-beta.0")`
|
||||
}
|
||||
`;
|
||||
|
||||
helpers.isNativeFunction = helper("7.0.0-beta.0")`
|
||||
export default function _isNativeFunction(fn) {
|
||||
// Note: This function returns "true" for core-js functions.
|
||||
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
||||
}
|
||||
`;
|
||||
|
||||
// Based on https://github.com/WebReflection/babel-plugin-transform-builtin-classes
|
||||
helpers.wrapNativeSuper = helper("7.0.0-beta.0")`
|
||||
import getPrototypeOf from "getPrototypeOf";
|
||||
import setPrototypeOf from "setPrototypeOf";
|
||||
import isNativeFunction from "isNativeFunction";
|
||||
import construct from "construct";
|
||||
|
||||
export default function _wrapNativeSuper(Class) {
|
||||
var _cache = typeof Map === "function" ? new Map() : undefined;
|
||||
|
||||
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
||||
if (Class === null) return null;
|
||||
if (Class === null || !isNativeFunction(Class)) return Class;
|
||||
if (typeof Class !== "function") {
|
||||
throw new TypeError("Super expression must either be null or a function");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/highlight",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Syntax highlight JavaScript strings for output in terminals.",
|
||||
"author": "suchipi <me@suchipi.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -10,7 +10,7 @@
|
||||
"dependencies": {
|
||||
"chalk": "^2.0.0",
|
||||
"esutils": "^2.0.2",
|
||||
"js-tokens": "^3.0.0"
|
||||
"js-tokens": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"strip-ansi": "^4.0.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/node",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Babel command line",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -16,8 +16,8 @@
|
||||
"compiler"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/polyfill": "7.0.0-rc.0",
|
||||
"@babel/register": "7.0.0-rc.0",
|
||||
"@babel/polyfill": "7.0.0-rc.3",
|
||||
"@babel/register": "7.0.0-rc.3",
|
||||
"commander": "^2.8.1",
|
||||
"fs-readdir-recursive": "^1.0.0",
|
||||
"lodash": "^4.17.10",
|
||||
@@ -25,11 +25,11 @@
|
||||
"v8flags": "^3.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.3"
|
||||
},
|
||||
"bin": {
|
||||
"babel-node": "./bin/babel-node.js"
|
||||
|
||||
@@ -60,6 +60,9 @@ program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
program.parse(process.argv);
|
||||
|
||||
register({
|
||||
caller: {
|
||||
name: "@babel/node",
|
||||
},
|
||||
extensions: program.extensions,
|
||||
ignore: program.ignore,
|
||||
only: program.only,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/parser",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "A JavaScript parser",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -23,7 +23,7 @@
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-fixtures": "7.0.0-rc.0",
|
||||
"@babel/helper-fixtures": "7.0.0-rc.3",
|
||||
"charcodes": "0.1.0",
|
||||
"unicode-11.0.0": "^0.7.7"
|
||||
},
|
||||
|
||||
@@ -122,6 +122,15 @@ export default class CommentsParser extends BaseParser {
|
||||
lastComment.end <= node.end
|
||||
) {
|
||||
if (this.state.commentPreviousNode) {
|
||||
for (j = 0; j < this.state.leadingComments.length; j++) {
|
||||
if (
|
||||
this.state.leadingComments[j].end <
|
||||
this.state.commentPreviousNode.end
|
||||
) {
|
||||
this.state.leadingComments.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (this.state.leadingComments.length > 0) {
|
||||
lastArg.trailingComments = this.state.leadingComments;
|
||||
this.state.leadingComments = [];
|
||||
|
||||
@@ -41,13 +41,26 @@ export function getPluginOption(
|
||||
const PIPELINE_PROPOSALS = ["minimal"];
|
||||
|
||||
export function validatePlugins(plugins: PluginList) {
|
||||
if (
|
||||
hasPlugin(plugins, "decorators") &&
|
||||
hasPlugin(plugins, "decorators-legacy")
|
||||
) {
|
||||
throw new Error(
|
||||
"Cannot use the decorators and decorators-legacy plugin together",
|
||||
if (hasPlugin(plugins, "decorators")) {
|
||||
if (hasPlugin(plugins, "decorators-legacy")) {
|
||||
throw new Error(
|
||||
"Cannot use the decorators and decorators-legacy plugin together",
|
||||
);
|
||||
}
|
||||
|
||||
const decoratorsBeforeExport = getPluginOption(
|
||||
plugins,
|
||||
"decorators",
|
||||
"decoratorsBeforeExport",
|
||||
);
|
||||
if (decoratorsBeforeExport == null) {
|
||||
throw new Error(
|
||||
"The 'decorators' plugin requires a" +
|
||||
" 'decoratorsBeforeExport' option, whose value must be a boolean.",
|
||||
);
|
||||
} else if (typeof decoratorsBeforeExport !== "boolean") {
|
||||
throw new Error("'decoratorsBeforeExport' must be a boolean.");
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
|
||||
|
||||
@@ -1539,11 +1539,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// export default interface allowed in:
|
||||
// https://github.com/Microsoft/TypeScript/pull/16040
|
||||
if (this.state.value === "interface") {
|
||||
return this.tsParseDeclaration(
|
||||
const result = this.tsParseDeclaration(
|
||||
this.startNode(),
|
||||
this.state.value,
|
||||
true,
|
||||
);
|
||||
|
||||
if (result) return result;
|
||||
}
|
||||
|
||||
return super.parseExportDefaultExpression();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
test(function() {
|
||||
var a = 1;
|
||||
// one
|
||||
}
|
||||
// two
|
||||
);
|
||||
261
packages/babel-parser/test/fixtures/comments/basic/call-expression-function-argument/output.json
vendored
Normal file
261
packages/babel-parser/test/fixtures/comments/basic/call-expression-function-argument/output.json
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start": 0,
|
||||
"end": 50,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start": 0,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
},
|
||||
"identifierName": "test"
|
||||
},
|
||||
"name": "test"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"type": "FunctionExpression",
|
||||
"start": 5,
|
||||
"end": 41,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 16,
|
||||
"end": 41,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start": 20,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start": 24,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 24,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"init": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 28,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 1,
|
||||
"raw": "1"
|
||||
},
|
||||
"value": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "var",
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " one",
|
||||
"start": 33,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 8
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " two",
|
||||
"start": 42,
|
||||
"end": 48,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " one",
|
||||
"start": 33,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 8
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " two",
|
||||
"start": 42,
|
||||
"end": 48,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties", "decorators"]
|
||||
"plugins": [
|
||||
"classProperties",
|
||||
"classPrivateProperties",
|
||||
["decorators", { "decoratorsBeforeExport": false }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"plugins": ["decorators", "classProperties"]
|
||||
"plugins": [
|
||||
["decorators", { "decoratorsBeforeExport": false }],
|
||||
"classProperties"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
["decorators", { "decoratorsBeforeExport": "yes" }]
|
||||
],
|
||||
"throws": "'decoratorsBeforeExport' must be a boolean."
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["decorators"],
|
||||
"throws": "The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean."
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"plugins": ["decorators"]
|
||||
"plugins": [
|
||||
["decorators", { "decoratorsBeforeExport": false }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties", "decorators"]
|
||||
"plugins": [
|
||||
"classProperties",
|
||||
"classPrivateProperties",
|
||||
["decorators", { "decoratorsBeforeExport": false }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"plugins": ["classProperties", "decorators"]
|
||||
"plugins": [
|
||||
"classProperties",
|
||||
["decorators", { "decoratorsBeforeExport": false }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -9,19 +9,56 @@ describe("plugin options", function() {
|
||||
// NOTE: This test is not specific about decorators, it can be applied
|
||||
// to any plugin with options.
|
||||
|
||||
const NAME = "decorators";
|
||||
const OPT_1 = [NAME, { decoratorsBeforeExport: true }];
|
||||
const OPT_2 = [NAME, { decoratorsBeforeExport: false }];
|
||||
const SYNTAX_1 = "@dec export class C {}";
|
||||
const SYNTAX_2 = "export @dec class C {}";
|
||||
const SYNTAX_DEFAULT = "export @dec class C {}";
|
||||
|
||||
it("when they aren't specified", function() {
|
||||
expect(getParser(SYNTAX_DEFAULT, [NAME, OPT_1])).not.toThrow();
|
||||
expect(getParser(SYNTAX_DEFAULT, [NAME, OPT_2])).not.toThrow();
|
||||
const WITHOUT_FLAG = "flow";
|
||||
const WITH_FLAG = ["flow", { all: true }];
|
||||
|
||||
const CODE = "new Foo<x>(y)";
|
||||
|
||||
const AST_WITHOUT_FLAG = {
|
||||
type: "BinaryExpression",
|
||||
operator: ">",
|
||||
left: {
|
||||
type: "BinaryExpression",
|
||||
operator: "<",
|
||||
left: { type: "NewExpression" },
|
||||
right: { type: "Identifier" },
|
||||
},
|
||||
right: { type: "Identifier", extra: { parenthesized: true } },
|
||||
};
|
||||
|
||||
const AST_WITH_FLAG = {
|
||||
type: "NewExpression",
|
||||
callee: { type: "Identifier" },
|
||||
arguments: [{ type: "Identifier" }],
|
||||
typeArguments: {
|
||||
type: "TypeParameterInstantiation",
|
||||
params: [
|
||||
{ type: "GenericTypeAnnotation", id: { type: "Identifier" } },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
getParser(CODE, [WITHOUT_FLAG, WITH_FLAG])().program.body[0].expression,
|
||||
).toMatchObject(AST_WITHOUT_FLAG);
|
||||
|
||||
expect(
|
||||
getParser(CODE, [WITHOUT_FLAG])().program.body[0].expression,
|
||||
).toMatchObject(AST_WITHOUT_FLAG);
|
||||
|
||||
expect(
|
||||
getParser(CODE, [WITH_FLAG])().program.body[0].expression,
|
||||
).toMatchObject(AST_WITH_FLAG);
|
||||
});
|
||||
|
||||
it("when they are specified", function() {
|
||||
const NAME = "decorators";
|
||||
const OPT_1 = [NAME, { decoratorsBeforeExport: true }];
|
||||
const OPT_2 = [NAME, { decoratorsBeforeExport: false }];
|
||||
const SYNTAX_1 = "@dec export class C {}";
|
||||
const SYNTAX_2 = "export @dec class C {}";
|
||||
|
||||
expect(getParser(SYNTAX_1, [OPT_1, OPT_2])).not.toThrow();
|
||||
expect(getParser(SYNTAX_2, [OPT_2, OPT_1])).not.toThrow();
|
||||
expect(getParser(SYNTAX_1, [OPT_2, OPT_1])).toThrow();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-external-helpers",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "This plugin contains helper functions that’ll be placed at the top of the generated code",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-external-helpers",
|
||||
"license": "MIT",
|
||||
@@ -9,13 +9,13 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.0"
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-proposal-async-generator-functions",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "Turn async generator functions into ES2015 generators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-async-generator-functions",
|
||||
"license": "MIT",
|
||||
@@ -9,15 +9,15 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.0",
|
||||
"@babel/helper-remap-async-to-generator": "7.0.0-rc.0",
|
||||
"@babel/plugin-syntax-async-generators": "7.0.0-rc.0"
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.3",
|
||||
"@babel/helper-remap-async-to-generator": "7.0.0-rc.3",
|
||||
"@babel/plugin-syntax-async-generators": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-proposal-class-properties",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"description": "This plugin transforms static class properties as well as properties declared with the property initializer syntax",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-class-properties",
|
||||
"license": "MIT",
|
||||
@@ -9,18 +9,18 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-function-name": "7.0.0-rc.0",
|
||||
"@babel/helper-member-expression-to-functions": "7.0.0-rc.0",
|
||||
"@babel/helper-optimise-call-expression": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.0",
|
||||
"@babel/helper-replace-supers": "7.0.0-rc.0",
|
||||
"@babel/plugin-syntax-class-properties": "7.0.0-rc.0"
|
||||
"@babel/helper-function-name": "7.0.0-rc.3",
|
||||
"@babel/helper-member-expression-to-functions": "7.0.0-rc.3",
|
||||
"@babel/helper-optimise-call-expression": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.3",
|
||||
"@babel/helper-replace-supers": "7.0.0-rc.3",
|
||||
"@babel/plugin-syntax-class-properties": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,10 @@ export default declare((api, options) => {
|
||||
const classFieldDefinitionEvaluationTDZVisitor = traverse.visitors.merge([
|
||||
{
|
||||
ReferencedIdentifier(path) {
|
||||
if (this.classRef === path.scope.getBinding(path.node.name)) {
|
||||
if (
|
||||
this.classBinding &&
|
||||
this.classBinding === path.scope.getBinding(path.node.name)
|
||||
) {
|
||||
const classNameTDZError = this.file.addHelper("classNameTDZError");
|
||||
const throwNode = t.callExpression(classNameTDZError, [
|
||||
t.stringLiteral(path.node.name),
|
||||
@@ -312,7 +315,6 @@ export default declare((api, options) => {
|
||||
if (!props.length) return;
|
||||
|
||||
let ref;
|
||||
|
||||
if (path.isClassExpression() || !path.node.id) {
|
||||
nameFunction(path);
|
||||
ref = path.scope.generateUidIdentifier("class");
|
||||
@@ -327,7 +329,8 @@ export default declare((api, options) => {
|
||||
|
||||
for (const computedPath of computedPaths) {
|
||||
computedPath.traverse(classFieldDefinitionEvaluationTDZVisitor, {
|
||||
classRef: path.scope.getBinding(ref.name),
|
||||
classBinding:
|
||||
path.node.id && path.scope.getBinding(path.node.id.name),
|
||||
file: this.file,
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function dec() {}
|
||||
|
||||
class A {
|
||||
@dec a;
|
||||
|
||||
[Symbol.search]() {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
["proposal-decorators", { "legacy": true }],
|
||||
["proposal-class-properties", { "loose": true }],
|
||||
"transform-classes"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
var _class, _descriptor, _class2, _Symbol$search, _temp;
|
||||
|
||||
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object['ke' + 'ys'](descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object['define' + 'Property'](target, property, desc); desc = null; } return desc; }
|
||||
|
||||
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and set to use loose mode. ' + 'To use proposal-class-properties in spec mode with decorators, wait for ' + 'the next major version of decorators in stage 2.'); }
|
||||
|
||||
function dec() {}
|
||||
|
||||
let A = (_class = (_temp = (_Symbol$search = Symbol.search, _class2 =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function A() {
|
||||
_classCallCheck(this, A);
|
||||
|
||||
_initializerDefineProperty(this, "a", _descriptor, this);
|
||||
}
|
||||
|
||||
_createClass(A, [{
|
||||
key: _Symbol$search,
|
||||
value: function () {}
|
||||
}]);
|
||||
|
||||
return A;
|
||||
}()), _temp), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "a", [dec], {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
initializer: null
|
||||
})), _class);
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/plugin-proposal-decorators",
|
||||
"version": "7.0.0-rc.0",
|
||||
"version": "7.0.0-rc.3",
|
||||
"author": "Logan Smyth <loganfsmyth@gmail.com>",
|
||||
"license": "MIT",
|
||||
"description": "Compile class and object decorators to ES5",
|
||||
@@ -12,14 +12,14 @@
|
||||
"decorators"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.0",
|
||||
"@babel/plugin-syntax-decorators": "7.0.0-rc.0"
|
||||
"@babel/helper-plugin-utils": "7.0.0-rc.3",
|
||||
"@babel/plugin-syntax-decorators": "7.0.0-rc.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0"
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-rc.0",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.0"
|
||||
"@babel/core": "7.0.0-rc.3",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-rc.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,10 +168,18 @@ function applyTargetDecorators(path, state, decoratedProps) {
|
||||
decorators.map(dec => t.cloneNode(dec.expression)),
|
||||
),
|
||||
t.objectExpression([
|
||||
t.objectProperty(
|
||||
t.identifier("configurable"),
|
||||
t.booleanLiteral(true),
|
||||
),
|
||||
t.objectProperty(
|
||||
t.identifier("enumerable"),
|
||||
t.booleanLiteral(true),
|
||||
),
|
||||
t.objectProperty(
|
||||
t.identifier("writable"),
|
||||
t.booleanLiteral(true),
|
||||
),
|
||||
t.objectProperty(t.identifier("initializer"), initializer),
|
||||
]),
|
||||
]),
|
||||
|
||||
@@ -16,6 +16,16 @@ function dec(target, name, descriptor) {
|
||||
});
|
||||
}
|
||||
|
||||
function plainDec(target, name, descriptor) {
|
||||
expect(target).toBeTruthy();
|
||||
expect(typeof name).toBe("string");
|
||||
expect(typeof descriptor).toBe("object");
|
||||
|
||||
target.decoratedProps = (target.decoratedProps || []).concat([name]);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
class Example {
|
||||
@dec
|
||||
enumconfwrite = 1;
|
||||
@@ -40,6 +50,9 @@ class Example {
|
||||
|
||||
@dec
|
||||
_ = 8;
|
||||
|
||||
@plainDec
|
||||
plain = 9;
|
||||
}
|
||||
|
||||
const inst = new Example();
|
||||
@@ -54,6 +67,7 @@ expect(inst.decoratedProps).toEqual([
|
||||
"conf",
|
||||
"write",
|
||||
"_",
|
||||
"plain",
|
||||
]);
|
||||
|
||||
const descs = Object.getOwnPropertyDescriptors(inst);
|
||||
@@ -97,3 +111,8 @@ expect(descs._.enumerable).toBe(false);
|
||||
expect(descs._.writable).toBe(false);
|
||||
expect(descs._.configurable).toBe(false);
|
||||
expect(inst._).toBe("__8__");
|
||||
|
||||
expect(descs.plain.enumerable).toBeTruthy();
|
||||
expect(descs.plain.writable).toBeTruthy();
|
||||
expect(descs.plain.configurable).toBeTruthy();
|
||||
expect(inst.plain).toBe(9);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
function dec(target, name, descriptor) {
|
||||
expect(target).toBeTruthy();
|
||||
expect(typeof name).toBe("string");
|
||||
expect(typeof descriptor).toBe("object");
|
||||
|
||||
target.decoratedProps = (target.decoratedProps || []).concat([name]);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
class Example {
|
||||
@@ -7,5 +13,17 @@ class Example {
|
||||
}
|
||||
|
||||
let inst = new Example();
|
||||
|
||||
expect(Example.prototype).toHaveProperty("decoratedProps");
|
||||
expect(inst.decoratedProps).toEqual([
|
||||
"prop",
|
||||
]);
|
||||
|
||||
expect(inst).toHaveProperty("prop");
|
||||
expect(inst.prop).toBeUndefined();
|
||||
|
||||
const descs = Object.getOwnPropertyDescriptors(inst);
|
||||
|
||||
expect(descs.prop.enumerable).toBeTruthy();
|
||||
expect(descs.prop.writable).toBeTruthy();
|
||||
expect(descs.prop.configurable).toBeTruthy();
|
||||
|
||||
8
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8512/exec.js
vendored
Normal file
8
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8512/exec.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
function dec(Class, key, desc) {
|
||||
return desc;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
@dec
|
||||
get bar() {}
|
||||
}
|
||||
5
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8512/options.json
vendored
Normal file
5
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8512/options.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
["proposal-decorators", { "legacy": true }]
|
||||
]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user