[Pkg-javascript-commits] [uglifyjs] 22/26: Referencing a global is assumed to have side effects.
Jonas Smedegaard
dr at jones.dk
Tue May 19 00:02:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v2.4.16
in repository uglifyjs.
commit 01d19b4b52abef47f8501e8719f0f17b11fc0d70
Author: Mihai Bazon <mihai at bazon.net>
Date: Sun Sep 28 11:16:51 2014 +0300
Referencing a global is assumed to have side effects.
Close #550
---
lib/compress.js | 4 +++-
test/compress/conditionals.js | 19 +++++++++++++++++++
test/compress/sequences.js | 8 ++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/lib/compress.js b/lib/compress.js
index 77de594..e63ce14 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -897,7 +897,9 @@ merge(Compressor.prototype, {
|| this.operator == "--"
|| this.expression.has_side_effects(compressor);
});
- def(AST_SymbolRef, function(compressor){ return false });
+ def(AST_SymbolRef, function(compressor){
+ return this.global() && this.undeclared();
+ });
def(AST_Object, function(compressor){
for (var i = this.properties.length; --i >= 0;)
if (this.properties[i].has_side_effects(compressor))
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index c20297a..2212f85 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -239,6 +239,7 @@ cond_7: {
evaluate : true
};
input: {
+ var x, y, z, a, b;
// compress these
if (y) {
x = 1+1;
@@ -281,6 +282,7 @@ cond_7: {
x = y ? 'foo' : 'fo';
}
expect: {
+ var x, y, z, a, b;
x = 2;
x = 2;
x = 'foo';
@@ -293,3 +295,20 @@ cond_7: {
}
}
+cond_7_1: {
+ options = {
+ conditionals: true,
+ evaluate : true
+ };
+ input: {
+ // access to global should be assumed to have side effects
+ if (y) {
+ x = 1+1;
+ } else {
+ x = 2;
+ }
+ }
+ expect: {
+ x = (y, 2);
+ }
+}
diff --git a/test/compress/sequences.js b/test/compress/sequences.js
index 4669571..0e3319a 100644
--- a/test/compress/sequences.js
+++ b/test/compress/sequences.js
@@ -91,9 +91,11 @@ make_sequences_4: {
lift_sequences_1: {
options = { sequences: true };
input: {
+ var foo, x, y, bar;
foo = !(x(), y(), bar());
}
expect: {
+ var foo, x, y, bar;
x(), y(), foo = !bar();
}
}
@@ -101,10 +103,12 @@ lift_sequences_1: {
lift_sequences_2: {
options = { sequences: true, evaluate: true };
input: {
+ var foo, bar;
foo.x = (foo = {}, 10);
bar = (bar = {}, 10);
}
expect: {
+ var foo, bar;
foo.x = (foo = {}, 10),
bar = {}, bar = 10;
}
@@ -113,9 +117,11 @@ lift_sequences_2: {
lift_sequences_3: {
options = { sequences: true, conditionals: true };
input: {
+ var x, foo, bar, baz;
x = (foo(), bar(), baz()) ? 10 : 20;
}
expect: {
+ var x, foo, bar, baz;
foo(), bar(), x = baz() ? 10 : 20;
}
}
@@ -123,9 +129,11 @@ lift_sequences_3: {
lift_sequences_4: {
options = { side_effects: true };
input: {
+ var x, foo, bar, baz;
x = (foo, bar, baz);
}
expect: {
+ var x, foo, bar, baz;
x = baz;
}
}
--
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