[Pkg-javascript-commits] [uglifyjs] 103/190: collapse_vars: fix bug in repeated var defs of same name
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:17 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit af2472d85e25e2bddad0b663b38281aeb61536e9
Author: kzc <zaxxon2011 at gmail.com>
Date: Wed Jan 27 18:35:49 2016 -0500
collapse_vars: fix bug in repeated var defs of same name
---
lib/compress.js | 15 ++++++++++++---
test/compress/collapse_vars.js | 28 ++++++++++++++++++++++------
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 6af086f..6cd5571 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -255,16 +255,25 @@ merge(Compressor.prototype, {
var var_defs = prev_stat.definitions;
if (var_defs == null) continue;
- // Scan variable definitions from right to left.
+ var var_names_seen = {};
var side_effects_encountered = false;
var lvalues_encountered = false;
var lvalues = {};
+
+ // Scan variable definitions from right to left.
for (var var_defs_index = var_defs.length; --var_defs_index >= 0;) {
+
+ // Obtain var declaration and var name with basic sanity check.
var var_decl = var_defs[var_defs_index];
- if (var_decl.value == null) continue;
+ if (var_decl.value == null) break;
+ var var_name = var_decl.name.name;
+ if (!var_name || !var_name.length) break;
+
+ // Bail if we've seen a var definition of same name before.
+ if (var_name in var_names_seen) break;
+ var_names_seen[var_name] = true;
// Only interested in cases with just one reference to the variable.
- var var_name = var_decl.name.name;
var def = self.find_variable && self.find_variable(var_name);
if (!def || !def.references || def.references.length !== 1 || var_name == "arguments") {
side_effects_encountered = true;
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index f67b3f4..39fee59 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -685,19 +685,35 @@ collapse_vars_repeated: {
var dummy = 3, a = 5, unused = 2, a = 1, a = 3;
return -a;
}
- function f2() {
- var a = 3, a = a + 2;
+ function f2(x) {
+ var a = 3, a = x;
return a;
}
+ (function(x){
+ var a = "GOOD" + x, e = "BAD", k = "!", e = a;
+ console.log(e + k);
+ })("!"),
+
+ (function(x){
+ var a = "GOOD" + x, e = "BAD" + x, k = "!", e = a;
+ console.log(e + k);
+ })("!");
}
expect: {
function f1() {
return -3
}
- function f2() {
- var a = 3, a = a + 2;
- return a
- }
+ function f2(x) {
+ return x
+ }
+ (function(x){
+ var a = "GOOD" + x, e = "BAD", e = a;
+ console.log(e + "!");
+ })("!"),
+ (function(x){
+ var a = "GOOD" + x, e = "BAD" + x, e = a;
+ console.log(e + "!");
+ })("!");
}
}
--
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