Add proposal flag to pipeline plugin (#8196)
This is going to be required so we can add support for other proposals, as well as later set the accepted proposal as the default. Update stage-0 and stage-1 presets with `pipelineProposal` to thread down to the plugin.
This commit is contained in:
committed by
Nicolò Ribaudo
parent
e1662759ed
commit
eac4c5bc17
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"presets": [["stage-0", { "decoratorsLegacy": true }], "es2015"]
|
||||
"presets": [
|
||||
["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }],
|
||||
"es2015"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]],
|
||||
"presets": [
|
||||
["stage-0", { "decoratorsLegacy": true }],
|
||||
["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }],
|
||||
"es2015"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "proposal-class-properties"],
|
||||
"presets": [
|
||||
["stage-0", { "decoratorsLegacy": true }],
|
||||
["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }],
|
||||
"es2015"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"presets": [
|
||||
"es2015",
|
||||
["stage-0", { "decoratorsLegacy": true }]
|
||||
["stage-0", { "decoratorsLegacy": true, "pipelineProposal": "minimal" }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"plugins": ["proposal-pipeline-operator"]
|
||||
"plugins": [
|
||||
["proposal-pipeline-operator", { "proposal": "minimal" }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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 }]);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user