Skip to content

Commit

Permalink
Fix syntax error for modifier name class methods with type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Nov 13, 2020
1 parent 5bbad89 commit 0574a07
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -166,7 +166,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
!this.match(tt.colon) &&
!this.match(tt.eq) &&
!this.match(tt.question) &&
!this.match(tt.bang)
!this.match(tt.bang) &&
!this.match(tt.relational)
);
}

Expand Down
@@ -0,0 +1,5 @@
class C {
declare<T>() {}
readonly<T>() {}
abstract<T>() {}
}
@@ -0,0 +1,128 @@
{
"type": "File",
"start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
"program": {
"type": "Program",
"start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start":8,"end":67,"loc":{"start":{"line":1,"column":8},"end":{"line":5,"column":1}},
"body": [
{
"type": "ClassMethod",
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
"static": false,
"key": {
"type": "Identifier",
"start":12,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9},"identifierName":"declare"},
"name": "declare"
},
"computed": false,
"kind": "method",
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}},
"params": [
{
"type": "TSTypeParameter",
"start":20,"end":21,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}},
"name": "T"
}
]
},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":30,"end":46,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":18}},
"static": false,
"key": {
"type": "Identifier",
"start":30,"end":38,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":10},"identifierName":"readonly"},
"name": "readonly"
},
"computed": false,
"kind": "method",
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start":38,"end":41,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13}},
"params": [
{
"type": "TSTypeParameter",
"start":39,"end":40,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":12}},
"name": "T"
}
]
},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":44,"end":46,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":18}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":49,"end":65,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":18}},
"static": false,
"key": {
"type": "Identifier",
"start":49,"end":57,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":10},"identifierName":"abstract"},
"name": "abstract"
},
"computed": false,
"kind": "method",
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start":57,"end":60,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":13}},
"params": [
{
"type": "TSTypeParameter",
"start":58,"end":59,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":12}},
"name": "T"
}
]
},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":63,"end":65,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":18}},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

0 comments on commit 0574a07

Please sign in to comment.