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

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Nov 13, 2020

Q                       A
Fixed Issues? Fixes #12353
Patch: Bug Fix? Y
Major: Breaking Change? N
Minor: New Feature? N
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

@sosukesuzuki sosukesuzuki added area: typescript pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Nov 13, 2020
@babel-bot
Copy link
Collaborator

babel-bot commented Nov 13, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/32858/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 13, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 92f8321:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could align to TS implementation here:

https://github.com/microsoft/TypeScript/blob/4885dec80d184ef1570ac97739679ca66af7181d/src/compiler/parser.ts#L1796

An allowlist instead of denylist is better to reason about and avoid any surprise cases that we did not rule out.

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?

@@ -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.

@nicolo-ribaudo
Copy link
Member

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 94d1160 into babel:main Nov 18, 2020
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 18, 2020

(I reworded the commit title a bit otherwise it was too long when adding (#12356))

@sosukesuzuki sosukesuzuki deleted the fix-12353 branch November 18, 2020 14:29
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 18, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Class function cannot be named 'declare' and be generic
4 participants