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
properties are not mangled if it's in a deferred top level object #397
Comments
The old issue message is here: it's too long and somehow incorrect, so I move it here just to archive it. description When I compiled Vimium C at commit gdh1995/vimium-c@c7cb108 using different versions of terser, the terser v4.1.2 cause null pointer exception, and after debugging, I found some properties are not mangled unexpectedly. After further tests, I've confirmed:
I tested removing it in v3.14.1 but this bug still exists. error details Vimium C has quite a few steps to compile it:
And:
|
Hey there! Nice extension :) What you described is not exactly a bug. Terser has no way of knowing whether lowercase What I found though, is that if I create another artificial file and use
I suppose this is the bug you're trying to report. In that case, sounds like an interesting bug. And indeed I want this to be a Terser feature. When this is fixed I'll ensure there's a test that protects your use case. Thanks for your report! |
Thanks. idea 1If it's hard to tell whether a variable is from outsides, I think a new option may be suitable to leave this problem to final users. idea 2For the project I mentioned above, it's in TypeScript and I've applied many "strict" rules, so I have a terser config looking like this (from https://github.com/gdh1995/vimium-c/blob/master/scripts/uglifyjs.dist.json): var config = {
"compress": {
"properties": true,
"pure_getters": true,
"toplevel": false,
},
"mangle": {
"properties": {
"regex": /^_|_$/
},
"toplevel": true,
"reserved": [
// # expected names in web-extension content
"WeakSet", "Set",
// # expected names in 3rd-party extensions' contents
"requestIdleCallback",
// # content global names:
"browser",
"VimiumInjector", "VDom", "VKey",
"VHints", "VScroller", "VOmni", "VFind", "VVisual", "VMarks",
"VHud", "VPort", "VEvent",
// ...
],
// I've ensured all other global names of my code MUST start / end with "_",
// and they are mangled correctly by terser v3.10.*.
}
}; And as said in the comment, only those global variables name which starts/ends with "_" will be mangled, so I wonder if terser may think "all matched global names and their properties visits should be uglified" when it knows:
|
Bug report or Feature request? Bug report
Version (complete output of
terser -V
or specific git commit) from v3.14.1 to the latest v4.1.2code to run
expected result
real result
why this is a bug
In a real case, if a
Bar
is defined in some later files, I want to pre-defineBar
to maketerser
uglifiy this name, and I also want to uglify all its properties. But I don't like to pass all input files toterser
during one calling to.minify
Bar
is in another taskterser.minify("var Bar = {};")
by myself, and abort its outputThis usage works well under terser v3.10.*, and something becames wrong since terser v3.14.1 .
I've read #219 , but I think my usage is still worth a new if-branch.
debugging
I find a commit in v3.14.1 seems to blame:
https://github.com/terser-js/terser/blob/b4dda6d2ccdc94ac42f6dbf459af50ac343f9454/lib/propmangle.js#L168-L173
When I reverted it to a simple
add(node.property);
, this bug disappeared.The text was updated successfully, but these errors were encountered: