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

Cannot remove unused variables declared by object destructuring with default value #9460

Open
wjw99830 opened this issue Aug 20, 2024 · 0 comments · Fixed by #9478
Open

Cannot remove unused variables declared by object destructuring with default value #9460

wjw99830 opened this issue Aug 20, 2024 · 0 comments · Fixed by #9478
Labels

Comments

@wjw99830
Copy link

Describe the bug

Cannot remove unused variables declared by object destructuring with default value.

However, it works without default value or declared by member accessing with nullish coalescing.

Input code

const { a, b = 'b' } = {};
const c = {}.c ?? 'c';

Config

{
  "minify": true,
  "jsc": {
    "target": "esnext",
    "minify": {
      "compress": {
        "module": true,
        "pure_getters": true
      },
      "mangle": false
    }
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.14&code=H4sIAAAAAAAAA0vOzysuUahWSNRRSFKwVVBPUleoBdLVtdZcyWCpZDBPL1nB3l5BPVndmgsAb%2BdTbTIAAAA%3D&config=H4sIAAAAAAAAA32VwXLjIAyG732KjM89dHrYQx9gb30GhoBwyBrwSCJNppN3X5nYadLIuXhsffwSSEL%2Bftlsuj257mPzLa%2FyMVokwOu3WOiU2R7F0oFLlhzGkbvXhe5pQsEOBM10vpCOLfbATUXvb%2B9vs6IbSiFYFLMtxRzD6TamK2lEILqxiVVc1gSZ6V4%2FMyxfE2Cst%2FZtKQPY%2FIQYSyZmhh5Qc%2BzKMNiRwBwsKl6mnVqMVLQQE6wM3oxYRpVnHzmWLDEfqQfrjSseFBQRHMcDaDKJJbJMcjzlPA172Na%2Bb3X%2BpYaDHaplJSYcW0lkt4rXXYnEJtSspfACV3JwgXNyfytjMAhcMT%2Fq9iXmlZr8A5AMDJYo2wSa37YiSD%2BtqcNTZcxBWpZPCpf%2B1k6ZoZekmhiDktkpM4ActWoi%2BOpgyqzTtjPjlfRR9GAgBOkVxTV9RXY7LSifRihBAVJfG7SuugBzvYUrfLoQT%2FBfOSXrDTavSJZ365ROaVuGJwES8K74JwukFFzWMcqUOI7rvGYP0hrg1SWVGngcAnIBuJihzcuH3pDrIR5NP5StOibGikKBGa53YYbn65RONvc%2F0%2BB%2BUKPMwFAw3c5fBOv4fvhizRzT5KOzlYsUIrpuCfSyPJvXLhVfW7j5pzL10%2BVX8Kf7WbRM%2FWuiukifi7Id4%2FwfhUyNrqAGAAA%3D

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000
    CPU: (10 cores)
        Models: Apple M1 Pro

Binaries:
    Node: 18.20.4
    npm: 10.7.0
    Yarn: 1.22.22
    pnpm: 7.33.7

Relevant Packages:
    @swc/core: 1.7.14
    @swc/helpers: 0.5.1
    @swc/types: N/A
    typescript: 5.4.5

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

All code should be removed.

Actual behavior

b isn't removed.

Output code

const { b = 'b' } = {};

Version

1.7.14

Additional context

No response

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