From c70a32ab9dbddb5b9a370b3e9a95d1567e879e2e Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Mon, 23 Jul 2018 22:22:52 -0400 Subject: [PATCH] Throw when using Stage presets (#8293) * inline stage presets into standalone, throw error with using Stage presets --- .../misc/regression-4855/options.json | 7 +- .../private-loose/foobar/options.json | 1 - .../fixtures/public-loose/foobar/options.json | 1 - .../test/fixtures/public/foobar/options.json | 1 - .../fixtures/regression/6154/options.json | 6 +- .../legacy-regression/7030/options.json | 3 +- packages/babel-preset-stage-0/README.md | 63 ++++++++++++-- packages/babel-preset-stage-0/package.json | 13 +-- packages/babel-preset-stage-0/src/index.js | 83 +++++++++++------- packages/babel-preset-stage-1/README.md | 60 +++++++++++-- packages/babel-preset-stage-1/package.json | 18 +--- packages/babel-preset-stage-1/src/index.js | 85 +++++++++++-------- packages/babel-preset-stage-2/README.md | 52 ++++++++++-- packages/babel-preset-stage-2/package.json | 17 +--- packages/babel-preset-stage-2/src/index.js | 70 ++++++++------- packages/babel-preset-stage-3/README.md | 46 +++++++--- packages/babel-preset-stage-3/package.json | 19 +---- packages/babel-preset-stage-3/src/index.js | 67 +++++++-------- packages/babel-standalone/src/index.js | 8 +- .../babel-standalone/src/preset-es2015.js | 14 --- .../babel-standalone/src/preset-stage-0.js | 22 +++++ .../babel-standalone/src/preset-stage-1.js | 29 +++++++ .../babel-standalone/src/preset-stage-2.js | 22 +++++ .../babel-standalone/src/preset-stage-3.js | 21 +++++ scripts/generators/readmes.js | 1 + 25 files changed, 470 insertions(+), 259 deletions(-) create mode 100644 packages/babel-standalone/src/preset-stage-0.js create mode 100644 packages/babel-standalone/src/preset-stage-1.js create mode 100644 packages/babel-standalone/src/preset-stage-2.js create mode 100644 packages/babel-standalone/src/preset-stage-3.js diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json index b9463ff720..724a353072 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json @@ -1,7 +1,10 @@ { "compact": false, "presets": [ - "env", - ["stage-2", { "decoratorsLegacy": true }] + "env" + ], + "plugins": [ + "external-helpers", + "proposal-object-rest-spread" ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/foobar/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/foobar/options.json index 7968f50cf1..b207aefdde 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/foobar/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/foobar/options.json @@ -1,6 +1,5 @@ { "presets": [ - ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], "env" ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/foobar/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/foobar/options.json index 4472ee6e57..b7eb1d6c8a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/foobar/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/foobar/options.json @@ -1,7 +1,6 @@ { "plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]], "presets": [ - ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], "env" ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/foobar/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/foobar/options.json index 195ad04836..4c1b8e687e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/foobar/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/foobar/options.json @@ -1,7 +1,6 @@ { "plugins": ["external-helpers", "proposal-class-properties"], "presets": [ - ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], "env" ] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json index 934c425065..af1fe1bf40 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json @@ -1,6 +1,8 @@ { "presets": [ - "env", - ["stage-2", { "decoratorsLegacy": true }] + "env" + ], + "plugins": [ + "proposal-class-properties" ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/7030/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/7030/options.json index ff0a5398e9..b207aefdde 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/7030/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/7030/options.json @@ -1,6 +1,5 @@ { "presets": [ - "env", - ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }] + "env" ] } diff --git a/packages/babel-preset-stage-0/README.md b/packages/babel-preset-stage-0/README.md index d64efb28db..7bb6f3ba2d 100644 --- a/packages/babel-preset-stage-0/README.md +++ b/packages/babel-preset-stage-0/README.md @@ -1,19 +1,64 @@ # @babel/preset-stage-0 -> Babel preset for stage 0 plugins +> As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue [#7770](https://github.com/babel/babel/issues/7770), but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-0" -See our website [@babel/preset-stage-0](https://babeljs.io/docs/en/next/babel-preset-stage-0.html) for more information. +--- -## Install +If you want the same configuration as before: -Using npm: +```json +{ + "plugins": [ + // Stage 0 + "@babel/plugin-proposal-function-bind", -```sh -npm install --save-dev @babel/preset-stage-0 + // Stage 1 + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-logical-assignment-operators", + ["@babel/plugin-proposal-optional-chaining", { "loose": false }], + ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }], + ["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }], + "@babel/plugin-proposal-do-expressions", + + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", + + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} ``` -or using yarn: +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. -```sh -yarn add @babel/preset-stage-0 --dev +```js +module.exports = function() { + return { + plugins: [ + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... + ], + }; +}; ``` diff --git a/packages/babel-preset-stage-0/package.json b/packages/babel-preset-stage-0/package.json index e834e40d8a..8ee8e45900 100644 --- a/packages/babel-preset-stage-0/package.json +++ b/packages/babel-preset-stage-0/package.json @@ -6,16 +6,5 @@ "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-0", - "main": "lib/index.js", - "dependencies": { - "@babel/helper-plugin-utils": "7.0.0-beta.54", - "@babel/plugin-proposal-function-bind": "7.0.0-beta.54", - "@babel/preset-stage-1": "7.0.0-beta.54" - }, - "peerDependencies": { - "@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0" - }, - "devDependencies": { - "@babel/core": "7.0.0-beta.54" - } + "main": "lib/index.js" } diff --git a/packages/babel-preset-stage-0/src/index.js b/packages/babel-preset-stage-0/src/index.js index 84e1a9d3b8..10186ec092 100644 --- a/packages/babel-preset-stage-0/src/index.js +++ b/packages/babel-preset-stage-0/src/index.js @@ -1,39 +1,60 @@ -import { declare } from "@babel/helper-plugin-utils"; -import presetStage1 from "@babel/preset-stage-1"; +export default function() { + throw new Error(` +As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue #7770: https://github.com/babel/babel/issues/7770, but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-0" -import transformFunctionBind from "@babel/plugin-proposal-function-bind"; +If you want the same configuration as before: -export default declare((api, opts = {}) => { - api.assertVersion(7); +{ + "plugins": [ + // Stage 0 + "@babel/plugin-proposal-function-bind", - const { - loose = false, - useBuiltIns = false, - decoratorsLegacy = true, - pipelineProposal = "minimal", - } = opts; + // Stage 1 + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-logical-assignment-operators", + ["@babel/plugin-proposal-optional-chaining", { "loose": false }], + ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }], + ["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }], + "@babel/plugin-proposal-do-expressions", - if (typeof loose !== "boolean") { - throw new Error("@babel/preset-stage-0 'loose' option must be a boolean."); - } - if (typeof useBuiltIns !== "boolean") { - throw new Error( - "@babel/preset-stage-0 'useBuiltIns' option must be a boolean.", - ); - } - if (typeof decoratorsLegacy !== "boolean") { - throw new Error( - "@babel/preset-stage-0 'decoratorsLegacy' option must be a boolean.", - ); - } + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} + +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. + +module.exports = function() { return { - presets: [ - [ - presetStage1, - { loose, useBuiltIns, decoratorsLegacy, pipelineProposal }, - ], + plugins: [ + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... ], - plugins: [transformFunctionBind], }; -}); +}; + `); +} diff --git a/packages/babel-preset-stage-1/README.md b/packages/babel-preset-stage-1/README.md index 16a67afb62..1f1b567baf 100644 --- a/packages/babel-preset-stage-1/README.md +++ b/packages/babel-preset-stage-1/README.md @@ -1,19 +1,61 @@ # @babel/preset-stage-1 -> Babel preset for stage 1 plugins +> As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue [#7770](https://github.com/babel/babel/issues/7770), but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-1" -See our website [@babel/preset-stage-1](https://babeljs.io/docs/en/next/babel-preset-stage-1.html) for more information. +--- -## Install +If you want the same configuration as before: -Using npm: +```json +{ + "plugins": [ + // Stage 1 + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-logical-assignment-operators", + ["@babel/plugin-proposal-optional-chaining", { "loose": false }], + ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }], + ["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }], + "@babel/plugin-proposal-do-expressions", -```sh -npm install --save-dev @babel/preset-stage-1 + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", + + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} ``` -or using yarn: +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. -```sh -yarn add @babel/preset-stage-1 --dev +```js +module.exports = function() { + return { + plugins: [ + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... + ], + }; +}; ``` diff --git a/packages/babel-preset-stage-1/package.json b/packages/babel-preset-stage-1/package.json index b34caaa827..0e85d28455 100644 --- a/packages/babel-preset-stage-1/package.json +++ b/packages/babel-preset-stage-1/package.json @@ -6,21 +6,5 @@ "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-1", - "main": "lib/index.js", - "dependencies": { - "@babel/helper-plugin-utils": "7.0.0-beta.54", - "@babel/plugin-proposal-do-expressions": "7.0.0-beta.54", - "@babel/plugin-proposal-export-default-from": "7.0.0-beta.54", - "@babel/plugin-proposal-logical-assignment-operators": "7.0.0-beta.54", - "@babel/plugin-proposal-nullish-coalescing-operator": "7.0.0-beta.54", - "@babel/plugin-proposal-optional-chaining": "7.0.0-beta.54", - "@babel/plugin-proposal-pipeline-operator": "7.0.0-beta.54", - "@babel/preset-stage-2": "7.0.0-beta.54" - }, - "peerDependencies": { - "@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0" - }, - "devDependencies": { - "@babel/core": "7.0.0-beta.54" - } + "main": "lib/index.js" } diff --git a/packages/babel-preset-stage-1/src/index.js b/packages/babel-preset-stage-1/src/index.js index 6324c7ac2d..0544c93948 100644 --- a/packages/babel-preset-stage-1/src/index.js +++ b/packages/babel-preset-stage-1/src/index.js @@ -1,46 +1,57 @@ -import { declare } from "@babel/helper-plugin-utils"; -import presetStage2 from "@babel/preset-stage-2"; +export default function() { + throw new Error(` +As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue #7770: https://github.com/babel/babel/issues/7770, but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-1" -import transformExportDefaultFrom from "@babel/plugin-proposal-export-default-from"; -import transformLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators"; -import transformOptionalChaining from "@babel/plugin-proposal-optional-chaining"; -import transformPipelineOperator from "@babel/plugin-proposal-pipeline-operator"; -import transformNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator"; -import transformDoExpressions from "@babel/plugin-proposal-do-expressions"; +If you want the same configuration as before: -export default declare((api, opts = {}) => { - api.assertVersion(7); +{ + "plugins": [ + // Stage 1 + "@babel/plugin-proposal-export-default-from", + "@babel/plugin-proposal-logical-assignment-operators", + ["@babel/plugin-proposal-optional-chaining", { "loose": false }], + ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }], + ["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }], + "@babel/plugin-proposal-do-expressions", - const { - loose = false, - useBuiltIns = false, - decoratorsLegacy = true, - pipelineProposal = "minimal", - } = opts; + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", - if (typeof loose !== "boolean") { - throw new Error("@babel/preset-stage-1 'loose' option must be a boolean."); - } - if (typeof useBuiltIns !== "boolean") { - throw new Error( - "@babel/preset-stage-1 'useBuiltIns' option must be a boolean.", - ); - } - if (typeof decoratorsLegacy !== "boolean") { - throw new Error( - "@babel/preset-stage-1 'decoratorsLegacy' option must be a boolean.", - ); - } + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. + +module.exports = function() { return { - presets: [[presetStage2, { loose, useBuiltIns, decoratorsLegacy }]], plugins: [ - transformExportDefaultFrom, - transformLogicalAssignmentOperators, - [transformOptionalChaining, { loose }], - [transformPipelineOperator, { proposal: pipelineProposal }], - [transformNullishCoalescingOperator, { loose }], - transformDoExpressions, + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... ], }; -}); +}; +`); +} diff --git a/packages/babel-preset-stage-2/README.md b/packages/babel-preset-stage-2/README.md index 9f1b36fd34..61ca252147 100644 --- a/packages/babel-preset-stage-2/README.md +++ b/packages/babel-preset-stage-2/README.md @@ -1,19 +1,53 @@ # @babel/preset-stage-2 -> Babel preset for stage 2 plugins +> As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue [#7770](https://github.com/babel/babel/issues/7770), but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-2" -See our website [@babel/preset-stage-2](https://babeljs.io/docs/en/next/babel-preset-stage-2.html) for more information. +--- -## Install +If you want the same configuration as before: -Using npm: +```json +{ + "plugins": [ + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", -```sh -npm install --save-dev @babel/preset-stage-2 + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} ``` -or using yarn: +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. -```sh -yarn add @babel/preset-stage-2 --dev +```js +module.exports = function() { + return { + plugins: [ + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... + ], + }; +}; ``` diff --git a/packages/babel-preset-stage-2/package.json b/packages/babel-preset-stage-2/package.json index 9b2961ea23..37fe829975 100644 --- a/packages/babel-preset-stage-2/package.json +++ b/packages/babel-preset-stage-2/package.json @@ -6,20 +6,5 @@ "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-2", - "main": "lib/index.js", - "dependencies": { - "@babel/helper-plugin-utils": "7.0.0-beta.54", - "@babel/plugin-proposal-decorators": "7.0.0-beta.54", - "@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.54", - "@babel/plugin-proposal-function-sent": "7.0.0-beta.54", - "@babel/plugin-proposal-numeric-separator": "7.0.0-beta.54", - "@babel/plugin-proposal-throw-expressions": "7.0.0-beta.54", - "@babel/preset-stage-3": "7.0.0-beta.54" - }, - "peerDependencies": { - "@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0" - }, - "devDependencies": { - "@babel/core": "7.0.0-beta.54" - } + "main": "lib/index.js" } diff --git a/packages/babel-preset-stage-2/src/index.js b/packages/babel-preset-stage-2/src/index.js index 8b20233bb9..f1d206dcb6 100644 --- a/packages/babel-preset-stage-2/src/index.js +++ b/packages/babel-preset-stage-2/src/index.js @@ -1,39 +1,49 @@ -import { declare } from "@babel/helper-plugin-utils"; -import presetStage3 from "@babel/preset-stage-3"; +export default function() { + throw new Error(` +As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue #7770: https://github.com/babel/babel/issues/7770, but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-2" -import transformDecorators from "@babel/plugin-proposal-decorators"; -import transformFunctionSent from "@babel/plugin-proposal-function-sent"; -import transformExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from"; -import transformNumericSeparator from "@babel/plugin-proposal-numeric-separator"; -import transformThrowExpressions from "@babel/plugin-proposal-throw-expressions"; +If you want the same configuration as before: -export default declare((api, opts = {}) => { - api.assertVersion(7); +{ + "plugins": [ + // Stage 2 + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions", - const { loose = false, useBuiltIns = false, decoratorsLegacy = true } = opts; + // Stage 3 + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} - if (typeof loose !== "boolean") { - throw new Error("@babel/preset-stage-2 'loose' option must be a boolean."); - } - if (typeof useBuiltIns !== "boolean") { - throw new Error( - "@babel/preset-stage-2 'useBuiltIns' option must be a boolean.", - ); - } - if (typeof decoratorsLegacy !== "boolean") { - throw new Error( - "@babel/preset-stage-2 'decoratorsLegacy' option must be a boolean.", - ); - } +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. +module.exports = function() { return { - presets: [[presetStage3, { loose, useBuiltIns }]], plugins: [ - [transformDecorators, { legacy: decoratorsLegacy }], - transformFunctionSent, - transformExportNamespaceFrom, - transformNumericSeparator, - transformThrowExpressions, + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... ], }; -}); +}; +`); +} diff --git a/packages/babel-preset-stage-3/README.md b/packages/babel-preset-stage-3/README.md index fe5de4e5c2..1685676b70 100644 --- a/packages/babel-preset-stage-3/README.md +++ b/packages/babel-preset-stage-3/README.md @@ -1,19 +1,45 @@ # @babel/preset-stage-3 -> Babel preset for stage 3 plugins +> As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue [#7770](https://github.com/babel/babel/issues/7770), but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-3" -See our website [@babel/preset-stage-3](https://babeljs.io/docs/en/next/babel-preset-stage-3.html) for more information. +--- -## Install +If you want the same configuration as before: -Using npm: - -```sh -npm install --save-dev @babel/preset-stage-3 +```json +{ + "plugins": [ + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} ``` -or using yarn: +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. -```sh -yarn add @babel/preset-stage-3 --dev +```js +module.exports = function() { + return { + plugins: [ + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... + ], + }; +}; ``` diff --git a/packages/babel-preset-stage-3/package.json b/packages/babel-preset-stage-3/package.json index 04a0001db0..02a2c939e9 100644 --- a/packages/babel-preset-stage-3/package.json +++ b/packages/babel-preset-stage-3/package.json @@ -6,22 +6,5 @@ "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-3", - "main": "lib/index.js", - "dependencies": { - "@babel/helper-plugin-utils": "7.0.0-beta.54", - "@babel/plugin-proposal-async-generator-functions": "7.0.0-beta.54", - "@babel/plugin-proposal-class-properties": "7.0.0-beta.54", - "@babel/plugin-proposal-json-strings": "7.0.0-beta.54", - "@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.54", - "@babel/plugin-proposal-optional-catch-binding": "7.0.0-beta.54", - "@babel/plugin-proposal-unicode-property-regex": "7.0.0-beta.54", - "@babel/plugin-syntax-dynamic-import": "7.0.0-beta.54", - "@babel/plugin-syntax-import-meta": "7.0.0-beta.54" - }, - "peerDependencies": { - "@babel/core": ">=7.0.0-beta.50 <7.0.0-rc.0" - }, - "devDependencies": { - "@babel/core": "7.0.0-beta.54" - } + "main": "lib/index.js" } diff --git a/packages/babel-preset-stage-3/src/index.js b/packages/babel-preset-stage-3/src/index.js index 4562067b4e..1ab5ae5996 100644 --- a/packages/babel-preset-stage-3/src/index.js +++ b/packages/babel-preset-stage-3/src/index.js @@ -1,43 +1,42 @@ -import { declare } from "@babel/helper-plugin-utils"; -import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import"; -import syntaxImportMeta from "@babel/plugin-syntax-import-meta"; -import transformAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions"; -import transformClassProperties from "@babel/plugin-proposal-class-properties"; -import transformJsonStrings from "@babel/plugin-proposal-json-strings"; -import transformObjectRestSpread from "@babel/plugin-proposal-object-rest-spread"; -import transformOptionalCatchBinding from "@babel/plugin-proposal-optional-catch-binding"; -import transformUnicodePropertyRegex from "@babel/plugin-proposal-unicode-property-regex"; +export default function() { + throw new Error(` +As of v7.0.0-beta.54, we've decided to remove +the official Babel Stage presets. You can find more information +at issue #7770: https://github.com/babel/babel/issues/7770, but +the TL;DR is that it's causing more harm than convenience in that +the preset is always out of date, each change is usually going to +require a major version bump and thus people will be behind, +and it encouraged too many people to opt-in to too many proposals +that they didn't intend to. This is intended to be the last publish +of "@babel/preset-stage-3" -export default declare((api, opts) => { - api.assertVersion(7); +If you want the same configuration as before: - let loose = false; - let useBuiltIns = false; +{ + "plugins": [ + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + ["@babel/plugin-proposal-class-properties", { "loose": false }], + "@babel/plugin-proposal-json-strings" + ] +} - if (opts !== undefined) { - if (opts.loose !== undefined) loose = opts.loose; - if (opts.useBuiltIns !== undefined) useBuiltIns = opts.useBuiltIns; - } - if (typeof loose !== "boolean") { - throw new Error("@babel/preset-stage-3 'loose' option must be a boolean."); - } - if (typeof useBuiltIns !== "boolean") { - throw new Error( - "@babel/preset-stage-3 'useBuiltIns' option must be a boolean.", - ); - } +If you're using the same configuration across many separate projects, +keep in mind that you can also create your own custom presets with +whichever plugins and presets you're looking to use. +module.exports = function() { return { plugins: [ - syntaxDynamicImport, - syntaxImportMeta, - transformAsyncGeneratorFunctions, - [transformClassProperties, { loose }], - transformJsonStrings, - [transformObjectRestSpread, { loose, useBuiltIns }], - transformOptionalCatchBinding, - transformUnicodePropertyRegex, + require("@babel/plugin-syntax-dynamic-import"), + [require("@babel/plugin-proposal-decorators"), { "legacy": true }], + [require("@babel/plugin-proposal-class-properties"), { "loose": false }], + ], + presets: [ + // ... ], }; -}); +}; +`); +} diff --git a/packages/babel-standalone/src/index.js b/packages/babel-standalone/src/index.js index 03fa91efbe..10fad226a9 100644 --- a/packages/babel-standalone/src/index.js +++ b/packages/babel-standalone/src/index.js @@ -233,10 +233,10 @@ registerPresets({ }; }, react: require("@babel/preset-react"), - "stage-0": require("@babel/preset-stage-0"), - "stage-1": require("@babel/preset-stage-1"), - "stage-2": require("@babel/preset-stage-2"), - "stage-3": require("@babel/preset-stage-3"), + "stage-0": require("./preset-stage-0"), + "stage-1": require("./preset-stage-1"), + "stage-2": require("./preset-stage-2"), + "stage-3": require("./preset-stage-3"), "es2015-loose": { presets: [[require("./preset-es2015"), { loose: true }]], }, diff --git a/packages/babel-standalone/src/preset-es2015.js b/packages/babel-standalone/src/preset-es2015.js index 9f21ae59a8..c06632f654 100644 --- a/packages/babel-standalone/src/preset-es2015.js +++ b/packages/babel-standalone/src/preset-es2015.js @@ -24,7 +24,6 @@ import transformES2015Instanceof from "@babel/plugin-transform-instanceof"; import transformRegenerator from "@babel/plugin-transform-regenerator"; export default (_, opts) => { - const moduleTypes = ["commonjs", "cjs", "amd", "umd", "systemjs"]; let loose = false; let modules = "commonjs"; let spec = false; @@ -35,19 +34,6 @@ export default (_, opts) => { if (opts.spec !== undefined) spec = opts.spec; } - if (typeof loose !== "boolean") { - throw new Error("Preset es2015 'loose' option must be a boolean."); - } - if (typeof spec !== "boolean") { - throw new Error("Preset es2015 'spec' option must be a boolean."); - } - if (modules !== false && moduleTypes.indexOf(modules) === -1) { - throw new Error( - "Preset es2015 'modules' option must be 'false' to indicate no modules\n" + - "or a module type which be be one of: 'commonjs' (default), 'amd', 'umd', 'systemjs'", - ); - } - // be DRY const optsLoose = { loose }; diff --git a/packages/babel-standalone/src/preset-stage-0.js b/packages/babel-standalone/src/preset-stage-0.js new file mode 100644 index 0000000000..d9b011bba0 --- /dev/null +++ b/packages/babel-standalone/src/preset-stage-0.js @@ -0,0 +1,22 @@ +import presetStage1 from "./preset-stage-1"; + +import transformFunctionBind from "@babel/plugin-proposal-function-bind"; + +export default (_, opts = {}) => { + const { + loose = false, + useBuiltIns = false, + decoratorsLegacy = false, + pipelineProposal = "minimal", + } = opts; + + return { + presets: [ + [ + presetStage1, + { loose, useBuiltIns, decoratorsLegacy, pipelineProposal }, + ], + ], + plugins: [transformFunctionBind], + }; +}; diff --git a/packages/babel-standalone/src/preset-stage-1.js b/packages/babel-standalone/src/preset-stage-1.js new file mode 100644 index 0000000000..b5f2556ec7 --- /dev/null +++ b/packages/babel-standalone/src/preset-stage-1.js @@ -0,0 +1,29 @@ +import presetStage2 from "./preset-stage-2"; + +import transformExportDefaultFrom from "@babel/plugin-proposal-export-default-from"; +import transformLogicalAssignmentOperators from "@babel/plugin-proposal-logical-assignment-operators"; +import transformOptionalChaining from "@babel/plugin-proposal-optional-chaining"; +import transformPipelineOperator from "@babel/plugin-proposal-pipeline-operator"; +import transformNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator"; +import transformDoExpressions from "@babel/plugin-proposal-do-expressions"; + +export default (_, opts = {}) => { + const { + loose = false, + useBuiltIns = false, + decoratorsLegacy = false, + pipelineProposal = "minimal", + } = opts; + + return { + presets: [[presetStage2, { loose, useBuiltIns, decoratorsLegacy }]], + plugins: [ + transformExportDefaultFrom, + transformLogicalAssignmentOperators, + [transformOptionalChaining, { loose }], + [transformPipelineOperator, { proposal: pipelineProposal }], + [transformNullishCoalescingOperator, { loose }], + transformDoExpressions, + ], + }; +}; diff --git a/packages/babel-standalone/src/preset-stage-2.js b/packages/babel-standalone/src/preset-stage-2.js new file mode 100644 index 0000000000..b11c760883 --- /dev/null +++ b/packages/babel-standalone/src/preset-stage-2.js @@ -0,0 +1,22 @@ +import presetStage3 from "./preset-stage-3"; + +import transformDecorators from "@babel/plugin-proposal-decorators"; +import transformFunctionSent from "@babel/plugin-proposal-function-sent"; +import transformExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from"; +import transformNumericSeparator from "@babel/plugin-proposal-numeric-separator"; +import transformThrowExpressions from "@babel/plugin-proposal-throw-expressions"; + +export default (_, opts = {}) => { + const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts; + + return { + presets: [[presetStage3, { loose, useBuiltIns }]], + plugins: [ + [transformDecorators, { legacy: decoratorsLegacy }], + transformFunctionSent, + transformExportNamespaceFrom, + transformNumericSeparator, + transformThrowExpressions, + ], + }; +}; diff --git a/packages/babel-standalone/src/preset-stage-3.js b/packages/babel-standalone/src/preset-stage-3.js new file mode 100644 index 0000000000..e16237dbcd --- /dev/null +++ b/packages/babel-standalone/src/preset-stage-3.js @@ -0,0 +1,21 @@ +import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import"; +import syntaxImportMeta from "@babel/plugin-syntax-import-meta"; +import transformClassProperties from "@babel/plugin-proposal-class-properties"; +import transformJsonStrings from "@babel/plugin-proposal-json-strings"; + +export default (_, opts) => { + let loose = false; + + if (opts !== undefined) { + if (opts.loose !== undefined) loose = opts.loose; + } + + return { + plugins: [ + syntaxDynamicImport, + syntaxImportMeta, + [transformClassProperties, { loose }], + transformJsonStrings, + ], + }; +}; diff --git a/scripts/generators/readmes.js b/scripts/generators/readmes.js index 04d754c9a0..1ab0b25214 100644 --- a/scripts/generators/readmes.js +++ b/scripts/generators/readmes.js @@ -66,6 +66,7 @@ yarn add ${name} --dev packages .filter(x => x !== "README.md") // ignore root readme + .filter(x => x.indexOf("babel-preset-stage-") === -1) // ignore stages .forEach(id => { const { name, description } = getPackageJson(id); const readmePath = join(packageDir, id, "README.md");