[Pkg-javascript-commits] [uglifyjs] 115/190: Don't compress (0, eval)() to eval()
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:18 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 9662228f6a026908aaf6f3e3531b6abd98fa28fc
Author: Richard van Velzen <rvanvelzen at experty.com>
Date: Tue Feb 16 19:00:48 2016 +0100
Don't compress (0, eval)() to eval()
---
lib/compress.js | 34 ++++++++++++++++++----------------
test/compress/issue-973.js | 17 +++++++++++++++++
2 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 16dc90f..df8975d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -179,14 +179,16 @@ merge(Compressor.prototype, {
// we shouldn't compress (1,func)(something) to
// func(something) because that changes the meaning of
// the func (becomes lexical instead of global).
- function maintain_this_binding(parent, orig, val) {
- if (parent instanceof AST_Call && parent.expression === orig && val instanceof AST_PropAccess) {
- return make_node(AST_Seq, orig, {
- car: make_node(AST_Number, orig, {
- value: 0
- }),
- cdr: val
- });
+ function maintain_call_binding(parent, orig, val) {
+ if (parent instanceof AST_Call && parent.expression === orig) {
+ if (val instanceof AST_PropAccess || (val instanceof AST_Symbol && val.name === "eval")) {
+ return make_node(AST_Seq, orig, {
+ car: make_node(AST_Number, orig, {
+ value: 0
+ }),
+ cdr: val
+ });
+ }
}
return val;
}
@@ -381,7 +383,7 @@ merge(Compressor.prototype, {
if (is_lvalue(node, parent)) return node;
// Remove var definition and return its value to the TreeTransformer to replace.
- var value = maintain_this_binding(parent, node, var_decl.value);
+ var value = maintain_call_binding(parent, node, var_decl.value);
var_decl.value = null;
var_defs.splice(var_defs_index, 1);
@@ -2123,7 +2125,7 @@ merge(Compressor.prototype, {
if (!compressor.option("side_effects"))
return self;
if (!self.car.has_side_effects(compressor)) {
- return maintain_this_binding(compressor.parent(), self, self.cdr);
+ return maintain_call_binding(compressor.parent(), self, self.cdr);
}
if (compressor.option("cascade")) {
if (self.car instanceof AST_Assign
@@ -2313,10 +2315,10 @@ merge(Compressor.prototype, {
if (ll.length > 1) {
if (ll[1]) {
compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
+ return maintain_call_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
} else {
compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, ll[0]);
+ return maintain_call_binding(compressor.parent(), self, ll[0]);
}
}
}
@@ -2325,10 +2327,10 @@ merge(Compressor.prototype, {
if (ll.length > 1) {
if (ll[1]) {
compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, ll[0]);
+ return maintain_call_binding(compressor.parent(), self, ll[0]);
} else {
compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
+ return maintain_call_binding(compressor.parent(), self, self.right.evaluate(compressor)[0]);
}
}
}
@@ -2553,10 +2555,10 @@ merge(Compressor.prototype, {
if (cond.length > 1) {
if (cond[1]) {
compressor.warn("Condition always true [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.consequent);
+ return maintain_call_binding(compressor.parent(), self, self.consequent);
} else {
compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
- return maintain_this_binding(compressor.parent(), self, self.alternative);
+ return maintain_call_binding(compressor.parent(), self, self.alternative);
}
}
var negated = cond[0].negate(compressor);
diff --git a/test/compress/issue-973.js b/test/compress/issue-973.js
index 41fb0e2..f2d4401 100644
--- a/test/compress/issue-973.js
+++ b/test/compress/issue-973.js
@@ -49,4 +49,21 @@ this_binding_collapse_vars: {
a();
(0, a.b)();
}
+}
+
+eval_direct_calls: {
+ options = {
+ side_effects: true,
+ collapse_vars: true
+ }
+ input: {
+ (0, eval)('');
+
+ var fn = eval;
+ fn('');
+ }
+ expect: {
+ (0, eval)('');
+ (0, eval)('');
+ }
}
\ No newline at end of file
--
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