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

minify: invalid output #2007

Closed
troy351 opened this issue Aug 4, 2021 · 1 comment · Fixed by #2006
Closed

minify: invalid output #2007

troy351 opened this issue Aug 4, 2021 · 1 comment · Fixed by #2006
Assignees
Labels
Milestone

Comments

@troy351
Copy link
Contributor

troy351 commented Aug 4, 2021

Describe the bug
using compiler.minify produce invaild output

Input code

const obj = {}
for (let key in obj) {
  obj[key] = obj[key].trim();
}

let arr = ["foo",]
arr.forEach(() => { })
function func() {
  (async () => {
    await this.foo();
    this.bar();
  })()
}

func()

Output code

"use strict";const a={};for(let b in a)a[b]=a[b].trim()["foo",].forEach(()=>{})

NOTE: the trim()["foo",] part

"use strict";function a(){await this.foo(),this.bar()}a()

NOTE: async was gone

Config

{
    compress: true,
    mangle: { topLevel: true },
  }

Expected behavior
A clear and concise description of what you expected to happen.

  • should add leading semicolon for array
  • should remove trailing comma of array
  • should not extract IIFE async

Version
The version of @swc/wasm-web: 1.2.73

Additional context
Add any other context about the problem here.

@troy351 troy351 added the C-bug label Aug 4, 2021
@kdy1 kdy1 self-assigned this Aug 4, 2021
@kdy1 kdy1 added this to the v1.2.74 milestone Aug 4, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 4, 2021
@kdy1 kdy1 closed this as completed in #2006 Aug 4, 2021
kdy1 added a commit that referenced this issue Aug 4, 2021
swc_ecma_codegen:
 - Emit a semicolon before `!`.
 - Emit a semicolon before `[`. (#2007)

swc_ecma_minifier:
 - Disable buggy passes.
 - `iife`: Don't inline async functions. (#2007)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 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 23, 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