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

minifier: self-referential var declaration makes inlining invalid #8841

Closed
hyp3rflow opened this issue Apr 11, 2024 · 1 comment · Fixed by #8887
Closed

minifier: self-referential var declaration makes inlining invalid #8841

hyp3rflow opened this issue Apr 11, 2024 · 1 comment · Fixed by #8887
Assignees
Labels
Milestone

Comments

@hyp3rflow
Copy link
Contributor

Describe the bug

When var declaration has itself as a rhs expression, minifier inlines rhs expression without handling possible ReferenceError.

Input code

const k = (() => {
    var x = x;
    return x;
})();

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.13&code=H4sIAAAAAAAAA0vOzysuUchWsFXQ0NBUsLVTqOZSAIKyxCKFCqBghTWYW5RaUlqUB%2BLVampoWnMBAHUc1Rk2AAAA&config=H4sIAAAAAAAAA32UO3LjMAyG%2B5zCozrFjostcoDtcgYOLYIyvSShIUDHmozvvtDDj40hdRI%2B%2FAAJgPh%2B2%2B2aE7XNx%2B5bPuWnt4Wg3P%2FFQkNmexFLA22y1JbQc%2FN%2BoycakbeRYDJdZ9KwLR3wpKL9r%2F1%2BUTQRkeCmWGwp5OCH55wtpr4A0ZNNrBKyJshM%2F%2BsXVvBrBFzqs%2F2AGMHmDWIsmZAZOiha4BZjtD2BOduiRBlPaksg1FKMsDI40xfsVZ5d4IBZcr5SB9aZFh0oKBRoOZxBk0kukWWS6yn3mbCDQ%2B26qc8%2F1HC2sVpWcsJlaomcVol6xEBsfM1aCWe4UoMZLsX9qQzeFOBa8qvuhCGv9OQvgFQgWqJsE2hxJw8v87Sm9pvKkL2MLA8Kl%2FnWbpmhk6KaELxS2bEyUDho3SzgagtjZVvtOAteKR8FBwa8l1lRQtNX4PaoJeWhB%2FQKkP5ar03VDMz9Fa7w8UFs4D9yS9YHbPFIlo%2FrlIZ0wLiRIAEf0W04SCsY13GRLXHp13nNDmQ0wKkulSbwugTkATCaOO3Ll9mQ5yERTRfx8FgTi8P1voeTzd3jvc%2Br%2BG1xaBK6OsFlyY%2F9nVfz7%2BbhdNvC94M3gT5vyjns9R%2F7ntJqMQYAAA%3D%3D

SWC Info output

No response

Expected behavior

let k = void 0;

Actual behavior

let k = x;

The result occurs ReferenceError due to a dangling usage of x.

Version

1.4.13

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Apr 11, 2024
@kdy1 kdy1 self-assigned this Apr 11, 2024
kdy1 pushed a commit that referenced this issue Apr 23, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.5.1, v1.5.0 Apr 27, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented May 27, 2024

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 May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 participants