aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-28 13:08:40 +0800
committerGitHub <noreply@github.com>2017-11-28 13:08:40 +0800
commitecc9f6b77093758d78a693a5ac4b6bcaf75e9a3f (patch)
treed1da1a5309bd75053dae1fde43c1b086ae192e7e /lib
parentb37a68c84f7b74de8ec7fc862792964c436fa2ec (diff)
downloadtracifyjs-ecc9f6b77093758d78a693a5ac4b6bcaf75e9a3f.tar.gz
tracifyjs-ecc9f6b77093758d78a693a5ac4b6bcaf75e9a3f.zip
drop assignment in `AST_VarDef.value` (#2522)
fixes #2516
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js59
1 files changed, 28 insertions, 31 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 22415f4d..b51fdfc7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1088,6 +1088,7 @@ merge(Compressor.prototype, {
function get_lhs(expr) {
if (expr instanceof AST_VarDef) {
var def = expr.name.definition();
+ if (!member(expr.name, def.orig)) return;
var declared = def.orig.length - def.eliminated;
var referenced = def.references.length - def.replaced;
if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)
@@ -2434,47 +2435,18 @@ merge(Compressor.prototype, {
});
return true;
}
- var sym;
- if (scope === self
- && (sym = assign_as_unused(node)) instanceof AST_SymbolRef
- && self.variables.get(sym.name) === sym.definition()) {
- if (node instanceof AST_Assign) node.right.walk(tw);
- return true;
- }
- if (node instanceof AST_SymbolRef) {
- var node_def = node.definition();
- if (!(node_def.id in in_use_ids)) {
- in_use_ids[node_def.id] = true;
- in_use.push(node_def);
- }
- return true;
- }
- if (node instanceof AST_Scope) {
- var save_scope = scope;
- scope = node;
- descend();
- scope = save_scope;
- return true;
- }
+ return scan_ref_scoped(node, descend);
});
self.walk(tw);
// pass 2: for every used symbol we need to walk its
// initialization code to figure out if it uses other
// symbols (that may not be in_use).
+ tw = new TreeWalker(scan_ref_scoped);
for (var i = 0; i < in_use.length; ++i) {
in_use[i].orig.forEach(function(decl){
// undeclared globals will be instanceof AST_SymbolRef
var init = initializations.get(decl.name);
if (init) init.forEach(function(init){
- var tw = new TreeWalker(function(node){
- if (node instanceof AST_SymbolRef) {
- var node_def = node.definition();
- if (!(node_def.id in in_use_ids)) {
- in_use_ids[node_def.id] = true;
- in_use.push(node_def);
- }
- }
- });
init.walk(tw);
});
});
@@ -2663,6 +2635,31 @@ merge(Compressor.prototype, {
}
);
self.transform(tt);
+
+ function scan_ref_scoped(node, descend) {
+ var sym;
+ if (scope === self
+ && (sym = assign_as_unused(node)) instanceof AST_SymbolRef
+ && self.variables.get(sym.name) === sym.definition()) {
+ if (node instanceof AST_Assign) node.right.walk(tw);
+ return true;
+ }
+ if (node instanceof AST_SymbolRef) {
+ var node_def = node.definition();
+ if (!(node_def.id in in_use_ids)) {
+ in_use_ids[node_def.id] = true;
+ in_use.push(node_def);
+ }
+ return true;
+ }
+ if (node instanceof AST_Scope) {
+ var save_scope = scope;
+ scope = node;
+ descend();
+ scope = save_scope;
+ return true;
+ }
+ }
});
AST_Scope.DEFMETHOD("hoist_declarations", function(compressor){