Skip to content

Fix optional call losing the receiver through a TS instantiation expression - #18477

Merged
nicolo-ribaudo merged 1 commit into
babel:mainfrom
Kjubikstronk:optional-call-ts-instantiation
Oct 31, 2026
Merged

nicolo-ribaudo merged 1 commit into
babel:mainfrom
Kjubikstronk:optional-call-ts-instantiation

Conversation

@Kjubikstronk

Copy link
Copy Markdown
Contributor
Q A
Fixed Issues? Fixes #18356
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

TypeScript has been used:

(obj.method<string>)?.()

The <string> is just a type and it vanished when TypeScript is removed.

Before:

const result = (_ref = receiver.method<string>) === null || _ref === void 0 ? void 0 : _ref();

After:

const result = (_receiver$method = (_receiver = receiver).method<string>) === null || _receiver$method === void 0 ? void 0 : _receiver$method.call(_receiver);

The wrapper has been added to the list (isTransparentExprWrapper) and a test has been added!

@babel-bot

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 5ad909a

@JLHwung JLHwung left a comment

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.

Thanks.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Oct 30, 2026
@nicolo-ribaudo
nicolo-ribaudo added this pull request to the merge queue Oct 31, 2026
Merged via the queue into babel:main with commit e57b6ea Oct 31, 2026
73 of 75 checks passed
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18482.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Optional-call lowering loses the receiver through a TypeScript instantiation expression

4 participants