Skip to content

Commit

Permalink
Fix compatibility between typescript and jsx plugins in interface dec…
Browse files Browse the repository at this point in the history
…larations (#9058)
  • Loading branch information
danez committed Nov 21, 2018
1 parent 4f16a12 commit d2971a1
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/typescript.js
Expand Up @@ -930,7 +930,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
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");
}
Expand Down
@@ -0,0 +1,3 @@
interface Foo<G> {
<T>(bar: G): T;
}
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "jsx"]
}
@@ -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": []
}
}

0 comments on commit d2971a1

Please sign in to comment.