Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC transpiles optional chaining even tho it shouldn't #1922

Closed
danieltroger opened this issue Jul 15, 2021 · 5 comments
Closed

SWC transpiles optional chaining even tho it shouldn't #1922

danieltroger opened this issue Jul 15, 2021 · 5 comments
Labels
Milestone

Comments

@danieltroger
Copy link

Describe the bug

Possible regression of #1704 ?
SWC transpiles optional chaining for node, even when setting target to latest node which supports optional chaining.

Input code

globalThis?.hello?.world?.("sup?");

Current output code:

var ref, ref1;
globalThis === null || globalThis === void 0 ? void 0 : (ref = globalThis.hello) === null || ref === void 0 ? void 0 : (ref1 = ref.world) === null || ref1 === void 0 ? void 0 : ref1.call(ref, "sup?");

Config

{
  "env": {
    "shippedProposals": true
  }
}
"browserslist": "node >=16.4.2",

Expected behavior

globalThis?.hello?.world?.("sup?");

Version
The version of @swc/core:

@swc/cli: 0.1.46
@swc/core: 1.2.64

Additional context
Idk but it feels like not transpiling it might be faster at runtime

Repro .zip:
swc-optional-chaining.zip

@kdy1 kdy1 modified the milestones: v1.2.65, v1.2.66, v1.2.67 Jul 16, 2021
@kdy1 kdy1 modified the milestones: v1.2.67, v1.2.68, v1.2.72, v1.2.73, v1.2.74, v1.2.75 Jul 31, 2021
@kdy1 kdy1 modified the milestones: v1.2.75, v1.2.76, v1.2.77 Aug 8, 2021
@kdy1
Copy link
Member

kdy1 commented Aug 9, 2021

It's caused by https://github.com/babel/babel/blob/main/packages/babel-compat-data/data/plugins.json not containing proper node version of proposal-optional-chaining.
I'm not sure where should I get the compat data.

kdy1 added a commit to kdy1/swc that referenced this issue Aug 9, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 9, 2021
@kdy1 kdy1 modified the milestones: v1.2.76, v1.2.77, v1.2.78, v1.2.79 Aug 9, 2021
@kdy1 kdy1 modified the milestones: v1.2.110, v1.2.111, v1.2.112, v1.2.113 Nov 17, 2021
@kdy1 kdy1 modified the milestones: v1.2.118, v1.2.119 Dec 5, 2021
@Austaras
Copy link
Member

Austaras commented Dec 8, 2021

It does now

@kdy1
Copy link
Member

kdy1 commented Dec 20, 2021

Closing as fixed by #3072

@kdy1 kdy1 closed this as completed Dec 20, 2021
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants