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: invalid function handling in switch statement #8812

Open
hyp3rflow opened this issue Apr 4, 2024 · 2 comments
Open

minifier: invalid function handling in switch statement #8812

hyp3rflow opened this issue Apr 4, 2024 · 2 comments
Labels
Milestone

Comments

@hyp3rflow
Copy link
Sponsor Contributor

Describe the bug

Even if the function in switch statement has some expressions; like console.log("hi"), the minified result remains unchanged.

Input code

const k = (() => {
    switch (1) { 
        case 0: 
            function x() {}
        default:
            x(); 
    } 
})();

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.11&code=H4sIAAAAAAAAA1WMvQqAIBSFd5%2FijLrVati7iClJoYNKgfjuXQuKvu38mhhSxgYFzgXUjMpApMNns4KPAhW30zE6WQzyMzquBJN9DDjpoLY3W6zTZc%2FyV6bO9MwbWBOk2AWJvP1RggAAAA%3D%3D&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

maybe

let k = void 0;

Actual behavior

let k = void (void 0)();

which results in calling undefined ((void 0) is not a function)

Version

1.4.11

Additional context

No response

@hyp3rflow hyp3rflow added the C-bug label Apr 4, 2024
@kdy1 kdy1 self-assigned this Apr 4, 2024
@kdy1 kdy1 added this to the Planned milestone Apr 4, 2024
@kdy1 kdy1 removed their assignment Apr 5, 2024
@yazaldefilimone
Copy link

Hello @kdy1, @magic-akari

could you help me send my first pr?

@kdy1
Copy link
Member

kdy1 commented Jun 19, 2024

@yazaldefilimone The code for the optimizer that uses variable data lives at https://github.com/swc-project/swc/tree/1839980185a5771f8e51fe6912438a08f2ed2fc2/crates/swc_ecma_minifier/src/compress/optimize and the code for variable analyzer lives at https://github.com/swc-project/swc/tree/1839980185a5771f8e51fe6912438a08f2ed2fc2/crates/swc_ecma_usage_analyzer/src/analyzer

Both the optimizer and analyzer use the visitor pattern, and you can follow visitor methods to understand the flow.

The visitor visits all fields of each types, and you can see the types at https://rustdoc.swc.rs/swc_ecma_ast/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants