feat: support hack pipeline in @babel/standalone (#13555)

This commit is contained in:
Huáng Jùnliàng 2021-07-28 15:45:30 -04:00 committed by Nicolò Ribaudo
parent ff287ac5a5
commit 15f2f171ab
3 changed files with 48 additions and 2 deletions

View File

@ -7,7 +7,8 @@ export default (_: any, opts: any = {}) => {
useBuiltIns = false,
decoratorsLegacy = false,
decoratorsBeforeExport,
pipelineProposal = "minimal",
pipelineProposal,
pipelineTopicToken,
importAssertionsVersion = "september-2020",
} = opts;
@ -21,6 +22,7 @@ export default (_: any, opts: any = {}) => {
decoratorsLegacy,
decoratorsBeforeExport,
pipelineProposal,
pipelineTopicToken,
importAssertionsVersion,
},
],

View File

@ -8,6 +8,7 @@ export default (_: any, opts: any = {}) => {
decoratorsLegacy = false,
decoratorsBeforeExport,
pipelineProposal = "minimal",
pipelineTopicToken = "%",
recordAndTupleSyntax: recordAndTupleSyntax = "hash",
} = opts;
@ -23,7 +24,10 @@ export default (_: any, opts: any = {}) => {
[babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }],
babelPlugins.syntaxModuleBlocks,
babelPlugins.proposalExportDefaultFrom,
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
[
babelPlugins.proposalPipelineOperator,
{ proposal: pipelineProposal, topicToken: pipelineTopicToken },
],
babelPlugins.proposalDoExpressions,
],
};

View File

@ -15,5 +15,45 @@ const require = createRequire(import.meta.url);
}).code;
expect(output).toBe("0.3m;");
});
it("should support hack pipeline", () => {
const output = Babel.transform("x |> %", {
presets: [
[
"stage-1",
{
pipelineProposal: "hack",
decoratorsBeforeExport: true,
},
],
],
}).code;
expect(output).toMatchInlineSnapshot(`
"var _ref;
_ref = x, _ref;"
`);
});
it("should support hack pipeline with `#` topic token", () => {
const output = Babel.transform("x |> #", {
presets: [
[
"stage-1",
{
pipelineProposal: "hack",
pipelineTopicToken: "#",
recordAndTupleSyntax: "bar",
decoratorsBeforeExport: true,
},
],
],
}).code;
expect(output).toMatchInlineSnapshot(`
"var _ref;
_ref = x, _ref;"
`);
});
},
);