aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorkzc <kzc@users.noreply.github.com>2017-03-06 12:42:33 -0500
committerAlex Lam S.L <alexlamsl@gmail.com>2017-03-07 01:42:33 +0800
commit3ac24219322384539caae803482ea257e7971cf2 (patch)
tree8964d96e572a22d450fc78a87b8e8c7717d60999 /lib/compress.js
parenta9fc9ddc3371a2ba051bca849db3c4b73983f24d (diff)
downloadtracifyjs-3ac24219322384539caae803482ea257e7971cf2.tar.gz
tracifyjs-3ac24219322384539caae803482ea257e7971cf2.zip
collapse_vars: do not replace a constant in loop condition or init (#1562)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d9a67c16..8c3fb155 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -535,10 +535,13 @@ merge(Compressor.prototype, {
// Constant single use vars can be replaced in any scope.
if (var_decl.value.is_constant()) {
var ctt = new TreeTransformer(function(node) {
- if (node === ref
- && !ctt.find_parent(AST_ForIn)) {
- return replace_var(node, ctt.parent(), true);
+ var parent = ctt.parent();
+ if (parent instanceof AST_IterationStatement
+ && (parent.condition === node || parent.init === node)) {
+ return node;
}
+ if (node === ref)
+ return replace_var(node, parent, true);
});
stat.transform(ctt);
continue;