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 1 commit
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
@@ -0,0 +1,4 @@
class Foo {
constructor(private, public, static) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be an error, because private, public and static are reserved words in strict mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

babel-parser doesn't check reserved word for TypeScript?

checkReservedWord(
word: string, // eslint-disable-line no-unused-vars
startLoc: number, // eslint-disable-line no-unused-vars
checkKeywords: boolean, // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-unused-vars
isBinding: boolean,
): void {
// Don't bother checking for TypeScript code.
// Strict mode words may be allowed as in `declare namespace N { const static: number; }`.
// And we have a type checker anyway, so don't bother having the parser do it.
}

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, I didn't remember about that.

}
}
@@ -0,0 +1,67 @@
{
"type": "File",
"start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
"program": {
"type": "Program",
"start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":58,"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":58,"loc":{"start":{"line":1,"column":10},"end":{"line":4,"column":1}},
"body": [
{
"type": "ClassMethod",
"start":14,"end":56,"loc":{"start":{"line":2,"column":2},"end":{"line":3,"column":3}},
"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":33,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":21},"identifierName":"private"},
"name": "private"
},
{
"type": "Identifier",
"start":35,"end":41,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":29},"identifierName":"public"},
"name": "public"
},
{
"type": "Identifier",
"start":43,"end":49,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":37},"identifierName":"static"},
"name": "static"
}
],
"body": {
"type": "BlockStatement",
"start":51,"end":56,"loc":{"start":{"line":2,"column":39},"end":{"line":3,"column":3}},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}
1 change: 0 additions & 1 deletion scripts/parser-tests/typescript/allowlist.txt
Expand Up @@ -399,7 +399,6 @@ sourceMapValidationDecorators.ts
sourceMapValidationStatements.ts
staticIndexer.ts
strictModeReservedWord.ts
strictModeReservedWordInClassDeclaration.ts
superCallFromClassThatHasNoBaseType1.ts
symbolLinkDeclarationEmitModuleNames.ts
symbolMergeValueAndImportedType.ts
Expand Down