Skip to content

Disallow super call after new#17871

Merged
JLHwung merged 8 commits intobabel:mainfrom
JLHwung:disallow-super-call-after-new
Mar 18, 2026
Merged

Disallow super call after new#17871
JLHwung merged 8 commits intobabel:mainfrom
JLHwung:disallow-super-call-after-new

Conversation

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Mar 13, 2026

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

In this PR we forbid super() after new and the binary form function bind operator ::.

We also update the parentheses rule of the new callee in @babel/generator. The new rule ensure optional chain and the the import expression are parenthesized when they are the callee of the new expression.

We also disallow NewExpression.callee being one of Super | Import | V8IntrinsicIdentifier, these productions are never valid and it is merely a side effect of inheriting CallExpression in the types definition.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories pkg: parser Spec: Function Bind Spec: Classes labels Mar 13, 2026
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 13, 2026

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

commit: 5f94063

@@ -0,0 +1 @@
a::import()
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case for a::import.defer()?

@JLHwung JLHwung force-pushed the disallow-super-call-after-new branch from 6428b6c to 047d66b Compare March 17, 2026 19:12
@JLHwung JLHwung merged commit a02d9cd into babel:main Mar 18, 2026
56 checks passed
@JLHwung JLHwung deleted the disallow-super-call-after-new branch March 18, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Classes Spec: Function Bind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@babel/parser should disallow unparenthesized super call after new

4 participants