Merge env-standalone to babel-standalone (#10821)
* feat: add babel-preset-env to babel-standalone * chore: copy preset-env-standalone test * polish: tune warning message when babel-preset-env-standalone is loaded
This commit is contained in:
parent
a1310333f7
commit
405c1aaad8
@ -18,6 +18,7 @@
|
|||||||
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
||||||
"@babel/plugin-proposal-decorators": "^7.7.4",
|
"@babel/plugin-proposal-decorators": "^7.7.4",
|
||||||
"@babel/plugin-proposal-do-expressions": "^7.7.4",
|
"@babel/plugin-proposal-do-expressions": "^7.7.4",
|
||||||
|
"@babel/plugin-proposal-dynamic-import": "^7.7.4",
|
||||||
"@babel/plugin-proposal-export-default-from": "^7.7.4",
|
"@babel/plugin-proposal-export-default-from": "^7.7.4",
|
||||||
"@babel/plugin-proposal-export-namespace-from": "^7.7.4",
|
"@babel/plugin-proposal-export-namespace-from": "^7.7.4",
|
||||||
"@babel/plugin-proposal-function-bind": "^7.7.4",
|
"@babel/plugin-proposal-function-bind": "^7.7.4",
|
||||||
@ -48,6 +49,7 @@
|
|||||||
"@babel/plugin-syntax-object-rest-spread": "^7.7.4",
|
"@babel/plugin-syntax-object-rest-spread": "^7.7.4",
|
||||||
"@babel/plugin-syntax-optional-catch-binding": "^7.7.4",
|
"@babel/plugin-syntax-optional-catch-binding": "^7.7.4",
|
||||||
"@babel/plugin-syntax-pipeline-operator": "^7.7.7",
|
"@babel/plugin-syntax-pipeline-operator": "^7.7.7",
|
||||||
|
"@babel/plugin-syntax-top-level-await": "^7.7.4",
|
||||||
"@babel/plugin-syntax-typescript": "^7.7.4",
|
"@babel/plugin-syntax-typescript": "^7.7.4",
|
||||||
"@babel/plugin-transform-arrow-functions": "^7.7.4",
|
"@babel/plugin-transform-arrow-functions": "^7.7.4",
|
||||||
"@babel/plugin-transform-async-to-generator": "^7.7.4",
|
"@babel/plugin-transform-async-to-generator": "^7.7.4",
|
||||||
@ -71,6 +73,7 @@
|
|||||||
"@babel/plugin-transform-modules-commonjs": "^7.7.5",
|
"@babel/plugin-transform-modules-commonjs": "^7.7.5",
|
||||||
"@babel/plugin-transform-modules-systemjs": "^7.7.4",
|
"@babel/plugin-transform-modules-systemjs": "^7.7.4",
|
||||||
"@babel/plugin-transform-modules-umd": "^7.7.4",
|
"@babel/plugin-transform-modules-umd": "^7.7.4",
|
||||||
|
"@babel/plugin-transform-named-capturing-groups-regex": "^7.7.4",
|
||||||
"@babel/plugin-transform-new-target": "^7.7.4",
|
"@babel/plugin-transform-new-target": "^7.7.4",
|
||||||
"@babel/plugin-transform-object-assign": "^7.7.4",
|
"@babel/plugin-transform-object-assign": "^7.7.4",
|
||||||
"@babel/plugin-transform-object-set-prototype-of-to-assign": "^7.7.4",
|
"@babel/plugin-transform-object-set-prototype-of-to-assign": "^7.7.4",
|
||||||
@ -97,6 +100,7 @@
|
|||||||
"@babel/plugin-transform-typeof-symbol": "^7.7.4",
|
"@babel/plugin-transform-typeof-symbol": "^7.7.4",
|
||||||
"@babel/plugin-transform-typescript": "^7.7.4",
|
"@babel/plugin-transform-typescript": "^7.7.4",
|
||||||
"@babel/plugin-transform-unicode-regex": "^7.7.4",
|
"@babel/plugin-transform-unicode-regex": "^7.7.4",
|
||||||
|
"@babel/preset-env": "^7.7.4",
|
||||||
"@babel/preset-flow": "^7.7.4",
|
"@babel/preset-flow": "^7.7.4",
|
||||||
"@babel/preset-react": "^7.7.4",
|
"@babel/preset-react": "^7.7.4",
|
||||||
"@babel/preset-typescript": "^7.7.7"
|
"@babel/preset-typescript": "^7.7.7"
|
||||||
|
|||||||
@ -15,11 +15,13 @@
|
|||||||
"syntax-object-rest-spread",
|
"syntax-object-rest-spread",
|
||||||
"syntax-optional-catch-binding",
|
"syntax-optional-catch-binding",
|
||||||
"syntax-pipeline-operator",
|
"syntax-pipeline-operator",
|
||||||
|
"syntax-top-level-await",
|
||||||
"syntax-typescript",
|
"syntax-typescript",
|
||||||
"proposal-async-generator-functions",
|
"proposal-async-generator-functions",
|
||||||
"proposal-class-properties",
|
"proposal-class-properties",
|
||||||
"proposal-decorators",
|
"proposal-decorators",
|
||||||
"proposal-do-expressions",
|
"proposal-do-expressions",
|
||||||
|
"proposal-dynamic-import",
|
||||||
"proposal-export-default-from",
|
"proposal-export-default-from",
|
||||||
"proposal-export-namespace-from",
|
"proposal-export-namespace-from",
|
||||||
"proposal-function-bind",
|
"proposal-function-bind",
|
||||||
@ -57,6 +59,7 @@
|
|||||||
"transform-modules-commonjs",
|
"transform-modules-commonjs",
|
||||||
"transform-modules-systemjs",
|
"transform-modules-systemjs",
|
||||||
"transform-modules-umd",
|
"transform-modules-umd",
|
||||||
|
"transform-named-capturing-groups-regex",
|
||||||
"transform-new-target",
|
"transform-new-target",
|
||||||
"transform-object-assign",
|
"transform-object-assign",
|
||||||
"transform-object-super",
|
"transform-object-super",
|
||||||
|
|||||||
@ -19,11 +19,13 @@ import syntaxJsx from "@babel/plugin-syntax-jsx";
|
|||||||
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||||
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
||||||
import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator";
|
import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator";
|
||||||
|
import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await";
|
||||||
import syntaxTypescript from "@babel/plugin-syntax-typescript";
|
import syntaxTypescript from "@babel/plugin-syntax-typescript";
|
||||||
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
|
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
|
||||||
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
|
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
|
||||||
import proposalDecorators from "@babel/plugin-proposal-decorators";
|
import proposalDecorators from "@babel/plugin-proposal-decorators";
|
||||||
import proposalDoExpressions from "@babel/plugin-proposal-do-expressions";
|
import proposalDoExpressions from "@babel/plugin-proposal-do-expressions";
|
||||||
|
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
|
||||||
import proposalExportDefaultFrom from "@babel/plugin-proposal-export-default-from";
|
import proposalExportDefaultFrom from "@babel/plugin-proposal-export-default-from";
|
||||||
import proposalExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";
|
import proposalExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";
|
||||||
import proposalFunctionBind from "@babel/plugin-proposal-function-bind";
|
import proposalFunctionBind from "@babel/plugin-proposal-function-bind";
|
||||||
@ -61,6 +63,7 @@ import transformModulesAmd from "@babel/plugin-transform-modules-amd";
|
|||||||
import transformModulesCommonjs from "@babel/plugin-transform-modules-commonjs";
|
import transformModulesCommonjs from "@babel/plugin-transform-modules-commonjs";
|
||||||
import transformModulesSystemjs from "@babel/plugin-transform-modules-systemjs";
|
import transformModulesSystemjs from "@babel/plugin-transform-modules-systemjs";
|
||||||
import transformModulesUmd from "@babel/plugin-transform-modules-umd";
|
import transformModulesUmd from "@babel/plugin-transform-modules-umd";
|
||||||
|
import transformNamedCapturingGroupsRegex from "@babel/plugin-transform-named-capturing-groups-regex";
|
||||||
import transformNewTarget from "@babel/plugin-transform-new-target";
|
import transformNewTarget from "@babel/plugin-transform-new-target";
|
||||||
import transformObjectAssign from "@babel/plugin-transform-object-assign";
|
import transformObjectAssign from "@babel/plugin-transform-object-assign";
|
||||||
import transformObjectSuper from "@babel/plugin-transform-object-super";
|
import transformObjectSuper from "@babel/plugin-transform-object-super";
|
||||||
@ -105,11 +108,13 @@ export {
|
|||||||
syntaxObjectRestSpread,
|
syntaxObjectRestSpread,
|
||||||
syntaxOptionalCatchBinding,
|
syntaxOptionalCatchBinding,
|
||||||
syntaxPipelineOperator,
|
syntaxPipelineOperator,
|
||||||
|
syntaxTopLevelAwait,
|
||||||
syntaxTypescript,
|
syntaxTypescript,
|
||||||
proposalAsyncGeneratorFunctions,
|
proposalAsyncGeneratorFunctions,
|
||||||
proposalClassProperties,
|
proposalClassProperties,
|
||||||
proposalDecorators,
|
proposalDecorators,
|
||||||
proposalDoExpressions,
|
proposalDoExpressions,
|
||||||
|
proposalDynamicImport,
|
||||||
proposalExportDefaultFrom,
|
proposalExportDefaultFrom,
|
||||||
proposalExportNamespaceFrom,
|
proposalExportNamespaceFrom,
|
||||||
proposalFunctionBind,
|
proposalFunctionBind,
|
||||||
@ -147,6 +152,7 @@ export {
|
|||||||
transformModulesCommonjs,
|
transformModulesCommonjs,
|
||||||
transformModulesSystemjs,
|
transformModulesSystemjs,
|
||||||
transformModulesUmd,
|
transformModulesUmd,
|
||||||
|
transformNamedCapturingGroupsRegex,
|
||||||
transformNewTarget,
|
transformNewTarget,
|
||||||
transformObjectAssign,
|
transformObjectAssign,
|
||||||
transformObjectSuper,
|
transformObjectSuper,
|
||||||
@ -192,11 +198,13 @@ export const all = {
|
|||||||
"syntax-object-rest-spread": syntaxObjectRestSpread,
|
"syntax-object-rest-spread": syntaxObjectRestSpread,
|
||||||
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
|
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
|
||||||
"syntax-pipeline-operator": syntaxPipelineOperator,
|
"syntax-pipeline-operator": syntaxPipelineOperator,
|
||||||
|
"syntax-top-level-await": syntaxTopLevelAwait,
|
||||||
"syntax-typescript": syntaxTypescript,
|
"syntax-typescript": syntaxTypescript,
|
||||||
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
|
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
|
||||||
"proposal-class-properties": proposalClassProperties,
|
"proposal-class-properties": proposalClassProperties,
|
||||||
"proposal-decorators": proposalDecorators,
|
"proposal-decorators": proposalDecorators,
|
||||||
"proposal-do-expressions": proposalDoExpressions,
|
"proposal-do-expressions": proposalDoExpressions,
|
||||||
|
"proposal-dynamic-import": proposalDynamicImport,
|
||||||
"proposal-export-default-from": proposalExportDefaultFrom,
|
"proposal-export-default-from": proposalExportDefaultFrom,
|
||||||
"proposal-export-namespace-from": proposalExportNamespaceFrom,
|
"proposal-export-namespace-from": proposalExportNamespaceFrom,
|
||||||
"proposal-function-bind": proposalFunctionBind,
|
"proposal-function-bind": proposalFunctionBind,
|
||||||
@ -234,6 +242,7 @@ export const all = {
|
|||||||
"transform-modules-commonjs": transformModulesCommonjs,
|
"transform-modules-commonjs": transformModulesCommonjs,
|
||||||
"transform-modules-systemjs": transformModulesSystemjs,
|
"transform-modules-systemjs": transformModulesSystemjs,
|
||||||
"transform-modules-umd": transformModulesUmd,
|
"transform-modules-umd": transformModulesUmd,
|
||||||
|
"transform-named-capturing-groups-regex": transformNamedCapturingGroupsRegex,
|
||||||
"transform-new-target": transformNewTarget,
|
"transform-new-target": transformNewTarget,
|
||||||
"transform-object-assign": transformObjectAssign,
|
"transform-object-assign": transformObjectAssign,
|
||||||
"transform-object-super": transformObjectSuper,
|
"transform-object-super": transformObjectSuper,
|
||||||
|
|||||||
@ -21,8 +21,9 @@ import presetStage0 from "./preset-stage-0";
|
|||||||
import presetStage1 from "./preset-stage-1";
|
import presetStage1 from "./preset-stage-1";
|
||||||
import presetStage2 from "./preset-stage-2";
|
import presetStage2 from "./preset-stage-2";
|
||||||
import presetStage3 from "./preset-stage-3";
|
import presetStage3 from "./preset-stage-3";
|
||||||
import presetReact from "@babel/preset-react";
|
import presetEnv from "@babel/preset-env";
|
||||||
import presetFlow from "@babel/preset-flow";
|
import presetFlow from "@babel/preset-flow";
|
||||||
|
import presetReact from "@babel/preset-react";
|
||||||
import presetTypescript from "@babel/preset-typescript";
|
import presetTypescript from "@babel/preset-typescript";
|
||||||
|
|
||||||
import { runScripts } from "./transformScriptTags";
|
import { runScripts } from "./transformScriptTags";
|
||||||
@ -136,10 +137,16 @@ export function registerPlugins(newPlugins: {
|
|||||||
*/
|
*/
|
||||||
export function registerPreset(name: string, preset: Object | Function): void {
|
export function registerPreset(name: string, preset: Object | Function): void {
|
||||||
if (Object.prototype.hasOwnProperty.call(availablePresets, name)) {
|
if (Object.prototype.hasOwnProperty.call(availablePresets, name)) {
|
||||||
|
if (name === "env") {
|
||||||
|
console.warn(
|
||||||
|
"@babel/preset-env is now included in @babel/standalone, please remove @babel/preset-env-standalone",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
`A preset named "${name}" is already registered, it will be overridden`,
|
`A preset named "${name}" is already registered, it will be overridden`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
availablePresets[name] = preset;
|
availablePresets[name] = preset;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -163,6 +170,7 @@ registerPlugins(all);
|
|||||||
// Want to get rid of this whitelist of presets?
|
// Want to get rid of this whitelist of presets?
|
||||||
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
// Wait! Please read https://github.com/babel/babel/pull/6177 first.
|
||||||
registerPresets({
|
registerPresets({
|
||||||
|
env: presetEnv,
|
||||||
es2015: preset2015,
|
es2015: preset2015,
|
||||||
es2016: () => {
|
es2016: () => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -110,6 +110,61 @@
|
|||||||
).toThrow(/Invalid plugin specified in Babel options: "lolfail"/);
|
).toThrow(/Invalid plugin specified in Babel options: "lolfail"/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("env preset", () => {
|
||||||
|
it("works w/o targets", () => {
|
||||||
|
const output = Babel.transform("const a = 1;", {
|
||||||
|
sourceType: "script",
|
||||||
|
presets: ["env"],
|
||||||
|
}).code;
|
||||||
|
expect(output).toBe("var a = 1;");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't transpile `const` with chrome 60", () => {
|
||||||
|
const output = Babel.transform("const a = 1;", {
|
||||||
|
sourceType: "script",
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
"env",
|
||||||
|
{
|
||||||
|
targets: {
|
||||||
|
chrome: 60,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
}).code;
|
||||||
|
expect(output).toBe("const a = 1;");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("transpiles `const` with chrome 60 and preset-es2015", () => {
|
||||||
|
const output = Babel.transform("const a = 1;", {
|
||||||
|
sourceType: "script",
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
"env",
|
||||||
|
{
|
||||||
|
targets: {
|
||||||
|
chrome: 60,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"es2015",
|
||||||
|
],
|
||||||
|
}).code;
|
||||||
|
expect(output).toBe("var a = 1;");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses transform-new-targets plugin", () => {
|
||||||
|
const output = Babel.transform("function Foo() {new.target}", {
|
||||||
|
sourceType: "script",
|
||||||
|
presets: ["env"],
|
||||||
|
}).code;
|
||||||
|
expect(output).toBe(
|
||||||
|
"function Foo() {\n this instanceof Foo ? this.constructor : void 0;\n}",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("custom plugins and presets", () => {
|
describe("custom plugins and presets", () => {
|
||||||
const lolizer = () => ({
|
const lolizer = () => ({
|
||||||
visitor: {
|
visitor: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user