@@ -165,10 +165,12 @@ Compressor.prototype = new TreeTransformer;
|
|||||||
merge(Compressor.prototype, {
|
merge(Compressor.prototype, {
|
||||||
option: function(key) { return this.options[key] },
|
option: function(key) { return this.options[key] },
|
||||||
exposed: function(def) {
|
exposed: function(def) {
|
||||||
if (def.global) for (var i = 0; i < def.orig.length; i++)
|
if (def.undeclared) return true;
|
||||||
if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"])
|
if (!(def.global || def.scope.resolve() instanceof AST_Toplevel)) return false;
|
||||||
return true;
|
var toplevel = this.toplevel;
|
||||||
return def.undeclared;
|
return !all(def.orig, function(sym) {
|
||||||
|
return toplevel[sym instanceof AST_SymbolDefun ? "funcs" : "vars"];
|
||||||
|
});
|
||||||
},
|
},
|
||||||
compress: function(node) {
|
compress: function(node) {
|
||||||
node = node.resolve_defines(this);
|
node = node.resolve_defines(this);
|
||||||
@@ -6642,13 +6644,10 @@ merge(Compressor.prototype, {
|
|||||||
var node = defn.name;
|
var node = defn.name;
|
||||||
if (!node.fixed_value()) return false;
|
if (!node.fixed_value()) return false;
|
||||||
var def = node.definition();
|
var def = node.definition();
|
||||||
|
if (compressor.exposed(def)) return false;
|
||||||
var scope = def.scope.resolve();
|
var scope = def.scope.resolve();
|
||||||
if (scope instanceof AST_Toplevel) {
|
|
||||||
if (!compressor.toplevel.vars) return false;
|
|
||||||
if (def.scope === scope) return true;
|
|
||||||
return !scope.variables.has(node.name) && !scope.globals.has(node.name);
|
|
||||||
}
|
|
||||||
if (def.scope === scope) return true;
|
if (def.scope === scope) return true;
|
||||||
|
if (scope instanceof AST_Toplevel) return !scope.variables.has(node.name) && !scope.globals.has(node.name);
|
||||||
var s = def.scope;
|
var s = def.scope;
|
||||||
do {
|
do {
|
||||||
s = s.parent_scope;
|
s = s.parent_scope;
|
||||||
|
|||||||
@@ -909,3 +909,24 @@ issue_4205: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4207: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
{
|
||||||
|
const a = function() {};
|
||||||
|
console.log(a.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
{
|
||||||
|
const a = function() {};
|
||||||
|
console.log(a.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user