Skip to content

Commit

Permalink
Fix parsing of pipeline operator in arrow bodies
Browse files Browse the repository at this point in the history
This should resolve the scoping issues we're seeing in the transform.
  • Loading branch information
mAAdhaTTah committed Apr 13, 2019
1 parent 7458063 commit 7e17e56
Show file tree
Hide file tree
Showing 15 changed files with 1,720 additions and 585 deletions.
12 changes: 11 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -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 (
Expand Down Expand Up @@ -1185,9 +1188,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;
Expand Down Expand Up @@ -1241,6 +1246,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 (
Expand Down Expand Up @@ -2347,6 +2353,8 @@ export default class ExpressionParser extends LValParser {

const node = this.startNode();
this.state.potentialArrowAt = this.state.start;
const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
this.state.inFSharpPipelineDirectBody = true;

node.body = this.parseExprOp(
this.parseMaybeUnary(),
Expand All @@ -2356,6 +2364,8 @@ export default class ExpressionParser extends LValParser {
noIn,
);

this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;

return this.finishNode(node, "PipelineBody");
}
}
1 change: 1 addition & 0 deletions packages/babel-parser/src/tokenizer/state.js
Expand Up @@ -79,6 +79,7 @@ export default class State {

// For the F# plugin
soloAwait: boolean = false;
inFSharpPipelineDirectBody: boolean = false;

// Check whether we are in a (nested) class or not.
classLevel: number = 0;
Expand Down
@@ -0,0 +1 @@
x => x |> [y => y + 1] |> z => z * 2
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "fsharp" }]]
}

0 comments on commit 7e17e56

Please sign in to comment.