You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64
Binaries:
Node: 16.14.2
npm: 8.5.5
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
PR for failing test based on latest canary: #35735
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I know that next-swc's shakeExports option is not public, but nonetheless I've found what I think is a bug, so I thought I'd report it.
shakeExports avoids shaking variable declarations in top-level scope where they're used within a function in the ignore list.
However, this breaks if the usage is in a JSX tag.
e.g. input:
functionShouldBeKept(){return'should be kept';}letshouldBeKept='should be kept';exportdefaultfunction(){return<ShouldBeKeptval={shouldBeKept}/>;}
Output with shakeExports: { ignore: ['default'] }:
letshouldBeKept="should be kept";exportdefaultfunction(){return<ShouldBeKeptval={shouldBeKept}/>;}
ShouldBeKept function has been erroneously shaken out.
My best guess is that the cause is upstream in SWC. Possibly dce expects to be used after JSX->JS transform, so it's not looking for variables used in JSX. That's just a total guess though.
Background on why I'm interested in shakeExports: #35487
Sorry I didn't explain myself well. I didn't open this issue as a demand that it be fixed!
Regardless if it's a public API or not, I'm aware from the discussion that it's in use internally at Vercel, so I thought a bug report and failing test would be helpful.
It turns out that the bug is indeed upstream in SWC's dce transform, so I've raised an issue there and will submit a fix if my meagre Rust skills allow.
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.
Verify canary release
Provide environment information
PR for failing test based on latest canary: #35735
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I know that next-swc's
shakeExports
option is not public, but nonetheless I've found what I think is a bug, so I thought I'd report it.shakeExports
avoids shaking variable declarations in top-level scope where they're used within a function in theignore
list.However, this breaks if the usage is in a JSX tag.
e.g. input:
Output with
shakeExports: { ignore: ['default'] }
:ShouldBeKept
function has been erroneously shaken out.My best guess is that the cause is upstream in SWC. Possibly
dce
expects to be used after JSX->JS transform, so it's not looking for variables used in JSX. That's just a total guess though.Background on why I'm interested in
shakeExports
: #35487Expected Behavior
Please see above.
To Reproduce
PR for failing test: #35735
The text was updated successfully, but these errors were encountered: