Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement f# pipeline in parser #9450

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
mAAdhaTTah marked this conversation as resolved.
Show resolved Hide resolved
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");
mAAdhaTTah marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
mAAdhaTTah marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "fsharp" }]]
}