aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-06-13 01:40:14 +0800
committerGitHub <noreply@github.com>2017-06-13 01:40:14 +0800
commit2bdc8802ddd913a8b3b921426e898fc2f2257265 (patch)
tree8ae7323ea65471a23575fea7b3f337bdf3c0891b /lib/compress.js
parent5ef7cb372abf82f28d7f1b014fd0ddb2ef5bdec8 (diff)
downloadtracifyjs-2bdc8802ddd913a8b3b921426e898fc2f2257265.tar.gz
tracifyjs-2bdc8802ddd913a8b3b921426e898fc2f2257265.zip
fix variable accounting in `inline` (#2085)
fixes #2084
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5f2ac2b0..4d768781 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3171,16 +3171,16 @@ merge(Compressor.prototype, {
&& !exp.uses_arguments
&& !exp.uses_eval
&& !self.has_pure_annotation(compressor)) {
- var body;
+ var value;
if (stat instanceof AST_Return) {
- body = stat.value.clone(true);
+ value = stat.value.clone(true);
} else if (stat instanceof AST_SimpleStatement) {
- body = [];
- merge_sequence(body, stat.body.clone(true));
- merge_sequence(body, make_node(AST_Undefined, self));
- body = make_sequence(self, body);
+ value = make_node(AST_UnaryPrefix, stat, {
+ operator: "void",
+ expression: stat.body.clone(true)
+ });
}
- if (body) {
+ if (value) {
var fn = exp.clone();
fn.argnames = [];
fn.body = [];
@@ -3200,17 +3200,25 @@ merge(Compressor.prototype, {
}));
}
fn.body.push(make_node(AST_Return, self, {
- value: body
+ value: value
}));
- body = fn.transform(compressor).body;
+ var body = fn.transform(compressor).body;
if (body.length == 0) return make_node(AST_Undefined, self);
if (body.length == 1 && body[0] instanceof AST_Return) {
- if (!body[0].value) return make_node(AST_Undefined, self);
- body = best_of(compressor, body[0].value, self);
+ value = body[0].value;
+ if (!value) return make_node(AST_Undefined, self);
+ value.walk(new TreeWalker(function(node) {
+ if (value === self) return true;
+ if (node instanceof AST_SymbolRef && exp.variables.has(node.name)) {
+ value = self;
+ return true;
+ }
+ }));
+ if (value !== self) value = best_of(compressor, value, self);
} else {
- body = self;
+ value = self;
}
- if (body !== self) return body;
+ if (value !== self) return value;
}
}
if (compressor.option("side_effects") && all(exp.body, is_empty)) {