From 794d72343dc2347af9b8c888382dc1df3314ce0c Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 23 Oct 2019 21:42:24 -0500 Subject: [PATCH] Fix some incorrect typeof parsing in flow --- packages/babel-parser/src/plugins/flow.js | 56 +- .../input.js | 1 + .../output.json | 155 ++ .../output.json | 2 +- .../flow/type-annotations/132/output.json | 2 +- .../flow/type-annotations/133/output.json | 2 +- .../typeof-reserved-invalid-1/input.js | 2 + .../typeof-reserved-invalid-1/options.json | 8 + .../typeof-reserved-invalid-2/input.js | 2 + .../typeof-reserved-invalid-2/output.json | 239 +++ .../typeof-reserved-invalid-3/input.js | 2 + .../typeof-reserved-invalid-3/output.json | 239 +++ .../typeof-reserved-invalid-4/input.js | 2 + .../typeof-reserved-invalid-4/output.json | 207 +++ .../typeof-reserved-invalid-5/input.js | 2 + .../typeof-reserved-invalid-5/options.json | 8 + .../typeof-reserved-invalid-6/input.js | 2 + .../typeof-reserved-invalid-6/output.json | 239 +++ .../typeof-reserved-valid/input.js | 15 + .../typeof-reserved-valid/output.json | 1620 +++++++++++++++++ .../options.json | 4 - .../output.json | 2 +- 22 files changed, 2787 insertions(+), 24 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/output.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/options.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/output.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/output.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/output.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/options.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/output.json create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/input.js create mode 100644 packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/output.json delete mode 100644 packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index 5e7187455da2..5a3a82743af3 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -22,12 +22,15 @@ import { SCOPE_OTHER, } from "../util/scopeflags"; -const reservedTypes = [ +const reservedTypes = new Set([ + "_", "any", "bool", "boolean", "empty", + "extends", "false", + "interface", "mixed", "null", "number", @@ -36,10 +39,7 @@ const reservedTypes = [ "true", "typeof", "void", - "interface", - "extends", - "_", -]; +]); function isEsModuleType(bodyElement: N.Node): boolean { return ( @@ -483,7 +483,10 @@ export default (superClass: Class): Class => node: N.FlowDeclare, isClass?: boolean = false, ): void { - node.id = this.flowParseRestrictedIdentifier(/*liberal*/ !isClass); + node.id = this.flowParseRestrictedIdentifier( + /* liberal */ !isClass, + /* declaration */ true, + ); this.scope.declareName( node.id.name, @@ -557,21 +560,32 @@ export default (superClass: Class): Class => } } - checkReservedType(word: string, startLoc: number) { - if (reservedTypes.indexOf(word) > -1) { + checkReservedType(word: string, startLoc: number, declaration?: boolean) { + if (!reservedTypes.has(word)) return; + + if (declaration) { this.raise(startLoc, `Cannot overwrite reserved type ${word}`); + return; } + + this.raise(startLoc, `Unexpected reserved type ${word}`); } - flowParseRestrictedIdentifier(liberal?: boolean): N.Identifier { - this.checkReservedType(this.state.value, this.state.start); + flowParseRestrictedIdentifier( + liberal?: boolean, + declaration?: boolean, + ): N.Identifier { + this.checkReservedType(this.state.value, this.state.start, declaration); return this.parseIdentifier(liberal); } // Type aliases flowParseTypeAlias(node: N.FlowTypeAlias): N.FlowTypeAlias { - node.id = this.flowParseRestrictedIdentifier(); + node.id = this.flowParseRestrictedIdentifier( + /* liberal */ false, + /* declaration */ true, + ); this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { @@ -591,7 +605,10 @@ export default (superClass: Class): Class => declare: boolean, ): N.FlowOpaqueType { this.expectContextual("type"); - node.id = this.flowParseRestrictedIdentifier(/*liberal*/ true); + node.id = this.flowParseRestrictedIdentifier( + /* liberal */ true, + /* declaration */ true, + ); this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { @@ -1134,12 +1151,12 @@ export default (superClass: Class): Class => ): N.FlowQualifiedTypeIdentifier { startPos = startPos || this.state.start; startLoc = startLoc || this.state.startLoc; - let node = id || this.parseIdentifier(); + let node = id || this.parseIdentifier(true); while (this.eat(tt.dot)) { const node2 = this.startNodeAt(startPos, startLoc); node2.qualification = node; - node2.id = this.parseIdentifier(); + node2.id = this.flowParseRestrictedIdentifier(true); node = this.finishNode(node2, "QualifiedTypeIdentifier"); } @@ -2352,7 +2369,10 @@ export default (superClass: Class): Class => contextDescription: string, ): void { specifier.local = hasTypeImportKind(node) - ? this.flowParseRestrictedIdentifier(true) + ? this.flowParseRestrictedIdentifier( + /* liberal */ true, + /* declaration */ true, + ) : this.parseIdentifier(); this.checkLVal( @@ -2458,7 +2478,11 @@ export default (superClass: Class): Class => } if (nodeIsTypeImport || specifierIsTypeImport) { - this.checkReservedType(specifier.local.name, specifier.local.start); + this.checkReservedType( + specifier.local.name, + specifier.local.start, + /* declaration */ true, + ); } if (isBinding && !nodeIsTypeImport && !specifierIsTypeImport) { diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/input.js b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/input.js new file mode 100644 index 000000000000..9feacceb06ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/input.js @@ -0,0 +1 @@ +class Foo implements Bar, string {} diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/output.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/output.json new file mode 100644 index 000000000000..7d3d5d229515 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid-2/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "errors": [ + "SyntaxError: Unexpected reserved type string (1:26)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "implements": [ + { + "type": "ClassImplements", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "Bar" + }, + "name": "Bar" + }, + "typeParameters": null + }, + { + "type": "ClassImplements", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "id": { + "type": "Identifier", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "string" + }, + "name": "string" + }, + "typeParameters": null + } + ], + "body": { + "type": "ClassBody", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/output.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/output.json index 1765354398c7..c29716887979 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/output.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: Cannot overwrite reserved type string (1:21)" + "SyntaxError: Unexpected reserved type string (1:21)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/132/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/132/output.json index aa2b8b19ecb0..042dd3afd3b4 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/132/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/132/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: Cannot overwrite reserved type number (1:9)" + "SyntaxError: Unexpected reserved type number (1:9)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/133/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/133/output.json index bb722c84feec..08cb55525e09 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/133/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/133/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: Cannot overwrite reserved type string (1:11)" + "SyntaxError: Unexpected reserved type string (1:11)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/input.js new file mode 100644 index 000000000000..57a78fa5a789 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof interface = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/options.json new file mode 100644 index 000000000000..151f6c5a3cd5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-1/options.json @@ -0,0 +1,8 @@ +{ + "sourceType": "module", + "plugins": [ + "jsx", + "flow" + ], + "throws": "Unexpected token, expected \"{\" (2:26)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/input.js new file mode 100644 index 000000000000..292205253049 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof type.interface = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/output.json new file mode 100644 index 000000000000..58a7471e980c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-2/output.json @@ -0,0 +1,239 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "errors": [ + "SyntaxError: Unexpected reserved type interface (2:21)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 15, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 30 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 18, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "typeParameters": null, + "id": { + "type": "QualifiedTypeIdentifier", + "start": 25, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "qualification": { + "type": "Identifier", + "start": 25, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "type" + }, + "name": "type" + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 30 + }, + "identifierName": "interface" + }, + "name": "interface" + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 42, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/input.js new file mode 100644 index 000000000000..018cfae79c6b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof stuff.number = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/output.json new file mode 100644 index 000000000000..8b8eb4bb5a32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-3/output.json @@ -0,0 +1,239 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "errors": [ + "SyntaxError: Unexpected reserved type number (2:22)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 15, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 28 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 18, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "typeParameters": null, + "id": { + "type": "QualifiedTypeIdentifier", + "start": 25, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "qualification": { + "type": "Identifier", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 21 + }, + "identifierName": "stuff" + }, + "name": "stuff" + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 28 + }, + "identifierName": "number" + }, + "name": "number" + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 40, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/input.js new file mode 100644 index 000000000000..01212f07ac93 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof static = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/output.json new file mode 100644 index 000000000000..9236c950f3be --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-4/output.json @@ -0,0 +1,207 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "errors": [ + "SyntaxError: Unexpected reserved word 'static' (2:16)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 15, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 18, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 25, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "static" + }, + "name": "static" + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 34, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/input.js new file mode 100644 index 000000000000..8c14711e1d8e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof typeof = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/options.json new file mode 100644 index 000000000000..749dcb796d32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-5/options.json @@ -0,0 +1,8 @@ +{ + "sourceType": "module", + "plugins": [ + "jsx", + "flow" + ], + "throws": "Unexpected token (2:23)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/input.js new file mode 100644 index 000000000000..1c47c611a6d7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/input.js @@ -0,0 +1,2 @@ +// @flow +const x: typeof d.i\u{6e}terface = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/output.json new file mode 100644 index 000000000000..25467cae1b2d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-invalid-6/output.json @@ -0,0 +1,239 @@ +{ + "type": "File", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "errors": [ + "SyntaxError: Unexpected reserved type interface (2:18)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 15, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 18, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "typeParameters": null, + "id": { + "type": "QualifiedTypeIdentifier", + "start": 25, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "qualification": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "d" + }, + "name": "d" + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "interface" + }, + "name": "interface" + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 44, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/input.js new file mode 100644 index 000000000000..f96ff8f65234 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/input.js @@ -0,0 +1,15 @@ +// @flow +const a: typeof default = "hi"; +const b: typeof stuff.default = "hi"; + +const c: typeof any = "hi"; +const d: typeof bool = "hi"; +const e: typeof boolean = "hi"; +const f: typeof empty = "hi"; +const g: typeof false = "hi"; +const h: typeof mixed = "hi"; +const i: typeof null = "hi"; +const j: typeof number = "hi"; +const k: typeof string = "hi"; +const l: typeof true = "hi"; +const m: typeof void = "hi"; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/output.json new file mode 100644 index 000000000000..5ef43efe2bd1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/typeof-reserved-valid/output.json @@ -0,0 +1,1620 @@ +{ + "type": "File", + "start": 0, + "end": 407, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 407, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 9, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 15, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "argument": { + "type": "Identifier", + "start": 25, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "default" + }, + "name": "default" + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + }, + { + "type": "VariableDeclaration", + "start": 41, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 47, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "id": { + "type": "Identifier", + "start": 47, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 29 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 48, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 50, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 57, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "typeParameters": null, + "id": { + "type": "QualifiedTypeIdentifier", + "start": 57, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "qualification": { + "type": "Identifier", + "start": 57, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 21 + }, + "identifierName": "stuff" + }, + "name": "stuff" + }, + "id": { + "type": "Identifier", + "start": 63, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 29 + }, + "identifierName": "default" + }, + "name": "default" + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 73, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 80, + "end": 107, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 27 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 86, + "end": 106, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 86, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 19 + }, + "identifierName": "c" + }, + "name": "c", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 87, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 89, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "argument": { + "type": "AnyTypeAnnotation", + "start": 96, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 102, + "end": 106, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 108, + "end": 136, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 114, + "end": 135, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 114, + "end": 128, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 20 + }, + "identifierName": "d" + }, + "name": "d", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 115, + "end": 128, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 117, + "end": 128, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "argument": { + "type": "BooleanTypeAnnotation", + "start": 124, + "end": 128, + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 131, + "end": 135, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 137, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 143, + "end": 167, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 143, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 23 + }, + "identifierName": "e" + }, + "name": "e", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 144, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 146, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "argument": { + "type": "BooleanTypeAnnotation", + "start": 153, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 23 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 163, + "end": 167, + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 30 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 169, + "end": 198, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 29 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 175, + "end": 197, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 175, + "end": 190, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 21 + }, + "identifierName": "f" + }, + "name": "f", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 176, + "end": 190, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 21 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 178, + "end": 190, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 21 + } + }, + "argument": { + "type": "EmptyTypeAnnotation", + "start": 185, + "end": 190, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 21 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 193, + "end": 197, + "loc": { + "start": { + "line": 8, + "column": 24 + }, + "end": { + "line": 8, + "column": 28 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 199, + "end": 228, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 205, + "end": 227, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 205, + "end": 220, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 21 + }, + "identifierName": "g" + }, + "name": "g", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 206, + "end": 220, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 21 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 208, + "end": 220, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 21 + } + }, + "argument": { + "type": "BooleanLiteralTypeAnnotation", + "start": 215, + "end": 220, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 21 + } + }, + "value": false + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 223, + "end": 227, + "loc": { + "start": { + "line": 9, + "column": 24 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 229, + "end": 258, + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 29 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 235, + "end": 257, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 235, + "end": 250, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 21 + }, + "identifierName": "h" + }, + "name": "h", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 236, + "end": 250, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 21 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 238, + "end": 250, + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 21 + } + }, + "argument": { + "type": "MixedTypeAnnotation", + "start": 245, + "end": 250, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 21 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 253, + "end": 257, + "loc": { + "start": { + "line": 10, + "column": 24 + }, + "end": { + "line": 10, + "column": 28 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 259, + "end": 287, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 265, + "end": 286, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 265, + "end": 279, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 20 + }, + "identifierName": "i" + }, + "name": "i", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 266, + "end": 279, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 268, + "end": 279, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "argument": { + "type": "NullLiteralTypeAnnotation", + "start": 275, + "end": 279, + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 11, + "column": 20 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 282, + "end": 286, + "loc": { + "start": { + "line": 11, + "column": 23 + }, + "end": { + "line": 11, + "column": 27 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 288, + "end": 318, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 30 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 294, + "end": 317, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 294, + "end": 310, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 22 + }, + "identifierName": "j" + }, + "name": "j", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 295, + "end": 310, + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 297, + "end": 310, + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "argument": { + "type": "NumberTypeAnnotation", + "start": 304, + "end": 310, + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 22 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 313, + "end": 317, + "loc": { + "start": { + "line": 12, + "column": 25 + }, + "end": { + "line": 12, + "column": 29 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 319, + "end": 349, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 325, + "end": 348, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 325, + "end": 341, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 22 + }, + "identifierName": "k" + }, + "name": "k", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 326, + "end": 341, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 328, + "end": 341, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 22 + } + }, + "argument": { + "type": "StringTypeAnnotation", + "start": 335, + "end": 341, + "loc": { + "start": { + "line": 13, + "column": 16 + }, + "end": { + "line": 13, + "column": 22 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 344, + "end": 348, + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 350, + "end": 378, + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 356, + "end": 377, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 356, + "end": 370, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 20 + }, + "identifierName": "l" + }, + "name": "l", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 357, + "end": 370, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 359, + "end": 370, + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "argument": { + "type": "BooleanLiteralTypeAnnotation", + "start": 366, + "end": 370, + "loc": { + "start": { + "line": 14, + "column": 16 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "value": true + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 373, + "end": 377, + "loc": { + "start": { + "line": 14, + "column": 23 + }, + "end": { + "line": 14, + "column": 27 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 379, + "end": 407, + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 385, + "end": 406, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 385, + "end": 399, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 20 + }, + "identifierName": "m" + }, + "name": "m", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 386, + "end": 399, + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TypeofTypeAnnotation", + "start": 388, + "end": 399, + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "argument": { + "type": "VoidTypeAnnotation", + "start": 395, + "end": 399, + "loc": { + "start": { + "line": 15, + "column": 16 + }, + "end": { + "line": 15, + "column": 20 + } + } + } + } + } + }, + "init": { + "type": "StringLiteral", + "start": 402, + "end": 406, + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 27 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + ], + "kind": "const" + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json deleted file mode 100644 index d822c40fbba2..000000000000 --- a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "sourceType": "module", - "plugins": ["jsx", "flow"] -} diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/output.json index e89da7ec21b6..e087eecbd2bb 100644 --- a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/output.json +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: Cannot overwrite reserved type _ (2:13)", + "SyntaxError: Unexpected reserved type _ (2:13)", "SyntaxError: `_` is only allowed as a type argument to call or new (2:19)" ], "program": {