declare const handled like const during analysis in Turbopack #72576
Labels
bug
Issue was opened via the bug report template.
linear: turbopack
Confirmed issue that is tracked by the Turbopack team.
locked
Turbopack
Related to Turbopack with Next.js.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/eager-stonebraker-x42f67
To Reproduce
Reproduction requires #71802 to have landed first.
next dev --turbo
/
my value
instead ofnot set
Current vs. Expected behavior
Currently it shows
not set
whendeclare const MY_MAGIC_VARIABLE: string
is in the file. Removing it shows the correctmy value
.This code does not work with our
define
handling but works with webpack. When I remove thedeclare const
it works. Looking at the AST output of SWC it seems declare const is aVariableDeclaration
but has a propertydeclare: true
which it doesn't have for normalconst
assignment. Looking at the analyzer code we don't takedeclare: true
into account so it's likely skipping replacement fordefine
because we detect aVariableDeclaration
already in scope so it doesn't replace.AST snippet:
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Available memory (MB): 4102 Available CPU cores: 2 Binaries: Node: 20.9.0 npm: 9.8.1 Yarn: 1.22.19 pnpm: 8.10.2 Relevant Packages: next: 15.0.4-canary.5 // Latest available version is detected (15.0.4-canary.5). eslint-config-next: N/A react: 19.0.0-rc-5c56b873-20241107 react-dom: 19.0.0-rc-5c56b873-20241107 typescript: 5.3.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: