Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts]Fix syntax error for modifier name class methods with type parameters #12356

Merged
merged 4 commits into from Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -159,13 +159,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// TODO: Would be nice to avoid lookahead. Want a hasLineBreakUpNext() method...
this.next();
return (
!this.hasPrecedingLineBreak() &&
!this.match(tt.parenL) &&
!this.match(tt.parenR) &&
!this.match(tt.colon) &&
!this.match(tt.eq) &&
!this.match(tt.question) &&
!this.match(tt.bang)
this.match(tt.bracketL) ||
this.match(tt.braceL) ||
this.match(tt.star) ||
this.match(tt.ellipsis) ||
this.match(tt.hash) ||
this.isLiteralPropertyName()
);
}

Expand Down
@@ -0,0 +1,9 @@
class C {
private *a() {}
public *b() {}
static *c() {}
abstract *d() {}
readonly *e() {}
declare *f() {}
protected *g() {}
}
@@ -0,0 +1,189 @@
{
"type": "File",
"start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}},
"program": {
"type": "Program",
"start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"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":139,"loc":{"start":{"line":1,"column":8},"end":{"line":9,"column":1}},
"body": [
{
"type": "ClassMethod",
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
"accessibility": "private",
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":21,"end":22,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12},"identifierName":"a"},
"name": "a"
},
"computed": false,
"id": null,
"generator": true,
"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":44,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":16}},
"accessibility": "public",
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":38,"end":39,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11},"identifierName":"b"},
"name": "b"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":42,"end":44,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":16}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":47,"end":61,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":16}},
"static": true,
"kind": "method",
"key": {
"type": "Identifier",
"start":55,"end":56,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":11},"identifierName":"c"},
"name": "c"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":59,"end":61,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":16}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":64,"end":80,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":18}},
"abstract": true,
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":74,"end":75,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":13},"identifierName":"d"},
"name": "d"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":78,"end":80,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":18}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":83,"end":99,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":18}},
"readonly": true,
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":93,"end":94,"loc":{"start":{"line":6,"column":12},"end":{"line":6,"column":13},"identifierName":"e"},
"name": "e"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":97,"end":99,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":18}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":102,"end":117,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":17}},
"declare": true,
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":111,"end":112,"loc":{"start":{"line":7,"column":11},"end":{"line":7,"column":12},"identifierName":"f"},
"name": "f"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":115,"end":117,"loc":{"start":{"line":7,"column":15},"end":{"line":7,"column":17}},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start":120,"end":137,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":19}},
"accessibility": "protected",
"static": false,
"kind": "method",
"key": {
"type": "Identifier",
"start":131,"end":132,"loc":{"start":{"line":8,"column":13},"end":{"line":8,"column":14},"identifierName":"g"},
"name": "g"
},
"computed": false,
"id": null,
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":135,"end":137,"loc":{"start":{"line":8,"column":17},"end":{"line":8,"column":19}},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1,9 @@
class C {
declare<T>() {}
readonly<T>() {}
abstract<T>() {}
Copy link
Contributor

@JLHwung JLHwung Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add test cases for private, public and protected?

static<T>() {}
private<T>() {}
public<T>() {}
protected<T>() {}
}