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

[Bug]: Bad output with two || in an expression #7264

Closed
bostondv opened this issue Jul 22, 2024 · 0 comments · Fixed by #7277
Closed

[Bug]: Bad output with two || in an expression #7264

bostondv opened this issue Jul 22, 2024 · 0 comments · Fixed by #7277
Assignees
Labels
bug Something isn't working

Comments

@bostondv
Copy link
Contributor

bostondv commented Jul 22, 2024

System Info

System:
OS: macOS 14.4
CPU: (12) arm64 Apple M2 Pro
Memory: 81.13 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v18.19.0/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
pnpm: 8.12.1 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
Browsers:
Chrome: 126.0.6478.183
Safari: 17.4
npmPackages:
@rspack/cli: latest => 0.7.5
@rspack/core: latest => 0.7.5

Details

Writing an expression with two or (||) in it produces incorrect bundle output.

Source:

el.innerHTML = 'hello, world' || undefined || undefined

Webpack output (correct):

el.innerHTML = 'hello, world' || 0 || 0

Rspack output (incorrect):

el.innerHTML =  true || 0

Another example:

// Config
new rspack.DefinePlugin({
   'process.env.GIT_COMMIT': JSON.stringify('commit-sha'),
})
// App
const GIT_COMMIT = process.env.GIT_COMMIT || process.env.ISC_SHA || process.env.BUILD_SHA
// Result
const GIT_COMMIT =  true || 0

We noticed this when upgrading from 0.6.2 to 0.7.5.

Reproduce link

https://github.com/bostondv/rspack-repro/tree/or-expr

Reproduce Steps

  1. Run npm run build
  2. Check output
@bostondv bostondv added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jul 22, 2024
@xc2 xc2 removed the pending triage The issue/PR is currently untouched. label Jul 23, 2024
@xc2 xc2 self-assigned this Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants