Repository navigation
Keep the receiver of TS-wrapped super and private member calls - #18576
Merged
Merged
Conversation
Skip transparent expression wrappers (type assertions, non-null assertions, parentheses) between a member and its call, so that `(super.m as any)()`, `super.m!()` and `this.#m!()` are lowered as calls with the correct `this` instead of plain reads. Fixes babel#18347 Assisted-by: Claude Opus 5.5
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63149 |
|
commit: |
nicolo-ribaudo
approved these changes
Nov 11, 2026
nicolo-ribaudo
left a comment
Member
There was a problem hiding this comment.
Thank you, but please read https://github.com/babel/babel/blob/main/AI_POLICY.md and do not post LLM-generated PR descriptions.
Collaborator
|
Backported to 7.x in #18595. |
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.
Skip transparent expression wrappers (type assertions, non-null assertions, parentheses) between a member and its call, so that
(super.m as any)(),super.m!()andthis.#m!()are lowered as calls with the correctthisinstead of plain reads.Fixes #18347
Assisted-by: Claude Opus 5.5
@babel/helper-member-expression-to-functionsnow depends on@babel/helper-skip-transparent-expression-wrappersThe problem
When a
supermethod call or a private method call has a TypeScript wrapper around the member, the method is called without the correctthis:The same happens with
super.m!(),(super.m satisfies Function)()andthis.#m!().The cause
@babel/helper-member-expression-to-functionsdecides whether the member is being called by looking only at its direct parent. In(super.m as any)(), the parent is theTSAsExpression, not theCallExpression. The helper treats the access as a plain read and generates_superPropGet(...)(), losing the receiver.The fix
Before checking if the member is the callee of a
CallExpressionorOptionalCallExpression, the helper now skips the transparent wrappers (as,!,satisfies,<T>, parentheses and Flow's type cast), usingisTransparentExprWrapperfrom@babel/helper-skip-transparent-expression-wrappers. This way,(super.m as any)()generates the same output assuper.m().Since the helper is shared, the fix applies to
super(transform-object-superandtransform-classes) as well as private members (transform-private-methods).Tests
I added
transparent-expr-wrappersfixtures totransform-object-super,transform-classesandtransform-private-methods, following the same pattern as the ones intransform-exponentiation-operator. Theexectests fail without the fix.Out of scope
zloirock pointed out in the issue that writes through wrappers (
this.#x! = 1,super.x! += 1,++this.#x!, destructuring) also break. These go through different code paths in the helper and the fix is bigger, so I'd rather handle them in a separate PR. I also didn't touch the case of an optional chain inside a wrapper ((a?.#b as any)()).