diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index b5d26fc300..6b3a6809e7 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -79,6 +79,7 @@ export default (superClass: Class): Class => return ( !this.hasPrecedingLineBreak() && !this.match(tt.parenL) && + !this.match(tt.parenR) && !this.match(tt.colon) && !this.match(tt.eq) && !this.match(tt.question) diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/input.js b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/input.js new file mode 100644 index 0000000000..5caeeca38c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/input.js @@ -0,0 +1,4 @@ +class Foo { + constructor(set, readonly) {} + constructor(set: any, readonly: boolean) {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/output.json b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/output.json new file mode 100644 index 0000000000..24aeccd1b0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-modifier-names/output.json @@ -0,0 +1,327 @@ +{ + "type": "File", + "start": 0, + "end": 91, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 91, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 91, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 91, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 14, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "set" + }, + "name": "set" + }, + { + "type": "Identifier", + "start": 31, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "readonly" + }, + "name": "readonly" + } + ], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 46, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 46, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 58, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 22 + }, + "identifierName": "set" + }, + "name": "set", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 61, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TSAnyKeyword", + "start": 63, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 22 + } + } + } + } + }, + { + "type": "Identifier", + "start": 68, + "end": 85, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 41 + }, + "identifierName": "readonly" + }, + "name": "readonly", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 76, + "end": 85, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "typeAnnotation": { + "type": "TSBooleanKeyword", + "start": 78, + "end": 85, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 41 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 87, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file