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

swc_ecma_minifier bad case #8651

Closed
xc2 opened this issue Feb 20, 2024 · 1 comment · Fixed by #8652
Closed

swc_ecma_minifier bad case #8651

xc2 opened this issue Feb 20, 2024 · 1 comment · Fixed by #8652
Assignees
Labels
Milestone

Comments

@xc2
Copy link
Contributor

xc2 commented Feb 20, 2024

Describe the bug

swc_ecma_minifier produces bad code when optimizing lottie-web with default config.

i've tested with the example "compress" and found that seems a69f172 introduced the issue.

Input code

https://github.com/airbnb/lottie-web/blob/63a39aeb27b8c13726ce9fcf850d9351b14be3e6/build/player/lottie.js#L10380-L10392

// input.js
// cargo run -p swc_ecma_minifier --example compress input.js

function renderShape () {
    var i;
    var len = this.animatedContents.length;
    var animatedContent;

    for (i = 0; i < len; i += 1) {
        animatedContent = this.animatedContents[i];

        if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) {
          animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
        }
    }
}

renderShape();

Config

{}

Playground link (or link to the minimal reproduction)

https://github.com/swc-project/swc/blob/main/crates/swc_ecma_minifier/examples/compress.rs

SWC Info output

No response

Expected behavior

3b845c3

function renderShape() {
    var i, animatedContent, len = this.animatedContents.length;
    for(i = 0; i < len; i += 1)animatedContent = this.animatedContents[i], (this._isFirstFrame || animatedContent.element._isAnimated) && !0 !== animatedContent.data && animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
}
renderShape();

Actual behavior

a69f172

function renderShape() {
    var i, animatedContent, len = this.animatedContents.length;
    for(i = 0; i < len; i += 1)(this._isFirstFrame || (animatedContent = this.animatedContents[i]).element._isAnimated) && !0 !== animatedContent.data && animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame);
}
renderShape();

Version

0.189.84

Additional context

related: web-infra-dev/rspack#5656

@xc2 xc2 added the C-bug label Feb 20, 2024
@magic-akari magic-akari self-assigned this Feb 20, 2024
@kdy1 kdy1 added this to the Planned milestone Feb 21, 2024
kdy1 pushed a commit that referenced this issue Feb 21, 2024
**Related issue:**

- Closes #8651 

The core logic of SWC is correct, but there are incorrect code examples in our code repository.
@kdy1 kdy1 modified the milestones: Planned, v1.4.3 Mar 5, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 4, 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 Apr 4, 2024
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.

4 participants