From d2971a1959775d86cbf954bc4b22ee4a6595c6a8 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Wed, 21 Nov 2018 15:58:50 -0800 Subject: [PATCH] Fix compatibility between typescript and jsx plugins in interface declarations (#9058) --- .../babel-parser/src/plugins/typescript.js | 2 +- .../typescript/regression/issue-7742/input.js | 3 + .../regression/issue-7742/options.json | 4 + .../regression/issue-7742/output.json | 278 ++++++++++++++++++ 4 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 packages/babel-parser/test/fixtures/typescript/regression/issue-7742/input.js create mode 100644 packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 8970a6e4cf..95f8e61d02 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -930,7 +930,7 @@ export default (superClass: Class): Class => node.extends = this.tsParseHeritageClause(); } const body: N.TSInterfaceBody = this.startNode(); - body.body = this.tsParseObjectTypeMembers(); + body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this)); node.body = this.finishNode(body, "TSInterfaceBody"); return this.finishNode(node, "TSInterfaceDeclaration"); } diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/input.js b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/input.js new file mode 100644 index 0000000000..f347dca737 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/input.js @@ -0,0 +1,3 @@ +interface Foo { + (bar: G): T; +} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json new file mode 100644 index 0000000000..a0f82d16f0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "plugins": ["typescript", "jsx"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json new file mode 100644 index 0000000000..ad154a88fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json @@ -0,0 +1,278 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "G" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start": 17, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSCallSignatureDeclaration", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "bar" + }, + "name": "bar", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "typeName": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "G" + }, + "name": "G" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "typeName": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "T" + }, + "name": "T" + } + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file