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 8110be628e..db6b4377ad 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,3 +1,6 @@ { - "presets": [["stage-0", { "decoratorsLegacy": true }], "es2015"] + "presets": [ + ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], + "es2015" + ] } 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 f5a0eb1d16..50d88253d9 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,7 @@ { "plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]], "presets": [ - ["stage-0", { "decoratorsLegacy": true }], + ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], "es2015" ] } 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 e0415a0526..e9dab83b7b 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,7 @@ { "plugins": ["external-helpers", "proposal-class-properties"], "presets": [ - ["stage-0", { "decoratorsLegacy": true }], + ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }], "es2015" ] } 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 64d67dac24..2b2c438c95 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,6 @@ { "presets": [ "es2015", - ["stage-0", { "decoratorsLegacy": true }] + ["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }] ] } diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/options.json b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/options.json index 1dece7986e..0a1dc4d010 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/options.json +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/options.json @@ -1,3 +1,5 @@ { - "plugins": ["proposal-pipeline-operator"] + "plugins": [ + ["proposal-pipeline-operator", { "proposal": "minimal" }] + ] } diff --git a/packages/babel-plugin-syntax-pipeline-operator/src/index.js b/packages/babel-plugin-syntax-pipeline-operator/src/index.js index c77a915bab..ae371a3792 100644 --- a/packages/babel-plugin-syntax-pipeline-operator/src/index.js +++ b/packages/babel-plugin-syntax-pipeline-operator/src/index.js @@ -1,11 +1,17 @@ import { declare } from "@babel/helper-plugin-utils"; -export default declare(api => { +const proposals = ["minimal"]; + +export default declare((api, { proposal }) => { api.assertVersion(7); + if (typeof proposal !== "string" || !proposals.includes(proposal)) { + throw new Error("'proposal' must be one of: " + proposals.join(", ")); + } + return { manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("pipelineOperator"); + parserOpts.plugins.push(["pipelineOperator", { proposal }]); }, }; }); diff --git a/packages/babel-preset-stage-0/src/index.js b/packages/babel-preset-stage-0/src/index.js index 855614351d..b5034e4e6c 100644 --- a/packages/babel-preset-stage-0/src/index.js +++ b/packages/babel-preset-stage-0/src/index.js @@ -6,7 +6,12 @@ import transformFunctionBind from "@babel/plugin-proposal-function-bind"; export default declare((api, opts = {}) => { api.assertVersion(7); - const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts; + const { + loose = false, + useBuiltIns = false, + decoratorsLegacy = false, + pipelineProposal, + } = opts; if (typeof loose !== "boolean") { throw new Error("@babel/preset-stage-0 'loose' option must be a boolean."); @@ -30,8 +35,21 @@ export default declare((api, opts = {}) => { ); } + if (typeof pipelineProposal !== "string") { + throw new Error( + "The pipeline operator requires a proposal set." + + " You must pass the 'pipelineProposal' option to" + + " @babel/preset-stage-0", + ); + } + return { - presets: [[presetStage1, { loose, useBuiltIns, decoratorsLegacy }]], + presets: [ + [ + presetStage1, + { loose, useBuiltIns, decoratorsLegacy, pipelineProposal }, + ], + ], plugins: [transformFunctionBind], }; }); diff --git a/packages/babel-preset-stage-1/src/index.js b/packages/babel-preset-stage-1/src/index.js index f4e47dce62..12d0c64de0 100644 --- a/packages/babel-preset-stage-1/src/index.js +++ b/packages/babel-preset-stage-1/src/index.js @@ -11,7 +11,12 @@ import transformDoExpressions from "@babel/plugin-proposal-do-expressions"; export default declare((api, opts = {}) => { api.assertVersion(7); - const { loose = false, useBuiltIns = false, decoratorsLegacy = false } = opts; + const { + loose = false, + useBuiltIns = false, + decoratorsLegacy = false, + pipelineProposal, + } = opts; if (typeof loose !== "boolean") { throw new Error("@babel/preset-stage-1 'loose' option must be a boolean."); @@ -35,13 +40,21 @@ export default declare((api, opts = {}) => { ); } + if (typeof pipelineProposal !== "string") { + throw new Error( + "The pipeline operator requires a proposal set." + + " You must pass 'pipelineProposal' option to" + + " @babel/preset-stage-1", + ); + } + return { presets: [[presetStage2, { loose, useBuiltIns, decoratorsLegacy }]], plugins: [ transformExportDefaultFrom, transformLogicalAssignmentOperators, [transformOptionalChaining, { loose }], - transformPipelineOperator, + [transformPipelineOperator, { proposal: pipelineProposal }], [transformNullishCoalescingOperator, { loose }], transformDoExpressions, ],