-
-
Notifications
You must be signed in to change notification settings - Fork 415
Closed
Labels
Description
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.2
code to run
#!/usr/bin/env node
"use strict";
var opts = {
"mangle": {
"properties": true,
"toplevel": true
},
nameCache: { vars: {}, props: {} }
};
var terser = require('terser');
terser.minify('var Bar = {};', opts);
var result = terser.minify('var Foo = { foo: function() { return Bar.bar() } };', opts);
var expected = "var r={o:function(){return a.v()}};";
console.log("[task] test uglifying external properties",
"\n[Current ]", result.code, "\n[Expected]", expected);
expected result
var r={o:function(){return a.v()}};
real result
var r={o:function(){return a.bar()}};
why this is a bug
In a real case, if a Bar
is defined in some later files, I want to pre-define Bar
to make terser
uglifiy this name, and I also want to uglify all its properties. But I don't like to pass all input files to terser
during one calling to .minify
- I'm using Gulp, and the file which defines
Bar
is in another task - currently, I add an extra step to call
terser.minify("var Bar = {};")
by myself, and abort its output- so that the gulp task's output keeps smallest.
This 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:
When I reverted it to a simple add(node.property);
, this bug disappeared.