Skip to content

minify: invalid output #2007

@troy351

Description

@troy351

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions