aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-17 19:53:26 +0100
committerGitHub <noreply@github.com>2020-04-18 02:53:26 +0800
commitda68ec6e190e8969741606b2b2a3eb2d327061ba (patch)
tree17aa71636bf7a44155e70626526ecfb980f830c3 /lib
parent15a3ebd467ea1f88b55affb0c3cc2d218fad3718 (diff)
downloadtracifyjs-da68ec6e190e8969741606b2b2a3eb2d327061ba.tar.gz
tracifyjs-da68ec6e190e8969741606b2b2a3eb2d327061ba.zip
fix corner cases in `join_vars` (#3790)
fixes #3789 fixes #3791
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2491757f..70ac9b8f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2330,7 +2330,7 @@ merge(Compressor.prototype, {
statements.length = n;
}
- function join_assigns(defn, body) {
+ function join_assigns(defn, body, keep) {
var exprs;
if (body instanceof AST_Assign) {
exprs = [ body ];
@@ -2352,14 +2352,14 @@ merge(Compressor.prototype, {
if (defn instanceof AST_Definitions) {
var def = defn.definitions[defn.definitions.length - 1];
if (trim_assigns(def.name, def.value, exprs)) trimmed = true;
- if (join_var_assign(defn.definitions, exprs)) trimmed = true;
+ if (join_var_assign(defn.definitions, exprs, keep || 0)) trimmed = true;
}
return trimmed && exprs;
}
- function join_var_assign(definitions, exprs) {
+ function join_var_assign(definitions, exprs, keep) {
var trimmed = false;
- while (exprs.length) {
+ while (exprs.length > keep) {
var expr = exprs[0];
if (!(expr instanceof AST_Assign)) break;
if (expr.operator != "=") break;
@@ -2367,7 +2367,9 @@ merge(Compressor.prototype, {
if (!(lhs instanceof AST_SymbolRef)) break;
if (is_undeclared_ref(lhs)) break;
var def = lhs.definition();
- if (def.scope !== definitions[0].name.scope) break;
+ if (def.scope !== lhs.scope) break;
+ if (def.orig.length > def.eliminated + 1) break;
+ if (def.orig[0].TYPE != "SymbolVar") break;
var name = make_node(AST_SymbolVar, lhs, lhs);
definitions.push(make_node(AST_VarDef, expr, {
name: name,
@@ -2478,7 +2480,7 @@ merge(Compressor.prototype, {
function join_assigns_expr(value) {
statements[++j] = stat;
- var exprs = join_assigns(prev, value);
+ var exprs = join_assigns(prev, value, 1);
if (!exprs) return value;
CHANGED = true;
var tail = value.tail_node();
@@ -6045,11 +6047,21 @@ merge(Compressor.prototype, {
function can_inject_symbols() {
var catches = Object.create(null);
+ var child;
+ scope = compressor.self();
do {
+ child = scope;
scope = compressor.parent(++level);
if (scope instanceof AST_Catch) {
catches[scope.argname.name] = true;
- } else if (scope instanceof AST_IterationStatement) {
+ } else if (scope instanceof AST_DWLoop) {
+ in_loop = [];
+ } else if (scope instanceof AST_For) {
+ if (scope.init === child) continue;
+ in_loop = [];
+ } else if (scope instanceof AST_ForIn) {
+ if (scope.init === child) continue;
+ if (scope.object === child) continue;
in_loop = [];
} else if (scope instanceof AST_SymbolRef) {
if (scope.fixed_value() instanceof AST_Scope) return false;