You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The collapse_vars and unused options for compress. (When they both are true, the error happens.)
Input code
functionexample(){varMyEnum=/*#__PURE__*/function(MyEnum){MyEnum["First"]="first";MyEnum["Second"]="second";returnMyEnum;}(MyEnum||{});returnMyEnum}example()// Output Code:(function(){varMyEnum1;return(MyEnum1=MyEnum||{})["First"]="first",MyEnum1["Second"]="second",MyEnum1;// ^^^^^^ This variable is never defined, // which leads to an Uncaught ReferenceError})();
I'd expect this to produce code along these lines:
(function(){varMyEnum;// ^^^^^^ Nice, the variable is defined!varMyEnum1=((MyEnum=MyEnum1||{})["First"]="first",MyEnum["Second"]="second",MyEnum);returnMyEnum1;})();
(Which it does, if I remove the __PURE__ comment or disable either one of the collapse_vars or unused options. (Although the code does of course look slightly different then.))
Actual behavior
No response
Version
1.3.44
Additional context
No response
The text was updated successfully, but these errors were encountered:
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.
Describe the bug
Hello! We're trying to use SWC as an alternative to Terser, but in a specific scenario, it produces invalid code.
The input code below is the result of compiling this TypeScript code, which defines an enum, with Babel:
Babel Playground →
This seems to be due to the combination of
__PURE__
magic commentcollapse_vars
andunused
options forcompress
. (When they both aretrue
, the error happens.)Input code
Config
Playground link
https://play.swc.rs/?version=1.3.44&code=H4sIAAAAAAAAA0srzUsuyczPU0itSMwtyEnV0FSo5lJQKEssUvCtdM0rzVWwVdDXUo6PDwgNco2P19JPg2nQgMhD1CtAVUcruWUWFZcoxQK1KaWBmdYo0sGpyfl5KRD5YggboqAotaS0KA%2BqDiRUC7VAoaZGobpW05qLC00RVy0XF9zVXACM67WcyQAAAA%3D%3D&config=H4sIAAAAAAAAA32UPXLjMAyFe5%2FCo3rbTZEDpNszcGgSlOkVCQ0BOtZkfPdAf46TQOokfA%2BC%2BAjg43A8NhdyzevxQx7lpbeFoDzeJUJDZnuTSAMuWXIl9tz8WemFRhRsRzCF7jNp2JYWeMqiv4u86RAJVvkSSzHHMDwXdJj6AkRPMYnK92qCzPQ9f2EF3zVwQuzA5j1kLJmYGVoomsxh19mewFztxLnU7ziJY5FQrTHSyuBNX7DXBdlHjpglrmAP1huHHjQWCziOV1ATpZ4kZpIzbmEPp9q2013%2F5HC1XbWspcJtuhv5ZQWeMRKbUFUzZrjlxEwXk3%2FCGEwBrkWrecGYt%2FL%2BA4gNnSXKNqlGTYogvbUNd1NjDtK%2FPChcml09aYZWrDUxBs3f0R8oHNWSBXx1MBrsdvCGGRQ9GAhBukbF75HdWS3LQw8YNCI3bdVjzMBsDubCxwHZwW9yUNZbbVEky%2BdtSkM6oTpZazrwGf2OQK6DcRsXWRu3fpvX7EEaBLwqqTSBXyslyyQwmm7an78bRAZFPmnaDk9Pa2NR3B%2BbOdncfk3%2FvJwPi6BJ6OsEl7U%2FXvG8rF%2BaL9G6mh%2F%2F0ET6t2aOv324fwIfWlHuQgYAAA%3D%3D
Expected behavior
I'd expect this to produce code along these lines:
(Which it does, if I remove the
__PURE__
comment or disable either one of thecollapse_vars
orunused
options. (Although the code does of course look slightly different then.))Actual behavior
No response
Version
1.3.44
Additional context
No response
The text was updated successfully, but these errors were encountered: