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

Minifier does not respect toplevel: false #6418

Closed
levmv opened this issue Nov 13, 2022 · 8 comments · Fixed by #6774
Closed

Minifier does not respect toplevel: false #6418

levmv opened this issue Nov 13, 2022 · 8 comments · Fixed by #6774
Assignees
Labels
Milestone

Comments

@levmv
Copy link

levmv commented Nov 13, 2022

Describe the bug

Different behaviour between online playground and real tool. Also, swc mangles top level global variable :(

Input code

var foo = function () { }

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": false
}

Playground link

https://play.swc.rs/?version=1.3.15&code=H4sIAAAAAAAAA1MqLU5VKC4pykwuUbLmKkssUkjLz1ewVUgrzUsuyczPU9DQVKhWqAUAf4u9HCcAAAA%3D&config=H4sIAAAAAAAAA22PSw7CMAxE7%2BJ1F7AAod6BMyArTKpAPlYcEFXVu5NCP0Ji5dG8sTUe6KaG2oGEsyJPSvtY%2BEUtwQRWk50UamqsWpa9YmyocO5QpogeKvMpKWbaUHDR2X66ZFKQDNUNcew8JlSSeDzhV3QH5GI8q0YO0F%2Ff%2FvEkuycX1JlkQw6nVStbzm6%2FW3qPtXlI18fcoBd8PjjSuJVezuh5Dn5X39hJ70MnAQAA

Expected behavior

var foo=function foo(){};

Actual behavior

var n=function n(){};

Version

1.3.15

Additional context

Online playground shows everything right. But when I copy config from playground to .swcrc file and execute cli tool (npx swc 'in.js' --config-file=.swcrc --out-file='out.js') its returns different (and wrong) code.

We have some projects with dependencies like https://github.com/ganlanyuan/tiny-slider/blob/master/dist/min/tiny-slider.js and this behaviour is blocking us from upgrade from babel/terser to swc :(
Now its working correct only with fully disabled mangle

@levmv levmv added the C-bug label Nov 13, 2022
@kdy1 kdy1 added this to the Planned milestone Nov 13, 2022
@kdy1
Copy link
Member

kdy1 commented Nov 13, 2022

Seems like this is an issue of @swc/cli

@kdy1 kdy1 changed the title Bug with global variables and possibly broken playground? Minifier does not respect toplevel: false Nov 13, 2022
@alexander-akait
Copy link
Collaborator

@kdy1 @levmv I think it is fixed by #6455

@kdy1 kdy1 closed this as completed Nov 17, 2022
@levmv
Copy link
Author

levmv commented Nov 17, 2022

@alexander-akait
Great job! Thanks a lot!

@kdy1 kdy1 modified the milestones: Planned, v1.3.19 Nov 20, 2022
@levmv
Copy link
Author

levmv commented Nov 26, 2022

Sorry, didn't test it right away and now see that issue isn't solved by Alexander's PR :(

@kdy1, would you reopen ticket, please?

@kdy1
Copy link
Member

kdy1 commented Nov 27, 2022

No, please file a new one instead

@kdy1
Copy link
Member

kdy1 commented Nov 27, 2022

Oh nevermind

@kdy1 kdy1 reopened this Nov 27, 2022
@kdy1 kdy1 modified the milestones: v1.3.19, Planned Nov 27, 2022
@kdy1 kdy1 self-assigned this Dec 22, 2022
kdy1 added a commit that referenced this issue Jan 10, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.26 Jan 11, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 10, 2023

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 Feb 10, 2023
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