aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-24 02:55:32 +0800
committerGitHub <noreply@github.com>2017-03-24 02:55:32 +0800
commite918748d88e39c6f2142b01e71c3e580d790d642 (patch)
treee8df63c176d67d82f7bc3f5a6df7e99091248a4d /lib
parent6b2f34769a5572bdd9db034f19bbc2a0b6e6dabb (diff)
downloadtracifyjs-e918748d88e39c6f2142b01e71c3e580d790d642.tar.gz
tracifyjs-e918748d88e39c6f2142b01e71c3e580d790d642.zip
improve collapsible value detection (#1638)
- #1634 bars variables with cross-scope references in between to collapse - but if assigned value is side-effect-free, no states can be modified, so it is safe to move
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index cfa8f230..e75d7c96 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -592,9 +592,10 @@ merge(Compressor.prototype, {
// Restrict var replacement to constants if side effects encountered.
if (side_effects_encountered |= lvalues_encountered) continue;
+ var value_has_side_effects = var_decl.value.has_side_effects(compressor);
// Non-constant single use vars can only be replaced in same scope.
if (ref.scope !== self) {
- side_effects_encountered |= var_decl.value.has_side_effects(compressor);
+ side_effects_encountered |= value_has_side_effects;
continue;
}
@@ -620,6 +621,7 @@ merge(Compressor.prototype, {
|| (parent instanceof AST_If && node !== parent.condition)
|| (parent instanceof AST_Conditional && node !== parent.condition)
|| (node instanceof AST_SymbolRef
+ && value_has_side_effects
&& !are_references_in_scope(node.definition(), self))
|| (parent instanceof AST_Binary
&& (parent.operator == "&&" || parent.operator == "||")