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
When running minify / minifySync contents of objects declared at the global scope are being removed unless you reference that variable directly elsewhere in the source. If you only use part of the object (reference only some properties), it inlines those properties and drops the entire top-level variable declaration which seems broken.
Input code
const{minifySync}=require('@swc/core');constoptions={compress: true,mangle: true,module: false};constsource=`const index = {foo: 5, bar: 10};`;constuseIndex=`console.log(index);`constusePartOfIndex=`console.log(index.foo);`console.log('test1:',minifySync(source,options).code);console.log('test2:',minifySync(`${source}\n${useIndex}`,options).code);console.log('test3:',minifySync(`${source}\n${usePartOfIndex}`,options).code);
Config
{
"compress": true,
"mangle": true,
}
Playground link
No response
Expected behavior
The output Terser produces in this case matches my expectations. Since we have module: false, top-level variables should not be mangled, or removed since they are in the global scope. As a result, each of the 3 test cases has the full object definition for index, and references that variable for the console.log statements:
The code currently produced by SWC varies based on how/if the index variable is used ranging from the variable not being declared at all, being fully declared, or being an empty object.
The behavior when setting module: true is a lot more consistent because in that context the top-level variables are only in module scope and aren't externally visible outside of the module.
What we get in that case is the following result which matches expectations for when setting module: true:
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
When running
minify
/minifySync
contents of objects declared at the global scope are being removed unless you reference that variable directly elsewhere in the source. If you only use part of the object (reference only some properties), it inlines those properties and drops the entire top-level variable declaration which seems broken.Input code
Config
Playground link
No response
Expected behavior
The output Terser produces in this case matches my expectations. Since we have
module: false
, top-level variables should not be mangled, or removed since they are in the global scope. As a result, each of the 3 test cases has the full object definition for index, and references that variable for theconsole.log
statements:Actual behavior
The code currently produced by SWC varies based on how/if the
index
variable is used ranging from the variable not being declared at all, being fully declared, or being an empty object.Version
1.3.68
Additional context
The behavior when setting
module: true
is a lot more consistent because in that context the top-level variables are only in module scope and aren't externally visible outside of the module.What we get in that case is the following result which matches expectations for when setting
module: true
:or if you
export const index
:The text was updated successfully, but these errors were encountered: