aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-11-08 10:50:08 +0000
committerGitHub <noreply@github.com>2020-11-08 18:50:08 +0800
commit810cd40356f6fa1ddbc9c97a0df95bd1d94a2720 (patch)
tree5c5c728f40005fc194ec5a3ea08c7dbad5795ea4
parent1cbd07e7897bcbb879921c63b9794f7a278ca5a6 (diff)
downloadtracifyjs-810cd40356f6fa1ddbc9c97a0df95bd1d94a2720.tar.gz
tracifyjs-810cd40356f6fa1ddbc9c97a0df95bd1d94a2720.zip
fix corner case in `inline` (#4266)
fixes #4265
-rw-r--r--lib/compress.js8
-rw-r--r--test/compress/functions.js31
2 files changed, 36 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9333cdf9..47eba90f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -7166,7 +7166,7 @@ merge(Compressor.prototype, {
return node;
}
}
- var child, in_loop, scope;
+ var insert, in_loop, scope;
if (replacing && can_inject_symbols()) {
fn._squeezed = true;
if (exp !== fn) fn.parent_scope = exp.scope;
@@ -7336,7 +7336,7 @@ merge(Compressor.prototype, {
function can_inject_symbols() {
var defined = Object.create(null);
- var level = 0;
+ var level = 0, child;
scope = compressor.self();
while (!(scope instanceof AST_Scope)) {
if (scope.variables) scope.variables.each(function(def) {
@@ -7357,6 +7357,8 @@ merge(Compressor.prototype, {
if (scope.fixed_value() instanceof AST_Scope) return false;
}
}
+ insert = scope.body.indexOf(child) + 1;
+ if (!insert) return false;
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
&& (exp !== fn || fn.parent_scope.resolve() === compressor.find_parent(AST_Scope));
var inline = compressor.option("inline");
@@ -7459,7 +7461,7 @@ merge(Compressor.prototype, {
return true;
}
});
- args.unshift(scope.body.indexOf(child) + 1, 0);
+ args.unshift(insert, 0);
if (decls.length) args.push(make_node(AST_Var, fn, {
definitions: decls
}));
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 3b57fb2b..686e7a50 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -5183,3 +5183,34 @@ issue_4261: {
}
expect_stdout: true
}
+
+issue_4265: {
+ options = {
+ conditionals: true,
+ dead_code: true,
+ inline: true,
+ sequences: true,
+ }
+ input: {
+ function f() {
+ console;
+ if ([ function() {
+ return this + console.log(a);
+ a;
+ var a;
+ }() ]);
+ return 0;
+ }
+ f();
+ }
+ expect: {
+ function f() {
+ return console, function() {
+ return console.log(a);
+ var a;
+ }(), 0;
+ }
+ f();
+ }
+ expect_stdout: "undefined"
+}