Pipeline Operator proposal (#742)

This commit is contained in:
Henry Zhu
2017-09-28 23:13:41 -04:00
committed by GitHub
parent 18c6b4e3e9
commit d2e06a9496
22 changed files with 968 additions and 3 deletions

View File

@@ -0,0 +1 @@
a |> b

View File

@@ -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": []
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -0,0 +1 @@
x => x |> inc |> double

View File

@@ -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": []
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -0,0 +1,4 @@
let result = "hello"
|> doubleSay
|> capitalize
|> exclaim;

View File

@@ -0,0 +1,203 @@
{
"type": "File",
"start": 0,
"end": 65,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 13
}
},
"program": {
"type": "Program",
"start": 0,
"end": 65,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 13
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 65,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 13
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 4,
"column": 12
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "result"
},
"name": "result"
},
"init": {
"type": "BinaryExpression",
"start": 13,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 4,
"column": 12
}
},
"left": {
"type": "BinaryExpression",
"start": 13,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 3,
"column": 15
}
},
"left": {
"type": "BinaryExpression",
"start": 13,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 2,
"column": 14
}
},
"left": {
"type": "StringLiteral",
"start": 13,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 20
}
},
"extra": {
"rawValue": "hello",
"raw": "\"hello\""
},
"value": "hello"
},
"operator": "|>",
"right": {
"type": "Identifier",
"start": 26,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "doubleSay"
},
"name": "doubleSay"
}
},
"operator": "|>",
"right": {
"type": "Identifier",
"start": 41,
"end": 51,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 15
},
"identifierName": "capitalize"
},
"name": "capitalize"
}
},
"operator": "|>",
"right": {
"type": "Identifier",
"start": 57,
"end": 64,
"loc": {
"start": {
"line": 4,
"column": 5
},
"end": {
"line": 4,
"column": 12
},
"identifierName": "exclaim"
},
"name": "exclaim"
}
}
}
],
"kind": "let"
}
],
"directives": []
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -0,0 +1 @@
a |> b

View File

@@ -0,0 +1,3 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'pipelineOperator' (1:5)"
}

View File

@@ -0,0 +1,2 @@
4 || 9 |> inc;
10 |> f || h |> inc

View File

@@ -0,0 +1,272 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 19
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 19
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"expression": {
"type": "BinaryExpression",
"start": 0,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"left": {
"type": "LogicalExpression",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
},
"left": {
"type": "NumericLiteral",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
},
"extra": {
"rawValue": 4,
"raw": "4"
},
"value": 4
},
"operator": "||",
"right": {
"type": "NumericLiteral",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"extra": {
"rawValue": 9,
"raw": "9"
},
"value": 9
}
},
"operator": "|>",
"right": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "inc"
},
"name": "inc"
}
}
},
{
"type": "ExpressionStatement",
"start": 15,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 19
}
},
"expression": {
"type": "BinaryExpression",
"start": 15,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 19
}
},
"left": {
"type": "BinaryExpression",
"start": 15,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 12
}
},
"left": {
"type": "NumericLiteral",
"start": 15,
"end": 17,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 2
}
},
"extra": {
"rawValue": 10,
"raw": "10"
},
"value": 10
},
"operator": "|>",
"right": {
"type": "LogicalExpression",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 12
}
},
"left": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "f"
},
"name": "f"
},
"operator": "||",
"right": {
"type": "Identifier",
"start": 26,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "h"
},
"name": "h"
}
}
},
"operator": "|>",
"right": {
"type": "Identifier",
"start": 31,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 19
},
"identifierName": "inc"
},
"name": "inc"
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -0,0 +1 @@
10 |> x => x + 1;

View File

@@ -0,0 +1,176 @@
{
"type": "File",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"program": {
"type": "Program",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "BinaryExpression",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"left": {
"type": "NumericLiteral",
"start": 0,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 2
}
},
"extra": {
"rawValue": 10,
"raw": "10"
},
"value": 10
},
"operator": "|>",
"right": {
"type": "ArrowFunctionExpression",
"start": 6,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 16
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "x"
},
"name": "x"
}
],
"body": {
"type": "BinaryExpression",
"start": 11,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 16
}
},
"left": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "x"
},
"name": "x"
},
"operator": "+",
"right": {
"type": "NumericLiteral",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["pipelineOperator"]
}