Skip to content

Conversation

magic-akari
Copy link
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
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
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
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
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
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
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
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
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