-
-
Notifications
You must be signed in to change notification settings - Fork 258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,9 +411,16 @@ export default class Tokenizer extends LocationParser { | |
const next = this.input.charCodeAt(this.state.pos + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is ok now |
||
if (next === code) | ||
return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2); | ||
if (code === 124) { | ||
// '|>' | ||
if (next === 62) { | ||
return this.finishOp(tt.pipeline, 2); | ||
} else if (next === 125 && this.hasPlugin("flow")) { | ||
// '|}' | ||
return this.finishOp(tt.braceBarR, 2); | ||
} | ||
} | ||
if (next === 61) return this.finishOp(tt.assign, 2); | ||
if (code === 124 && next === 125 && this.hasPlugin("flow")) | ||
return this.finishOp(tt.braceBarR, 2); | ||
return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ export class TokenType { | |
this.isAssign = !!conf.isAssign; | ||
this.prefix = !!conf.prefix; | ||
this.postfix = !!conf.postfix; | ||
this.binop = conf.binop || null; | ||
this.binop = conf.binop === 0 ? 0 : conf.binop || null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be nice with ?? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, should be easy to add/use here (would be good to find this kind of code on github/codebase and then do a codemod) |
||
this.updateContext = null; | ||
} | ||
} | ||
|
@@ -131,6 +131,7 @@ export const types: { [name: string]: TokenType } = { | |
incDec: new TokenType("++/--", { prefix, postfix, startsExpr }), | ||
bang: new TokenType("!", { beforeExpr, prefix, startsExpr }), | ||
tilde: new TokenType("~", { beforeExpr, prefix, startsExpr }), | ||
pipeline: new BinopTokenType("|>", 0), | ||
logicalOR: new BinopTokenType("||", 1), | ||
logicalAND: new BinopTokenType("&&", 2), | ||
bitwiseOR: new BinopTokenType("|", 3), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a |> b | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More examples, especially arrows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"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", | ||
"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": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["pipelineOperator"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x => x |> inc |> double |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
"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, | ||
"expression": true, | ||
"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": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["pipelineOperator"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let result = "hello" | ||
|> doubleSay | ||
|> capitalize | ||
|> exclaim; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the current draft spec has this logic. I couldn't figure out how to put it into the grammar. Right now,
x |> y => z
would be a syntax error. But it's clearly useful--i'll think more about the spec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know tc39/proposal-pipeline-operator#60