From 6cc321c3ebd2f9f9028c15839b22fe88b087cf36 Mon Sep 17 00:00:00 2001 From: James DiGioia Date: Thu, 29 Mar 2018 16:50:58 -0400 Subject: [PATCH] Bring `pipelineOperator` flag in line with minimal The minimal proposal requires parentheses around arrow functions and bans await from the pipeline. The `fsharpPipeline` flag will be responsible for enabling the await-in-pipeline behaviors. --- packages/babylon/src/parser/expression.js | 38 ++-- .../arrow-requires-parens/input.js | 1 + .../arrow-requires-parens/options.json | 4 + .../pipeline-operator/await-asi-semi/input.js | 4 - .../await-asi-semi/options.json | 3 - .../await-asi-semi/output.json | 215 ------------------ .../pipeline-operator/await-asi/input.js | 4 - .../pipeline-operator/await-asi/options.json | 3 - .../pipeline-operator/await-asi/output.json | 215 ------------------ .../pipeline-operator/await-expr/input.js | 3 - .../pipeline-operator/await-expr/options.json | 3 - .../pipeline-operator/await-expr/output.json | 200 ---------------- .../pipeline-operator/await-trailing/input.js | 3 - .../await-trailing/options.json | 3 - .../await-trailing/output.json | 183 --------------- .../pipeline-operator/await/options.json | 3 - .../pipeline-operator/await/output.json | 183 --------------- .../pipeline-operator/ban-await-f/input.js | 3 + .../ban-await-f/options.json | 4 + .../{await => ban-await}/input.js | 0 .../pipeline-operator/ban-await/options.json | 4 + .../pipeline-operator/with-arrow/input.js | 2 +- .../pipeline-operator/with-arrow/output.json | 60 ++--- 23 files changed, 72 insertions(+), 1069 deletions(-) create mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/input.js create mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/input.js delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/output.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/input.js delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/output.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/input.js delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/output.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/input.js delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/output.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await/options.json delete mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/await/output.json create mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/input.js create mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/options.json rename packages/babylon/test/fixtures/experimental/pipeline-operator/{await => ban-await}/input.js (100%) create mode 100644 packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/options.json diff --git a/packages/babylon/src/parser/expression.js b/packages/babylon/src/parser/expression.js index 28302babe03a8..80cc86c90b4c0 100644 --- a/packages/babylon/src/parser/expression.js +++ b/packages/babylon/src/parser/expression.js @@ -1960,23 +1960,31 @@ export default class ExpressionParser extends LValParser { checkPipelineAtInfixOperator(left: N.Expression, leftStartPos: number) { this.expectOnePlugin(["pipelineOperator", "smartPipelines"]); + if (this.hasPlugin("smartPipelines")) { this.checkSmartPipelineHeadEarlyErrors(left, leftStartPos); - } else if (this.hasPlugin("pipelineOperator")) { - // If `pipelineOperator` but `smartPipelines` plugin is active, then: - // pipelineOperator supports syntax such as `10 |> x => x + 1 |> f` - // grouping as `10 |> (x => x + 1) |> f`. - // - // In contrast, `smartPipelines` would require parentheses - // around the arrow function or else it would be invalid. - // - // Note that this means that, with pipelineOperator, - // `x => x |> f |> g` would be invalid, since it would group as - // `(x => x) |> f |> g`; this too is different from `smartPipelines`, - // in which `x => x |> f |> g` would be valid. - const startPos = this.state.start; - this.state.potentialArrowAt = startPos; - this.state.potentialSoloAwaitAt = startPos; + } + + if (this.hasPlugin("pipelineOperator")) { + const lookahead = this.lookahead(); + + if (lookahead.type === tt.arrow) { + throw this.raise( + this.state.start, + `Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized`, + ); + } + + if ( + this.match(tt.name) && + this.state.value === "await" && + this.state.inAsync + ) { + throw this.raise( + this.state.start, + `Unexpected "await" after pipeline body; await is banned in minimal proposal`, + ); + } } } diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/input.js new file mode 100644 index 0000000000000..a8cf1d7f87c73 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/input.js @@ -0,0 +1 @@ +10 |> x => x + 1; diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/options.json new file mode 100644 index 0000000000000..0ca16f7596624 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/arrow-requires-parens/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["pipelineOperator"], + "throws": "Unexpected arrow \"=>\" after pipeline body; arrow function in pipeline body must be parenthesized (1:6)" +} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/input.js deleted file mode 100644 index 1e62bbd8079c9..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/input.js +++ /dev/null @@ -1,4 +0,0 @@ -async function foo() { - a |> f |> await; - b -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/options.json deleted file mode 100644 index 599d48a46961c..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["pipelineOperator"] -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/output.json deleted file mode 100644 index 6202ecbdce5a5..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi-semi/output.json +++ /dev/null @@ -1,215 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 25, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "expression": { - "type": "BinaryExpression", - "start": 25, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "left": { - "type": "BinaryExpression", - "start": 25, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "left": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "|>", - "right": { - "type": "Identifier", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "f" - }, - "name": "f" - } - }, - "operator": "|>", - "right": { - "type": "AwaitExpression", - "start": 35, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 18 - } - } - } - } - }, - { - "type": "ExpressionStatement", - "start": 44, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 3 - } - }, - "expression": { - "type": "Identifier", - "start": 44, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 3 - }, - "identifierName": "b" - }, - "name": "b" - } - } - ], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/input.js deleted file mode 100644 index bb55958c9ac1b..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/input.js +++ /dev/null @@ -1,4 +0,0 @@ -async function foo() { - a |> f |> await - b -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/options.json deleted file mode 100644 index 599d48a46961c..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["pipelineOperator"] -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/output.json deleted file mode 100644 index 3415e1c3039ed..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-asi/output.json +++ /dev/null @@ -1,215 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 25, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 17 - } - }, - "expression": { - "type": "BinaryExpression", - "start": 25, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 17 - } - }, - "left": { - "type": "BinaryExpression", - "start": 25, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "left": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "|>", - "right": { - "type": "Identifier", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "f" - }, - "name": "f" - } - }, - "operator": "|>", - "right": { - "type": "AwaitExpression", - "start": 35, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 17 - } - } - } - } - }, - { - "type": "ExpressionStatement", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 3 - } - }, - "expression": { - "type": "Identifier", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 3 - }, - "identifierName": "b" - }, - "name": "b" - } - } - ], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/input.js deleted file mode 100644 index 6e3e7bff273f8..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/input.js +++ /dev/null @@ -1,3 +0,0 @@ -async function foo() { - return a |> await b |> f; -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/options.json deleted file mode 100644 index 599d48a46961c..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["pipelineOperator"] -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/output.json deleted file mode 100644 index e1aa96e1877e8..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-expr/output.json +++ /dev/null @@ -1,200 +0,0 @@ -{ - "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", - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 52, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 52, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 25, - "end": 50, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 27 - } - }, - "argument": { - "type": "BinaryExpression", - "start": 32, - "end": 49, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "left": { - "type": "BinaryExpression", - "start": 32, - "end": 44, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 21 - } - }, - "left": { - "type": "Identifier", - "start": 32, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 10 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "|>", - "right": { - "type": "AwaitExpression", - "start": 37, - "end": 44, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 21 - } - }, - "argument": { - "type": "Identifier", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 2, - "column": 20 - }, - "end": { - "line": 2, - "column": 21 - }, - "identifierName": "b" - }, - "name": "b" - } - } - }, - "operator": "|>", - "right": { - "type": "Identifier", - "start": 48, - "end": 49, - "loc": { - "start": { - "line": 2, - "column": 25 - }, - "end": { - "line": 2, - "column": 26 - }, - "identifierName": "f" - }, - "name": "f" - } - } - } - ], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/input.js deleted file mode 100644 index b5f34595a5a41..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/input.js +++ /dev/null @@ -1,3 +0,0 @@ -async function foo() { - a |> f |> await -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/options.json deleted file mode 100644 index 599d48a46961c..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["pipelineOperator"] -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/output.json deleted file mode 100644 index 976f1b780a679..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await-trailing/output.json +++ /dev/null @@ -1,183 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 25, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 17 - } - }, - "expression": { - "type": "BinaryExpression", - "start": 25, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 17 - } - }, - "left": { - "type": "BinaryExpression", - "start": 25, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "left": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "|>", - "right": { - "type": "Identifier", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "f" - }, - "name": "f" - } - }, - "operator": "|>", - "right": { - "type": "AwaitExpression", - "start": 35, - "end": 40, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 17 - } - } - } - } - } - ], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await/options.json deleted file mode 100644 index 599d48a46961c..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["pipelineOperator"] -} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/await/output.json deleted file mode 100644 index 0974b8c9c0f08..0000000000000 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/await/output.json +++ /dev/null @@ -1,183 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 25, - "end": 48, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 25 - } - }, - "argument": { - "type": "BinaryExpression", - "start": 32, - "end": 47, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 24 - } - }, - "left": { - "type": "BinaryExpression", - "start": 32, - "end": 42, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 19 - } - }, - "left": { - "type": "Identifier", - "start": 32, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 10 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "|>", - "right": { - "type": "AwaitExpression", - "start": 37, - "end": 42, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 19 - } - } - } - }, - "operator": "|>", - "right": { - "type": "Identifier", - "start": 46, - "end": 47, - "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/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/input.js new file mode 100644 index 0000000000000..d16d533ba060e --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/input.js @@ -0,0 +1,3 @@ +async function foo() { + return a |> await f |> g; +} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/options.json new file mode 100644 index 0000000000000..0ba3781636010 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await-f/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["pipelineOperator"], + "throws": "Unexpected \"await\" after pipeline body; await is banned in minimal proposal (2:14)" +} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/await/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/input.js similarity index 100% rename from packages/babylon/test/fixtures/experimental/pipeline-operator/await/input.js rename to packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/input.js diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/options.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/options.json new file mode 100644 index 0000000000000..0ba3781636010 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/ban-await/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["pipelineOperator"], + "throws": "Unexpected \"await\" after pipeline body; await is banned in minimal proposal (2:14)" +} diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/input.js b/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/input.js index a8cf1d7f87c73..ab865ac2c53fc 100644 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/input.js +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/input.js @@ -1 +1 @@ -10 |> x => x + 1; +10 |> (x => x + 1); diff --git a/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/output.json b/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/output.json index 979db6b9e659a..01ae302ad3a0b 100644 --- a/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/output.json +++ b/packages/babylon/test/fixtures/experimental/pipeline-operator/with-arrow/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 17, + "end": 19, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 17 + "column": 19 } }, "program": { "type": "Program", "start": 0, - "end": 17, + "end": 19, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 1, - "column": 17 + "column": 19 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 17, + "end": 19, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 1, - "column": 17 + "column": 19 } }, "expression": { "type": "BinaryExpression", "start": 0, - "end": 16, + "end": 18, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 1, - "column": 16 + "column": 18 } }, "left": { @@ -79,16 +79,16 @@ "operator": "|>", "right": { "type": "ArrowFunctionExpression", - "start": 6, - "end": 16, + "start": 7, + "end": 17, "loc": { "start": { "line": 1, - "column": 6 + "column": 7 }, "end": { "line": 1, - "column": 16 + "column": 17 } }, "id": null, @@ -97,16 +97,16 @@ "params": [ { "type": "Identifier", - "start": 6, - "end": 7, + "start": 7, + "end": 8, "loc": { "start": { "line": 1, - "column": 6 + "column": 7 }, "end": { "line": 1, - "column": 7 + "column": 8 }, "identifierName": "x" }, @@ -115,30 +115,30 @@ ], "body": { "type": "BinaryExpression", - "start": 11, - "end": 16, + "start": 12, + "end": 17, "loc": { "start": { "line": 1, - "column": 11 + "column": 12 }, "end": { "line": 1, - "column": 16 + "column": 17 } }, "left": { "type": "Identifier", - "start": 11, - "end": 12, + "start": 12, + "end": 13, "loc": { "start": { "line": 1, - "column": 11 + "column": 12 }, "end": { "line": 1, - "column": 12 + "column": 13 }, "identifierName": "x" }, @@ -147,16 +147,16 @@ "operator": "+", "right": { "type": "NumericLiteral", - "start": 15, - "end": 16, + "start": 16, + "end": 17, "loc": { "start": { "line": 1, - "column": 15 + "column": 16 }, "end": { "line": 1, - "column": 16 + "column": 17 } }, "extra": { @@ -165,6 +165,10 @@ }, "value": 1 } + }, + "extra": { + "parenthesized": true, + "parenStart": 6 } } }