Skip to content

Commit

Permalink
Bring pipelineOperator flag in line with minimal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mAAdhaTTah committed Mar 29, 2018
1 parent 7a5068e commit 6cc321c
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 1,069 deletions.
38 changes: 23 additions & 15 deletions packages/babylon/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10 |> x => x + 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["pipelineOperator"],
"throws": "Unexpected arrow \"=>\" after pipeline body; arrow function in pipeline body must be parenthesized (1:6)"
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6cc321c

Please sign in to comment.