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

Empty return inside nested conditionals is optimized incorrectly #2214

Closed
zigazeljko opened this issue Sep 7, 2021 · 1 comment · Fixed by #2183
Closed

Empty return inside nested conditionals is optimized incorrectly #2214

zigazeljko opened this issue Sep 7, 2021 · 1 comment · Fixed by #2183
Labels
Milestone

Comments

@zigazeljko
Copy link

Describe the bug

When using an empty return statement inside nested conditionals, the optimized output is incorrect.

Input code

function f(a, b) {
  if (a) {
    if (b) return;
    foo();
  }
  bar();
}

Config

{
  "jsc": {
    "minify": {
      "compress": true
    }
  }
}

Expected behavior
swc output = input

Current behavior

function f(a, b) {
    a && (b || foo()), bar();
}

Version
The version of @swc/core: 1.2.84

@kdy1 kdy1 added this to the v1.2.85 milestone Sep 7, 2021
@kdy1 kdy1 closed this as completed in #2183 Sep 8, 2021
kdy1 added a commit that referenced this issue Sep 8, 2021
swc_ecma_codegen:
 - Don't panic on `Pat::Invalid`.
 - Fix codegen of unary minus. (#2213)

swc_ecma_minifier:
 - Remove identifier of function expressions if a variable with same name exists.
 - `sequences`: Merge into the argument of a throw statement.
 - Use `ignore_return_value` for `void` expressions.
 - Improve inlining.
 - Drop last `return` if the return value is not used.
 - `sequences`: Merge `c++; use(c)` as `use(++c)`.
 - `sequences`: Merge assignments with an operator.
 - `comparisons`: Optimize the comparison operator if type is equivalent.
 - Fix `negate_cost`.
 - `unused`: Fix order or variable initalizer when variables are dropped.
 - Fix `top_retain` option.
 - `if_return`: Don't merge nested if it's wrong to do so. (#2214)
 - Fix negation of `if_return`.
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 22, 2022

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 Oct 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants