From bcc8bfba4e38befcd9ff96bbbd3681c4a9a22779 Mon Sep 17 00:00:00 2001 From: James DiGioia Date: Tue, 14 May 2019 16:12:17 -0400 Subject: [PATCH 1/2] Implement f# pipeline in parser (#9450) --- .../babel-parser/src/parser/expression.js | 92 ++++- packages/babel-parser/src/plugin-utils.js | 2 +- packages/babel-parser/src/tokenizer/state.js | 4 + .../invalid-proposal/options.json | 2 +- .../input.js | 1 + .../options.json | 3 + .../output.json | 333 ++++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 333 ++++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 240 ++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 368 ++++++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 368 ++++++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 170 ++++++++ .../proposal-fsharp-arrow-at-head/input.js | 1 + .../options.json | 3 + .../proposal-fsharp-arrow-at-head/output.json | 170 ++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 321 +++++++++++++++ .../input.js | 3 + .../options.json | 3 + .../output.json | 316 +++++++++++++++ .../input.js | 3 + .../options.json | 3 + .../output.json | 316 +++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 316 +++++++++++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 316 +++++++++++++++ .../proposal-fsharp-await-end/input.js | 3 + .../proposal-fsharp-await-end/options.json | 3 + .../proposal-fsharp-await-end/output.json | 151 +++++++ .../proposal-fsharp-await/input.js | 3 + .../proposal-fsharp-await/options.json | 3 + .../proposal-fsharp-await/output.json | 184 +++++++++ .../proposal-fsharp-ban-await-f/input.js | 3 + .../proposal-fsharp-ban-await-f/options.json | 4 + .../proposal-fsharp-base/input.js | 1 + .../proposal-fsharp-base/options.json | 3 + .../proposal-fsharp-base/output.json | 100 +++++ .../proposal-fsharp-chain/input.js | 1 + .../proposal-fsharp-chain/options.json | 3 + .../proposal-fsharp-chain/output.json | 133 +++++++ 54 files changed, 4295 insertions(+), 19 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 8eb02c74719e..9b48c7129e2f 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -331,8 +331,11 @@ export default class ExpressionParser extends LValParser { const prec = this.state.type.binop; if (prec != null && (!noIn || !this.match(tt._in))) { if (prec > minPrec) { - const node = this.startNodeAt(leftStartPos, leftStartLoc); const operator = this.state.value; + if (operator === "|>" && this.state.inFSharpPipelineDirectBody) { + return left; + } + const node = this.startNodeAt(leftStartPos, leftStartLoc); node.left = left; node.operator = operator; if ( @@ -406,18 +409,23 @@ export default class ExpressionParser extends LValParser { prec: number, noIn: ?boolean, ): N.Expression { + const startPos = this.state.start; + const startLoc = this.state.startLoc; switch (op) { case tt.pipeline: - if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - return this.withTopicPermittingContext(() => { - return this.parseSmartPipelineBody( - this.parseExprOpBaseRightExpr(op, prec, noIn), - startPos, - startLoc, - ); - }); + switch (this.getPluginOption("pipelineOperator", "proposal")) { + case "smart": + return this.withTopicPermittingContext(() => { + return this.parseSmartPipelineBody( + this.parseExprOpBaseRightExpr(op, prec, noIn), + startPos, + startLoc, + ); + }); + case "fsharp": + return this.withSoloAwaitPermittingContext(() => { + return this.parseFSharpPipelineBody(prec, noIn); + }); } // falls through @@ -766,6 +774,8 @@ export default class ExpressionParser extends LValParser { const elts = []; let innerParenStart; let first = true; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; while (!this.eat(close)) { if (first) { @@ -804,6 +814,8 @@ export default class ExpressionParser extends LValParser { this.unexpected(); } + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + return elts; } @@ -969,7 +981,10 @@ export default class ExpressionParser extends LValParser { case tt.parenL: return this.parseParenAndDistinguishExpression(canBeArrow); - case tt.bracketL: + case tt.bracketL: { + const oldInFSharpPipelineDirectBody = this.state + .inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; node = this.startNode(); this.next(); node.elements = this.parseExprList( @@ -985,11 +1000,17 @@ export default class ExpressionParser extends LValParser { // expression by calling toReferencedListDeep. this.toReferencedList(node.elements); } + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; return this.finishNode(node, "ArrayExpression"); - - case tt.braceL: - return this.parseObj(false, refShorthandDefaultPos); - + } + case tt.braceL: { + const oldInFSharpPipelineDirectBody = this.state + .inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; + const ret = this.parseObj(false, refShorthandDefaultPos); + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + return ret; + } case tt._function: return this.parseFunctionExpression(); @@ -1177,9 +1198,11 @@ export default class ExpressionParser extends LValParser { const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; const oldYieldPos = this.state.yieldPos; const oldAwaitPos = this.state.awaitPos; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; this.state.maybeInArrowParameters = true; this.state.yieldPos = 0; this.state.awaitPos = 0; + this.state.inFSharpPipelineDirectBody = false; const innerStartPos = this.state.start; const innerStartLoc = this.state.startLoc; @@ -1233,6 +1256,7 @@ export default class ExpressionParser extends LValParser { this.expect(tt.parenR); this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; let arrowNode = this.startNodeAt(startPos, startLoc); if ( @@ -2114,7 +2138,9 @@ export default class ExpressionParser extends LValParser { ); } - node.argument = this.parseMaybeUnary(); + if (!this.state.soloAwait) { + node.argument = this.parseMaybeUnary(); + } return this.finishNode(node, "AwaitExpression"); } @@ -2304,6 +2330,17 @@ export default class ExpressionParser extends LValParser { } } + withSoloAwaitPermittingContext(callback: () => T): T { + const outerContextSoloAwaitState = this.state.soloAwait; + this.state.soloAwait = true; + + try { + return callback(); + } finally { + this.state.soloAwait = outerContextSoloAwaitState; + } + } + // Register the use of a primary topic reference (`#`) within the current // topic context. registerTopicReference(): void { @@ -2320,4 +2357,25 @@ export default class ExpressionParser extends LValParser { this.state.topicContext.maxTopicIndex >= 0 ); } + + parseFSharpPipelineBody(prec: number, noIn: ?boolean): N.Expression { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + + this.state.potentialArrowAt = this.state.start; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = true; + + const ret = this.parseExprOp( + this.parseMaybeUnary(), + startPos, + startLoc, + prec, + noIn, + ); + + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + + return ret; + } } diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index d9e368e666b9..c1cb6a6b7e92 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -38,7 +38,7 @@ export function getPluginOption( return null; } -const PIPELINE_PROPOSALS = ["minimal", "smart"]; +const PIPELINE_PROPOSALS = ["minimal", "smart", "fsharp"]; export function validatePlugins(plugins: PluginList) { if (hasPlugin(plugins, "decorators")) { diff --git a/packages/babel-parser/src/tokenizer/state.js b/packages/babel-parser/src/tokenizer/state.js index f2bf621ee68e..80842fbc5103 100644 --- a/packages/babel-parser/src/tokenizer/state.js +++ b/packages/babel-parser/src/tokenizer/state.js @@ -77,6 +77,10 @@ export default class State { maxTopicIndex: null, }; + // For the F# plugin + soloAwait: boolean = false; + inFSharpPipelineDirectBody: boolean = false; + // Check whether we are in a (nested) class or not. classLevel: number = 0; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json index 97e5a55b8f75..d8fca74323cf 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json @@ -1,4 +1,4 @@ { "plugins": [["pipelineOperator", { "proposal": "invalid" }]], - "throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: 'minimal', 'smart'" + "throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: 'minimal', 'smart', 'fsharp'" } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js new file mode 100644 index 000000000000..f06c47069191 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js @@ -0,0 +1 @@ +x => x |> [y => y + 1 |> z => z * 2] diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json new file mode 100644 index 000000000000..0ed567f15eea --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json @@ -0,0 +1,333 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "elements": [ + { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "left": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 25, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 30, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "left": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js new file mode 100644 index 000000000000..a61aacfe0129 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js @@ -0,0 +1 @@ +x => x |> [y => y + 1] |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json new file mode 100644 index 000000000000..ef37548ee98f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json @@ -0,0 +1,333 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "elements": [ + { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ] + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 26, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js new file mode 100644 index 000000000000..a760dc479126 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js @@ -0,0 +1 @@ +x => x |> foo(x = 1 |> foo); diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json new file mode 100644 index 000000000000..5f2e34747dfa --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "CallExpression", + "start": 10, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "callee": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 14, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js new file mode 100644 index 000000000000..bf7747377ff1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js @@ -0,0 +1 @@ +x => x |> { method: y => y + 1 |> z => z * 2 } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json new file mode 100644 index 000000000000..de8143714401 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json @@ -0,0 +1,368 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ObjectExpression", + "start": 10, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 12, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "method" + }, + "name": "method" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 20, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 25, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "left": { + "type": "BinaryExpression", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "left": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js new file mode 100644 index 000000000000..e797fb636228 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js @@ -0,0 +1 @@ +x => x |> { method: y => y + 1 } |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json new file mode 100644 index 000000000000..d1e39e6ccea4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json @@ -0,0 +1,368 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ObjectExpression", + "start": 10, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "method" + }, + "name": "method" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ] + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 36, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 41, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js new file mode 100644 index 000000000000..894495272a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js @@ -0,0 +1 @@ +x => x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json new file mode 100644 index 000000000000..4f7a815237e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json @@ -0,0 +1,170 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js new file mode 100644 index 000000000000..894495272a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js @@ -0,0 +1 @@ +x => x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json new file mode 100644 index 000000000000..4f7a815237e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json @@ -0,0 +1,170 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js new file mode 100644 index 000000000000..dcac94775c2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js @@ -0,0 +1 @@ +x => x |> (y => y + 3 |> (b => y + b)) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json new file mode 100644 index 000000000000..fee1e93abafb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json @@ -0,0 +1,321 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "left": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 26, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "body": { + "type": "BinaryExpression", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "extra": { + "parenthesized": true, + "parenStart": 25 + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 10 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js new file mode 100644 index 000000000000..f0867e85b19c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js @@ -0,0 +1,3 @@ +(x) => x + |> (y) => y + 1 + |> (z) => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json new file mode 100644 index 000000000000..313e3fa4b8cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 7, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "BinaryExpression", + "start": 7, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 14, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 32, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js new file mode 100644 index 000000000000..8e08f24df1fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js @@ -0,0 +1,3 @@ +x => x + |> y => y + 1 + |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json new file mode 100644 index 000000000000..cf3c546e748d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js new file mode 100644 index 000000000000..dc05467170af --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js @@ -0,0 +1 @@ +(x) => x |> (y) => y + 1 |> (z) => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json new file mode 100644 index 000000000000..06ac009ecf09 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 7, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "left": { + "type": "BinaryExpression", + "start": 7, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "left": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js new file mode 100644 index 000000000000..010117c93787 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js @@ -0,0 +1 @@ +x => x |> y => y + 1 |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json new file mode 100644 index 000000000000..31cd9f27dc38 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "left": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js new file mode 100644 index 000000000000..75e12145a31d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json new file mode 100644 index 000000000000..49c1e410dc02 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json @@ -0,0 +1,151 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 27, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "AwaitExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js new file mode 100644 index 000000000000..fb50c9400ea6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await |> f; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json new file mode 100644 index 000000000000..fa743ed7e4ad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json @@ -0,0 +1,184 @@ +{ + "type": "File", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 34, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "left": { + "type": "BinaryExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "AwaitExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "f" + }, + "name": "f" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js new file mode 100644 index 000000000000..380040513fd5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await f; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json new file mode 100644 index 000000000000..b743604f7e0f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]], + "throws": "Unexpected token, expected \";\" (2:20)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js new file mode 100644 index 000000000000..cf3443941ff0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js @@ -0,0 +1 @@ +a |> b diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json new file mode 100644 index 000000000000..fbf187592a3e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js new file mode 100644 index 000000000000..0d1e8411dd06 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js @@ -0,0 +1 @@ +x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json new file mode 100644 index 000000000000..797dec673387 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file From 3eceb2be15bd665ce5f58721b299b88f55e6c0ee Mon Sep 17 00:00:00 2001 From: Thiago Arrais Date: Sat, 25 May 2019 07:48:30 -0300 Subject: [PATCH 2/2] Transform for F# Pipeline (#9984) * Transform for F#-style await Inludes support for optimizing single-parameter arrow functions * Wait until optimization before pushing placeholder into scope --- .../src/buildOptimizedSequenceExpression.js | 54 +++++++++++++++++++ .../src/fsharpVisitor.js | 25 +++++++++ .../src/index.js | 2 + .../src/minimalVisitor.js | 48 ++++------------- .../fsharp/arrow-functions-parenless/exec.js | 27 ++++++++++ .../fixtures/fsharp/arrow-functions/exec.js | 14 +++++ .../fixtures/fsharp/arrow-functions/input.js | 14 +++++ .../fixtures/fsharp/arrow-functions/output.js | 15 ++++++ .../test/fixtures/fsharp/await/exec.js | 13 +++++ .../test/fixtures/fsharp/await/input.js | 6 +++ .../test/fixtures/fsharp/await/options.json | 9 ++++ .../test/fixtures/fsharp/await/output.js | 5 ++ .../test/fixtures/fsharp/basic/exec.js | 3 ++ .../test/fixtures/fsharp/basic/input.js | 3 ++ .../test/fixtures/fsharp/basic/output.js | 5 ++ .../fixtures/fsharp/indirect-eval/exec.js | 7 +++ .../fixtures/fsharp/indirect-eval/input.js | 7 +++ .../fixtures/fsharp/indirect-eval/output.js | 8 +++ .../fsharp/multiple-argument-use/input.js | 5 ++ .../fsharp/multiple-argument-use/output.js | 5 ++ .../fsharp/optimize-0-param-arrow/exec.js | 8 +++ .../fsharp/optimize-0-param-arrow/input.js | 8 +++ .../fsharp/optimize-0-param-arrow/output.js | 5 ++ .../test/fixtures/fsharp/options.json | 8 +++ .../minimal/arrow-functions-parenless/exec.js | 20 +++++++ .../arrow-functions-parenless/input.js | 20 +++++++ .../arrow-functions-parenless/output.js | 23 ++++++++ .../minimal/arrow-functions/output.js | 8 +-- .../minimal/multiple-argument-use/output.js | 4 +- .../src/index.js | 2 +- 30 files changed, 335 insertions(+), 46 deletions(-) create mode 100644 packages/babel-plugin-proposal-pipeline-operator/src/buildOptimizedSequenceExpression.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/options.json create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/output.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/options.json create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/output.js diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/buildOptimizedSequenceExpression.js b/packages/babel-plugin-proposal-pipeline-operator/src/buildOptimizedSequenceExpression.js new file mode 100644 index 000000000000..2d0d3f23ea8f --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/src/buildOptimizedSequenceExpression.js @@ -0,0 +1,54 @@ +import { types as t } from "@babel/core"; + +// tries to optimize sequence expressions in the format +// (a = b, ((c) => d + e)(a)) +// to +// (a = b, a + e) +const buildOptimizedSequenceExpression = ({ assign, call, path }) => { + const { left: placeholderNode, right: pipelineLeft } = assign; + const { callee: calledExpression } = call; + + let optimizeArrow = + t.isArrowFunctionExpression(calledExpression) && + t.isExpression(calledExpression.body) && + !calledExpression.async && + !calledExpression.generator; + let param; + + if (optimizeArrow) { + const { params } = calledExpression; + if (params.length === 1 && t.isIdentifier(params[0])) { + param = params[0]; + } else if (params.length > 0) { + optimizeArrow = false; + } + } else if (t.isIdentifier(calledExpression, { name: "eval" })) { + const evalSequence = t.sequenceExpression([ + t.numericLiteral(0), + calledExpression, + ]); + + call.callee = evalSequence; + + path.scope.push({ id: placeholderNode }); + + return t.sequenceExpression([assign, call]); + } + + if (optimizeArrow && !param) { + // Arrow function with 0 arguments + return t.sequenceExpression([pipelineLeft, calledExpression.body]); + } + + path.scope.push({ id: placeholderNode }); + + if (param) { + path.get("right").scope.rename(param.name, placeholderNode.name); + + return t.sequenceExpression([assign, calledExpression.body]); + } + + return t.sequenceExpression([assign, call]); +}; + +export default buildOptimizedSequenceExpression; diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js b/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js new file mode 100644 index 000000000000..f32f8e33fd99 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js @@ -0,0 +1,25 @@ +import { types as t } from "@babel/core"; +import buildOptimizedSequenceExpression from "./buildOptimizedSequenceExpression"; + +const fsharpVisitor = { + BinaryExpression(path) { + const { scope, node } = path; + const { operator, left, right } = node; + if (operator !== "|>") return; + + const placeholder = scope.generateUidIdentifierBasedOnNode(left); + + const call = + right.type === "AwaitExpression" + ? t.awaitExpression(t.cloneNode(placeholder)) + : t.callExpression(right, [t.cloneNode(placeholder)]); + const sequence = buildOptimizedSequenceExpression({ + assign: t.assignmentExpression("=", t.cloneNode(placeholder), left), + call, + path, + }); + path.replaceWith(sequence); + }, +}; + +export default fsharpVisitor; diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/index.js b/packages/babel-plugin-proposal-pipeline-operator/src/index.js index 488cd02da9e0..241a99b87828 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/src/index.js +++ b/packages/babel-plugin-proposal-pipeline-operator/src/index.js @@ -2,10 +2,12 @@ import { declare } from "@babel/helper-plugin-utils"; import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator"; import minimalVisitor from "./minimalVisitor"; import smartVisitor from "./smartVisitor"; +import fsharpVisitor from "./fsharpVisitor"; const visitorsPerProposal = { minimal: minimalVisitor, smart: smartVisitor, + fsharp: fsharpVisitor, }; export default declare((api, options) => { diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/minimalVisitor.js b/packages/babel-plugin-proposal-pipeline-operator/src/minimalVisitor.js index 960082a09591..5975949779bb 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/src/minimalVisitor.js +++ b/packages/babel-plugin-proposal-pipeline-operator/src/minimalVisitor.js @@ -1,51 +1,21 @@ import { types as t } from "@babel/core"; +import buildOptimizedSequenceExpression from "./buildOptimizedSequenceExpression"; const minimalVisitor = { BinaryExpression(path) { - const { scope } = path; - const { node } = path; - const { operator, left } = node; - let { right } = node; + const { scope, node } = path; + const { operator, left, right } = node; if (operator !== "|>") return; - let optimizeArrow = - t.isArrowFunctionExpression(right) && - t.isExpression(right.body) && - !right.async && - !right.generator; - let param; + const placeholder = scope.generateUidIdentifierBasedOnNode(left); - if (optimizeArrow) { - const { params } = right; - if (params.length === 1 && t.isIdentifier(params[0])) { - param = params[0]; - } else if (params.length > 0) { - optimizeArrow = false; - } - } else if (t.isIdentifier(right, { name: "eval" })) { - right = t.sequenceExpression([t.numericLiteral(0), right]); - } - - if (optimizeArrow && !param) { - // Arrow function with 0 arguments - path.replaceWith(t.sequenceExpression([left, right.body])); - return; - } - - const placeholder = scope.generateUidIdentifierBasedOnNode(param || left); - scope.push({ id: placeholder }); - if (param) { - path.get("right").scope.rename(param.name, placeholder.name); - } - - const call = optimizeArrow - ? right.body - : t.callExpression(right, [t.cloneNode(placeholder)]); + const call = t.callExpression(right, [t.cloneNode(placeholder)]); path.replaceWith( - t.sequenceExpression([ - t.assignmentExpression("=", t.cloneNode(placeholder), left), + buildOptimizedSequenceExpression({ + assign: t.assignmentExpression("=", t.cloneNode(placeholder), left), call, - ]), + path, + }), ); }, }; diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js new file mode 100644 index 000000000000..03ffe5328721 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js @@ -0,0 +1,27 @@ +const y = 2; + +const f = (x) => (x |> (y) => y + 1) + |> (z) => z * y + +const _f = (x) => x + |> (y) => y + 1 + |> (z) => z * y + +const g = (x) => x + |> (y) => (y + 1 |> (z) => z * y) + +const _g = (x) => x + |> (y => (y + 1 |> (z) => z * y)) + +const __g = (x) => x + |> ( + y => { + return (y + 1 |> (z) => z * y); + } + ) + +expect( f(1)).toBe(4); +expect( _f(1)).toBe(4); +expect( g(1)).toBe(2); +expect( _g(1)).toBe(2); +expect(__g(1)).toBe(2); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/exec.js new file mode 100644 index 000000000000..2411e82738ee --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/exec.js @@ -0,0 +1,14 @@ +var result = [5,10] + |> (_ => _.map(x => x * 2)) + |> (_ => _.reduce( (a,b) => a + b )) + |> (sum => sum + 1) + +expect(result).toBe(31); + + +var inc = (x) => x + 1; +var double = (x) => x * 2; + +var result2 = [4, 9].map( x => x |> inc |> double ) + +expect(result2).toEqual([10, 20]); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/input.js new file mode 100644 index 000000000000..2411e82738ee --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/input.js @@ -0,0 +1,14 @@ +var result = [5,10] + |> (_ => _.map(x => x * 2)) + |> (_ => _.reduce( (a,b) => a + b )) + |> (sum => sum + 1) + +expect(result).toBe(31); + + +var inc = (x) => x + 1; +var double = (x) => x * 2; + +var result2 = [4, 9].map( x => x |> inc |> double ) + +expect(result2).toEqual([10, 20]); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/output.js new file mode 100644 index 000000000000..cd2b80132c22 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions/output.js @@ -0,0 +1,15 @@ +var _ref, _ref2, _ref3; + +var result = (_ref = (_ref2 = (_ref3 = [5, 10], _ref3.map(x => x * 2)), _ref2.reduce((a, b) => a + b)), _ref + 1); +expect(result).toBe(31); + +var inc = x => x + 1; + +var double = x => x * 2; + +var result2 = [4, 9].map(x => { + var _ref4, _x; + + return _ref4 = (_x = x, inc(_x)), double(_ref4); +}); +expect(result2).toEqual([10, 20]); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/exec.js new file mode 100644 index 000000000000..38503c1d0d23 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/exec.js @@ -0,0 +1,13 @@ +const triple = (x) => x * 3; + +async function myFunction(n) { + return n + |> Math.abs + |> Promise.resolve + |> await + |> triple; +} + +return myFunction(-7).then(result => { + expect(result).toBe(21); +}); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/input.js new file mode 100644 index 000000000000..ad69aa432bbf --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/input.js @@ -0,0 +1,6 @@ +async function myFunction(n) { + return n + |> Math.abs + |> Promise.resolve + |> await; +} diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/options.json b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/options.json new file mode 100644 index 000000000000..c5a39e971027 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/options.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + ["proposal-pipeline-operator", { "proposal": "fsharp" }] + ], + "parserOpts": { + "allowReturnOutsideFunction": true + }, + "minNodeVersion": "8.0.0" +} diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/output.js new file mode 100644 index 000000000000..bf7848696774 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/await/output.js @@ -0,0 +1,5 @@ +async function myFunction(n) { + var _ref, _ref2, _n; + + return _ref = (_ref2 = (_n = n, Math.abs(_n)), Promise.resolve(_ref2)), await _ref; +} diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/exec.js new file mode 100644 index 000000000000..a11e8073bb3f --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/exec.js @@ -0,0 +1,3 @@ +var inc = (x) => x + 1 + +expect(10 |> inc).toBe(11); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/input.js new file mode 100644 index 000000000000..a11e8073bb3f --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/input.js @@ -0,0 +1,3 @@ +var inc = (x) => x + 1 + +expect(10 |> inc).toBe(11); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/output.js new file mode 100644 index 000000000000..6ac05ce0fbc9 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/basic/output.js @@ -0,0 +1,5 @@ +var _; + +var inc = x => x + 1; + +expect((_ = 10, inc(_))).toBe(11); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/exec.js new file mode 100644 index 000000000000..30efd15ea92a --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/exec.js @@ -0,0 +1,7 @@ +(function() { + 'use strict'; + var result = '(function() { return this; })()' + |> eval; + + expect(result).not.toBeUndefined(); +})(); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/input.js new file mode 100644 index 000000000000..30efd15ea92a --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/input.js @@ -0,0 +1,7 @@ +(function() { + 'use strict'; + var result = '(function() { return this; })()' + |> eval; + + expect(result).not.toBeUndefined(); +})(); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/output.js new file mode 100644 index 000000000000..3c53e6d4f3bf --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/indirect-eval/output.js @@ -0,0 +1,8 @@ +(function () { + 'use strict'; + + var _functionReturn; + + var result = (_functionReturn = '(function() { return this; })()', (0, eval)(_functionReturn)); + expect(result).not.toBeUndefined(); +})(); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/input.js new file mode 100644 index 000000000000..f29037ed294e --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/input.js @@ -0,0 +1,5 @@ +var array = [10,20,30]; + +var last = array |> (a => a[a.length-1]); + +expect(last).toBe(30); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/output.js new file mode 100644 index 000000000000..121f15e8a584 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/multiple-argument-use/output.js @@ -0,0 +1,5 @@ +var _array; + +var array = [10, 20, 30]; +var last = (_array = array, _array[_array.length - 1]); +expect(last).toBe(30); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/exec.js new file mode 100644 index 000000000000..d8ab9b2ebcf2 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/exec.js @@ -0,0 +1,8 @@ +var a = 1, + b = 2, + c = 3; +var result = a + |> (() => b) + |> (() => c); + +expect(result).toBe(c); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/input.js new file mode 100644 index 000000000000..d8ab9b2ebcf2 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/input.js @@ -0,0 +1,8 @@ +var a = 1, + b = 2, + c = 3; +var result = a + |> (() => b) + |> (() => c); + +expect(result).toBe(c); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/output.js new file mode 100644 index 000000000000..4fcc70527ca8 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/optimize-0-param-arrow/output.js @@ -0,0 +1,5 @@ +var a = 1, + b = 2, + c = 3; +var result = ((a, b), c); +expect(result).toBe(c); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/options.json b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/options.json new file mode 100644 index 000000000000..4e41244cc302 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + ["proposal-pipeline-operator", { "proposal": "fsharp" }] + ], + "parserOpts": { + "allowReturnOutsideFunction": true + } +} diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/exec.js new file mode 100644 index 000000000000..88762f8e568f --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/exec.js @@ -0,0 +1,20 @@ +const y = 2; +const f = (x) => x + |> (y => y + 1) + |> (z => z * y) + +const g = (x) => x + |> (y => + y + 1 + |> (z => z * y) + ) + +const h = (x) => x + |> (y => ( + y + 1 + |> (z => z * y) + )) + +expect(f(1)).toBe(4); +expect(g(1)).toBe(2); +expect(h(1)).toBe(2); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/input.js new file mode 100644 index 000000000000..88762f8e568f --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/input.js @@ -0,0 +1,20 @@ +const y = 2; +const f = (x) => x + |> (y => y + 1) + |> (z => z * y) + +const g = (x) => x + |> (y => + y + 1 + |> (z => z * y) + ) + +const h = (x) => x + |> (y => ( + y + 1 + |> (z => z * y) + )) + +expect(f(1)).toBe(4); +expect(g(1)).toBe(2); +expect(h(1)).toBe(2); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/output.js new file mode 100644 index 000000000000..926086963984 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions-parenless/output.js @@ -0,0 +1,23 @@ +const y = 2; + +const f = x => { + var _ref, _x; + + return _ref = (_x = x, _x + 1), _ref * y; +}; + +const g = x => { + var _x2, _ref2; + + return _x2 = x, (_ref2 = _x2 + 1, _ref2 * _x2); +}; + +const h = x => { + var _x3, _ref3; + + return _x3 = x, (_ref3 = _x3 + 1, _ref3 * _x3); +}; + +expect(f(1)).toBe(4); +expect(g(1)).toBe(2); +expect(h(1)).toBe(2); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions/output.js index f9e5075a4800..cd2b80132c22 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions/output.js +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/arrow-functions/output.js @@ -1,6 +1,6 @@ -var _sum, _ref, _ref2; +var _ref, _ref2, _ref3; -var result = (_sum = (_ref = (_ref2 = [5, 10], _ref2.map(x => x * 2)), _ref.reduce((a, b) => a + b)), _sum + 1); +var result = (_ref = (_ref2 = (_ref3 = [5, 10], _ref3.map(x => x * 2)), _ref2.reduce((a, b) => a + b)), _ref + 1); expect(result).toBe(31); var inc = x => x + 1; @@ -8,8 +8,8 @@ var inc = x => x + 1; var double = x => x * 2; var result2 = [4, 9].map(x => { - var _ref3, _x; + var _ref4, _x; - return _ref3 = (_x = x, inc(_x)), double(_ref3); + return _ref4 = (_x = x, inc(_x)), double(_ref4); }); expect(result2).toEqual([10, 20]); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/multiple-argument-use/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/multiple-argument-use/output.js index b26deb11cd97..121f15e8a584 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/multiple-argument-use/output.js +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/minimal/multiple-argument-use/output.js @@ -1,5 +1,5 @@ -var _a; +var _array; var array = [10, 20, 30]; -var last = (_a = array, _a[_a.length - 1]); +var last = (_array = array, _array[_array.length - 1]); expect(last).toBe(30); diff --git a/packages/babel-plugin-syntax-pipeline-operator/src/index.js b/packages/babel-plugin-syntax-pipeline-operator/src/index.js index 4cb84850ebac..df904e77644c 100644 --- a/packages/babel-plugin-syntax-pipeline-operator/src/index.js +++ b/packages/babel-plugin-syntax-pipeline-operator/src/index.js @@ -1,6 +1,6 @@ import { declare } from "@babel/helper-plugin-utils"; -export const proposals = ["minimal", "smart"]; +export const proposals = ["minimal", "smart", "fsharp"]; export default declare((api, { proposal }) => { api.assertVersion(7);