From 3dc403974c218b868bde74999e59b7402a64318f Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Mon, 2 Jan 2017 13:13:53 +0400 Subject: [PATCH] flow: allow leading pipes in all positions (#256) --- src/plugins/flow.js | 15 +- .../good_14/actual.js | 1 + .../good_14/expected.json | 214 +++++++ test/fixtures/flow/type-alias/4/actual.js | 12 + test/fixtures/flow/type-alias/4/expected.json | 556 +++++++++++++++++- test/fixtures/flow/type-alias/5/5.js | 9 + test/fixtures/flow/type-alias/5/expected.json | 33 ++ .../flow/type-annotations/129/actual.js | 4 + .../flow/type-annotations/129/expected.json | 176 ++++++ .../flow/type-annotations/130/actual.js | 1 + .../flow/type-annotations/130/expected.json | 296 ++++++++++ .../negative-number-literal/expected.json | 25 +- 12 files changed, 1304 insertions(+), 38 deletions(-) create mode 100644 test/fixtures/flow/anonymous-function-types/good_14/actual.js create mode 100644 test/fixtures/flow/anonymous-function-types/good_14/expected.json create mode 100644 test/fixtures/flow/type-alias/5/5.js create mode 100644 test/fixtures/flow/type-alias/5/expected.json create mode 100644 test/fixtures/flow/type-annotations/129/actual.js create mode 100644 test/fixtures/flow/type-annotations/129/expected.json create mode 100644 test/fixtures/flow/type-annotations/130/actual.js create mode 100644 test/fixtures/flow/type-annotations/130/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 5114fd8e24..8b9c2048dc 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -7,15 +7,11 @@ import Parser from "../parser"; let pp = Parser.prototype; -pp.flowParseTypeInitialiser = function (tok, allowLeadingPipeOrAnd) { +pp.flowParseTypeInitialiser = function (tok) { let oldInType = this.state.inType; this.state.inType = true; this.expect(tok || tt.colon); - if (allowLeadingPipeOrAnd) { - if (this.match(tt.bitwiseAND) || this.match(tt.bitwiseOR)) { - this.next(); - } - } + let type = this.flowParseType(); this.state.inType = oldInType; return type; @@ -193,10 +189,7 @@ pp.flowParseTypeAlias = function (node) { node.typeParameters = null; } - node.right = this.flowParseTypeInitialiser( - tt.eq, - /*allowLeadingPipeOrAnd*/ true - ); + node.right = this.flowParseTypeInitialiser(tt.eq); this.semicolon(); return this.finishNode(node, "TypeAlias"); @@ -729,6 +722,7 @@ pp.flowParseAnonFunctionWithoutParens = function () { pp.flowParseIntersectionType = function () { let node = this.startNode(); + this.eat(tt.bitwiseAND); let type = this.flowParseAnonFunctionWithoutParens(); node.types = [type]; while (this.eat(tt.bitwiseAND)) { @@ -739,6 +733,7 @@ pp.flowParseIntersectionType = function () { pp.flowParseUnionType = function () { let node = this.startNode(); + this.eat(tt.bitwiseOR); let type = this.flowParseIntersectionType(); node.types = [type]; while (this.eat(tt.bitwiseOR)) { diff --git a/test/fixtures/flow/anonymous-function-types/good_14/actual.js b/test/fixtures/flow/anonymous-function-types/good_14/actual.js new file mode 100644 index 0000000000..9aa90c112e --- /dev/null +++ b/test/fixtures/flow/anonymous-function-types/good_14/actual.js @@ -0,0 +1 @@ +var f = (x): | 1 | 2 => 1; diff --git a/test/fixtures/flow/anonymous-function-types/good_14/expected.json b/test/fixtures/flow/anonymous-function-types/good_14/expected.json new file mode 100644 index 0000000000..3aa12410f0 --- /dev/null +++ b/test/fixtures/flow/anonymous-function-types/good_14/expected.json @@ -0,0 +1,214 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "f" + }, + "name": "f" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 8, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 11, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "typeAnnotation": { + "type": "UnionTypeAnnotation", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "types": [ + { + "type": "NumericLiteralTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": 1, + "extra": { + "rawValue": 1, + "raw": "1" + } + }, + { + "type": "NumericLiteralTypeAnnotation", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "value": 2, + "extra": { + "rawValue": 2, + "raw": "2" + } + } + ] + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-alias/4/actual.js b/test/fixtures/flow/type-alias/4/actual.js index 9561e96fd3..a7802ea8df 100644 --- a/test/fixtures/flow/type-alias/4/actual.js +++ b/test/fixtures/flow/type-alias/4/actual.js @@ -7,3 +7,15 @@ type overloads = & ((x: string) => number) & ((x: number) => string) ; + +type union2 = { + x: + | {type: "A"} + | {type: "B"} +}; + +type overloads2 = { + x: + & {type: "A"} + & {type: "B"} +}; diff --git a/test/fixtures/flow/type-alias/4/expected.json b/test/fixtures/flow/type-alias/4/expected.json index 2f90efab42..829a4048e2 100644 --- a/test/fixtures/flow/type-alias/4/expected.json +++ b/test/fixtures/flow/type-alias/4/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 120, + "end": 246, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 9, - "column": 1 + "line": 21, + "column": 2 } }, "program": { "type": "Program", "start": 0, - "end": 120, + "end": 246, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 9, - "column": 1 + "line": 21, + "column": 2 } }, "sourceType": "module", @@ -54,19 +54,20 @@ "end": { "line": 1, "column": 10 - } + }, + "identifierName": "union" }, "name": "union" }, "typeParameters": null, "right": { "type": "UnionTypeAnnotation", - "start": 16, + "start": 14, "end": 42, "loc": { "start": { "line": 2, - "column": 3 + "column": 1 }, "end": { "line": 3, @@ -116,7 +117,8 @@ "end": { "line": 2, "column": 8 - } + }, + "identifierName": "type" }, "name": "type" }, @@ -141,10 +143,12 @@ } }, "optional": false, + "static": false, "variance": null } ], - "indexers": [] + "indexers": [], + "exact": false }, { "type": "ObjectTypeAnnotation", @@ -188,7 +192,8 @@ "end": { "line": 3, "column": 8 - } + }, + "identifierName": "type" }, "name": "type" }, @@ -213,10 +218,12 @@ } }, "optional": false, + "static": false, "variance": null } ], - "indexers": [] + "indexers": [], + "exact": false } ] } @@ -247,19 +254,20 @@ "end": { "line": 6, "column": 14 - } + }, + "identifierName": "overloads" }, "name": "overloads" }, "typeParameters": null, "right": { "type": "IntersectionTypeAnnotation", - "start": 67, + "start": 65, "end": 118, "loc": { "start": { "line": 7, - "column": 4 + "column": 2 }, "end": { "line": 8, @@ -308,7 +316,8 @@ "end": { "line": 7, "column": 7 - } + }, + "identifierName": "x" }, "name": "x" }, @@ -389,7 +398,8 @@ "end": { "line": 8, "column": 7 - } + }, + "identifierName": "x" }, "name": "x" }, @@ -431,6 +441,516 @@ } ] } + }, + { + "type": "TypeAlias", + "start": 122, + "end": 181, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 127, + "end": 133, + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 11 + }, + "identifierName": "union2" + }, + "name": "union2" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 136, + "end": 180, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 15, + "column": 1 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 140, + "end": 178, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "key": { + "type": "Identifier", + "start": 140, + "end": 141, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "UnionTypeAnnotation", + "start": 147, + "end": 178, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "types": [ + { + "type": "ObjectTypeAnnotation", + "start": 149, + "end": 160, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 150, + "end": 159, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "key": { + "type": "Identifier", + "start": 150, + "end": 154, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 11 + }, + "identifierName": "type" + }, + "name": "type" + }, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 156, + "end": 159, + "loc": { + "start": { + "line": 13, + "column": 13 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "value": "A", + "extra": { + "rawValue": "A", + "raw": "\"A\"" + } + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + }, + { + "type": "ObjectTypeAnnotation", + "start": 167, + "end": 178, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 168, + "end": 177, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 16 + } + }, + "key": { + "type": "Identifier", + "start": 168, + "end": 172, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 11 + }, + "identifierName": "type" + }, + "name": "type" + }, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 174, + "end": 177, + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 16 + } + }, + "value": "B", + "extra": { + "rawValue": "B", + "raw": "\"B\"" + } + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + } + ] + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + } + }, + { + "type": "TypeAlias", + "start": 183, + "end": 246, + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 21, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 188, + "end": 198, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 15 + }, + "identifierName": "overloads2" + }, + "name": "overloads2" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 201, + "end": 245, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 21, + "column": 1 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 205, + "end": 243, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 20, + "column": 17 + } + }, + "key": { + "type": "Identifier", + "start": 205, + "end": 206, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "IntersectionTypeAnnotation", + "start": 212, + "end": 243, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 20, + "column": 17 + } + }, + "types": [ + { + "type": "ObjectTypeAnnotation", + "start": 214, + "end": 225, + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 17 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 215, + "end": 224, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 16 + } + }, + "key": { + "type": "Identifier", + "start": 215, + "end": 219, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + }, + "identifierName": "type" + }, + "name": "type" + }, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 221, + "end": 224, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 16 + } + }, + "value": "A", + "extra": { + "rawValue": "A", + "raw": "\"A\"" + } + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + }, + { + "type": "ObjectTypeAnnotation", + "start": 232, + "end": 243, + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 17 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 233, + "end": 242, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 16 + } + }, + "key": { + "type": "Identifier", + "start": 233, + "end": 237, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 11 + }, + "identifierName": "type" + }, + "name": "type" + }, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 239, + "end": 242, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 16 + } + }, + "value": "B", + "extra": { + "rawValue": "B", + "raw": "\"B\"" + } + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + } + ] + }, + "optional": false, + "static": false, + "variance": null + } + ], + "indexers": [], + "exact": false + } } ], "directives": [] diff --git a/test/fixtures/flow/type-alias/5/5.js b/test/fixtures/flow/type-alias/5/5.js new file mode 100644 index 0000000000..cd10f50013 --- /dev/null +++ b/test/fixtures/flow/type-alias/5/5.js @@ -0,0 +1,9 @@ +type A = Foo< + | {type: "A"} + | {type: "B"} +>; + +type B = Foo< + & {type: "A"} + & {type: "B"} +>; diff --git a/test/fixtures/flow/type-alias/5/expected.json b/test/fixtures/flow/type-alias/5/expected.json new file mode 100644 index 0000000000..016fc254c0 --- /dev/null +++ b/test/fixtures/flow/type-alias/5/expected.json @@ -0,0 +1,33 @@ +{ + "type": "File", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "sourceType": "module", + "body": [], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/129/actual.js b/test/fixtures/flow/type-annotations/129/actual.js new file mode 100644 index 0000000000..2a4e53e1ad --- /dev/null +++ b/test/fixtures/flow/type-annotations/129/actual.js @@ -0,0 +1,4 @@ +var x: + | 1 + | 2 += 2; diff --git a/test/fixtures/flow/type-annotations/129/expected.json b/test/fixtures/flow/type-annotations/129/expected.json new file mode 100644 index 0000000000..e55c90e118 --- /dev/null +++ b/test/fixtures/flow/type-annotations/129/expected.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "typeAnnotation": { + "type": "UnionTypeAnnotation", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "types": [ + { + "type": "NumericLiteralTypeAnnotation", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": 1, + "extra": { + "rawValue": 1, + "raw": "1" + } + }, + { + "type": "NumericLiteralTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": 2, + "extra": { + "rawValue": 2, + "raw": "2" + } + } + ] + } + } + }, + "init": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/130/actual.js b/test/fixtures/flow/type-annotations/130/actual.js new file mode 100644 index 0000000000..c196ae8699 --- /dev/null +++ b/test/fixtures/flow/type-annotations/130/actual.js @@ -0,0 +1 @@ +function x(a: | 1 | 2, b: & 3 & 4): number {} diff --git a/test/fixtures/flow/type-annotations/130/expected.json b/test/fixtures/flow/type-annotations/130/expected.json new file mode 100644 index 0000000000..2a823858a4 --- /dev/null +++ b/test/fixtures/flow/type-annotations/130/expected.json @@ -0,0 +1,296 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "sourceType": "module", + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 12, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "typeAnnotation": { + "type": "UnionTypeAnnotation", + "start": 14, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "types": [ + { + "type": "NumericLiteralTypeAnnotation", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "value": 1, + "extra": { + "rawValue": 1, + "raw": "1" + } + }, + { + "type": "NumericLiteralTypeAnnotation", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "value": 2, + "extra": { + "rawValue": 2, + "raw": "2" + } + } + ] + } + } + }, + { + "type": "Identifier", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 33 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 24, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "typeAnnotation": { + "type": "IntersectionTypeAnnotation", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "types": [ + { + "type": "NumericLiteralTypeAnnotation", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "value": 3, + "extra": { + "rawValue": 3, + "raw": "3" + } + }, + { + "type": "NumericLiteralTypeAnnotation", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": 4, + "extra": { + "rawValue": 4, + "raw": "4" + } + } + ] + } + } + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 34, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 42 + } + } + } + }, + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/negative-number-literal/expected.json b/test/fixtures/flow/type-annotations/negative-number-literal/expected.json index 52ca7d33a2..e4b1cc8f02 100644 --- a/test/fixtures/flow/type-annotations/negative-number-literal/expected.json +++ b/test/fixtures/flow/type-annotations/negative-number-literal/expected.json @@ -54,19 +54,20 @@ "end": { "line": 5, "column": 20 - } + }, + "identifierName": "DirectionVector" }, "name": "DirectionVector" }, "typeParameters": null, "right": { "type": "UnionTypeAnnotation", - "start": 45, + "start": 43, "end": 59, "loc": { "start": { "line": 6, - "column": 4 + "column": 2 }, "end": { "line": 8, @@ -196,7 +197,8 @@ "end": { "line": 11, "column": 21 - } + }, + "identifierName": "x" }, "name": "x", "typeAnnotation": { @@ -240,7 +242,8 @@ "end": { "line": 11, "column": 21 - } + }, + "identifierName": "DirectionVector" }, "name": "DirectionVector" } @@ -263,9 +266,6 @@ }, "operator": "-", "prefix": true, - "extra": { - "parenthesizedArgument": false - }, "argument": { "type": "NumericLiteral", "start": 88, @@ -285,6 +285,9 @@ "raw": "1" }, "value": 1 + }, + "extra": { + "parenthesizedArgument": false } } } @@ -345,7 +348,8 @@ "end": { "line": 12, "column": 7 - } + }, + "identifierName": "console" }, "name": "console" }, @@ -361,7 +365,8 @@ "end": { "line": 12, "column": 11 - } + }, + "identifierName": "log" }, "name": "log" },