Skip to content

fix(parser): properly handle optional markers in generator class methods#17312

Merged
nicolo-ribaudo merged 4 commits intobabel:mainfrom
magic-akari:fix/issue-17310
May 15, 2025
Merged

fix(parser): properly handle optional markers in generator class methods#17312
nicolo-ribaudo merged 4 commits intobabel:mainfrom
magic-akari:fix/issue-17310

Conversation

@magic-akari
Copy link
Copy Markdown
Contributor

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

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented May 15, 2025

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

Comment on lines +7 to +8
"SyntaxError: Class methods cannot have the 'readonly' modifier. (6:2)",
"SyntaxError: Class methods cannot have the 'declare' modifier. (7:2)"
Copy link
Copy Markdown
Contributor Author

@magic-akari magic-akari May 15, 2025

Choose a reason for hiding this comment

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

TS1024: 'readonly' modifier can only appear on a property declaration or index signature.
TS1031: 'declare' modifier cannot appear on class elements of this kind.

@@ -0,0 +1,9 @@
class A {
*[a?.b]?() { };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we report a recoverable error in cases like this, similarly to how report it for readonly and declare?

Copy link
Copy Markdown
Contributor Author

@magic-akari magic-akari May 15, 2025

Choose a reason for hiding this comment

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

Actually, this is valid TypeScript syntax.

Do you mean readonly *[a?.b]?() { }; ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I meant with just ?, I didn't realize it's actually valid syntax.

readonly *[e?.e]?() { }
declare *[f?.f]?() { }
protected *[g?.g]?() { }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you. Can you split this test into two? one for the valid cases and the other for invalid ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: typescript labels May 15, 2025
@nicolo-ribaudo nicolo-ribaudo merged commit 7667b0d into babel:main May 15, 2025
57 checks passed
@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 Aug 15, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 15, 2025
@magic-akari magic-akari deleted the fix/issue-17310 branch December 28, 2025 16:37
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.

Inconsistent behavior when parsing class optional methods (TS)

5 participants