Repository navigation
fix(parser): handle module as an identifier after class extends - #18541
Merged
JLHwung merged 2 commits intoNov 16, 2026
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63344 |
|
commit: |
nicolo-ribaudo
approved these changes
Nov 16, 2026
`module {` was always taken as the start of a module expression, so
`class C extends module {}` failed with or without the `moduleBlocks` plugin.
In a class heritage, optionally after `new`, `module {` is now an identifier
followed by the class body. `class A extends module {} {}` is ambiguous with
the plugin enabled, since a block statement can follow the class, and a module
is never a valid superclass anyway. Module expressions are still available
there in parentheses, so the generator now prints those parentheses.
Assisted-by: Claude Opus 5.5
JLHwung
force-pushed
the
fix-parser-class-heritage-module-identifier
branch
from
November 16, 2026 12:51
03ff450 to
0781210
Compare
liuxingbaoyu
approved these changes
Nov 16, 2026
Collaborator
|
Backported to 7.x in #18635. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
class C extends module {}(REPL)In this PR we fix a parser regression introduced in the implementation of module expression (previously module blocks proposal) (#12469): The current implementation interpreted
moduleafter class extends as a module expression and this renders code examples likeclass C extends module {}invalid.The following valid cases are affected as well:
They are all valid JS today, but Babel parser throws on all cases, expecting
moduleBlocksplugin. With themoduleBlocksplugin, the first two cases are still failing and the other 4 cases are parsed as class declarations, different AST than they should have been parsed today: a list of (ClassDeclaration, ExpressionStatement, and BlockStatement).So in this PR we hardened the parser and required that ModuleExpression within class heritage should be parenthesized if they starts from the class heritage, skipping optional
newchains. I have also open an issue to the proposal repo: tc39/proposal-module-expressions#83.