[Pkg-javascript-commits] [uglifyjs] 289/491: fix argument/atom collision by `collapse_vars` (#2507)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:45 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit eb001dc1d9efbb81841410c06d854091473061ee
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Nov 24 07:26:22 2017 +0800
fix argument/atom collision by `collapse_vars` (#2507)
fixes #2506
---
lib/compress.js | 24 +++++++++++++++++-------
test/compress/collapse_vars.js | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index ce881c0..d8a0bd7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -806,6 +806,12 @@ merge(Compressor.prototype, {
}
}
+ function is_identifier_atom(node) {
+ return node instanceof AST_Infinity
+ || node instanceof AST_NaN
+ || node instanceof AST_Undefined;
+ }
+
function tighten_body(statements, compressor) {
var CHANGED, max_iter = 10;
do {
@@ -890,14 +896,19 @@ merge(Compressor.prototype, {
return node;
}
var def = candidate.name.definition();
+ var value = candidate.value;
if (def.references.length - def.replaced == 1 && !compressor.exposed(def)) {
def.replaced++;
- return maintain_this_binding(parent, node, candidate.value);
+ if (funarg && is_identifier_atom(value)) {
+ return value.transform(compressor);
+ } else {
+ return maintain_this_binding(parent, node, value);
+ }
}
return make_node(AST_Assign, candidate, {
operator: "=",
left: make_node(AST_SymbolRef, candidate.name, candidate.name),
- right: candidate.value
+ right: value
});
}
candidate.write_only = false;
@@ -971,7 +982,8 @@ merge(Compressor.prototype, {
replace_all = def.references.length - def.replaced == 1;
}
var side_effects = value_has_side_effects(candidate);
- var hit = candidate.name instanceof AST_SymbolFunarg;
+ var funarg = candidate.name instanceof AST_SymbolFunarg;
+ var hit = funarg;
var abort = false, replaced = 0, can_replace = !args || !hit;
if (!can_replace) {
for (var j = compressor.self().argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) {
@@ -987,7 +999,7 @@ merge(Compressor.prototype, {
if (abort && def.references.length - def.replaced > replaced) replaced = false;
else {
abort = false;
- hit = candidate.name instanceof AST_SymbolFunarg;
+ hit = funarg;
for (var i = stat_index; !abort && i < statements.length; i++) {
statements[i].transform(multi_replacer);
}
@@ -3810,9 +3822,7 @@ merge(Compressor.prototype, {
if (self.operator == "delete"
&& !(e instanceof AST_SymbolRef
|| e instanceof AST_PropAccess
- || e instanceof AST_NaN
- || e instanceof AST_Infinity
- || e instanceof AST_Undefined)) {
+ || is_identifier_atom(e))) {
if (e instanceof AST_Sequence) {
e = e.expressions.slice();
e.push(make_node(AST_True, self));
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index e89d44d..844d5b0 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3618,3 +3618,41 @@ issue_2497: {
}
}
}
+
+issue_2506: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ var c = 0;
+ function f0(bar) {
+ function f1(Infinity_2) {
+ function f13(NaN) {
+ if (false <= NaN & this >> 1 >= 0) {
+ c++;
+ }
+ }
+ var b_2 = f13(NaN, c++);
+ }
+ var bar = f1(-3, -1);
+ }
+ f0(false);
+ console.log(c);
+ }
+ expect: {
+ var c = 0;
+ function f0(bar) {
+ (function(Infinity_2) {
+ (function(NaN) {
+ if (false <= 0/0 & this >> 1 >= 0)
+ c++;
+ })(0, c++);
+ })();
+ }
+ f0(false);
+ console.log(c);
+ }
+ expect_stdout: "1"
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list