From 9f3457797ff9b90f4cc794c173d626163f9a6046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Ledoux?= Date: Sun, 24 Feb 2019 06:34:38 -0600 Subject: [PATCH] Fix TypeScript parsers missing token check (#9571) (#9572) * Fix TypeScript parsers missing token check (#9571) * fix unit test --- .../babel-parser/src/plugins/typescript.js | 3 +- .../members-with-modifier-names/input.js | 1 + .../members-with-modifier-names/output.json | 82 +++++++++++++++++-- 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 621f756f0a..1c0961ab97 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -86,7 +86,8 @@ export default (superClass: Class): Class => !this.match(tt.parenR) && !this.match(tt.colon) && !this.match(tt.eq) && - !this.match(tt.question) + !this.match(tt.question) && + !this.match(tt.bang) ); } diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/input.js b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/input.js index cbf422a383..97ead10b46 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/input.js +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/input.js @@ -3,4 +3,5 @@ class C { public static(): void; readonly = 0; async(): void; + abstract!:void; } diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json index 47c282e398..bcd481d869 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 98, + "end": 118, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 6, + "line": 7, "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 98, + "end": 118, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 6, + "line": 7, "column": 1 } }, @@ -32,14 +32,14 @@ { "type": "ClassDeclaration", "start": 0, - "end": 98, + "end": 118, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 6, + "line": 7, "column": 1 } }, @@ -64,14 +64,14 @@ "body": { "type": "ClassBody", "start": 8, - "end": 98, + "end": 118, "loc": { "start": { "line": 1, "column": 8 }, "end": { - "line": 6, + "line": 7, "column": 1 } }, @@ -370,6 +370,72 @@ } } } + }, + { + "type": "ClassProperty", + "start": 101, + "end": 116, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 101, + "end": 109, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 12 + }, + "identifierName": "abstract" + }, + "name": "abstract" + }, + "computed": false, + "definite": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 110, + "end": 115, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start": 111, + "end": 115, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 18 + } + } + } + }, + "value": null } ] }