[Pkg-javascript-commits] [uglifyjs] 195/228: avoid confusion of `NaN` & `Infinity` with `catch` symbol of the same name (#1763)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:29 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit d57527697fba37bfad50ca0283326a458cdea031
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Apr 2 16:14:09 2017 +0800
avoid confusion of `NaN` & `Infinity` with `catch` symbol of the same name (#1763)
fixes #1760
fixes #1761
---
lib/compress.js | 22 +++++++++++++------
test/compress/evaluate.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 5776fb8..763490a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -409,6 +409,18 @@ merge(Compressor.prototype, {
}
});
+ function find_variable(compressor, name) {
+ var scope, i = 0;
+ while (scope = compressor.parent(i++)) {
+ if (scope instanceof AST_Scope) break;
+ if (scope instanceof AST_Catch) {
+ scope = scope.argname.definition().scope;
+ break;
+ }
+ }
+ return scope.find_variable(name);
+ }
+
function make_node(ctor, orig, props) {
if (!props) props = {};
if (orig) {
@@ -3517,12 +3529,11 @@ merge(Compressor.prototype, {
OPT(AST_Undefined, function(self, compressor){
if (compressor.option("unsafe")) {
- var scope = compressor.find_parent(AST_Scope);
- var undef = scope.find_variable("undefined");
+ var undef = find_variable(compressor, "undefined");
if (undef) {
var ref = make_node(AST_SymbolRef, self, {
name : "undefined",
- scope : scope,
+ scope : undef.scope,
thedef : undef
});
ref.is_undefined = true;
@@ -3538,8 +3549,7 @@ merge(Compressor.prototype, {
});
OPT(AST_Infinity, function(self, compressor){
- var retain = compressor.option("keep_infinity")
- && !compressor.find_parent(AST_Scope).find_variable("Infinity");
+ var retain = compressor.option("keep_infinity") && !find_variable(compressor, "Infinity");
return retain ? self : make_node(AST_Binary, self, {
operator: "/",
left: make_node(AST_Number, self, {
@@ -3552,7 +3562,7 @@ merge(Compressor.prototype, {
});
OPT(AST_NaN, function(self, compressor){
- return compressor.find_parent(AST_Scope).find_variable("NaN") ? make_node(AST_Binary, self, {
+ return find_variable(compressor, "NaN") ? make_node(AST_Binary, self, {
operator: "/",
left: make_node(AST_Number, self, {
value: 0
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 0d26e74..fa432c4 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -802,3 +802,58 @@ issue_1649: {
}
expect_stdout: "-2";
}
+
+issue_1760_1: {
+ options = {
+ evaluate: true,
+ }
+ input: {
+ !function(a) {
+ try {
+ throw 0;
+ } catch (NaN) {
+ a = +"foo";
+ }
+ console.log(a);
+ }();
+ }
+ expect: {
+ !function(a) {
+ try {
+ throw 0;
+ } catch (NaN) {
+ a = 0 / 0;
+ }
+ console.log(a);
+ }();
+ }
+ expect_stdout: "NaN"
+}
+
+issue_1760_2: {
+ options = {
+ evaluate: true,
+ keep_infinity: true,
+ }
+ input: {
+ !function(a) {
+ try {
+ throw 0;
+ } catch (Infinity) {
+ a = 123456789 / 0;
+ }
+ console.log(a);
+ }();
+ }
+ expect: {
+ !function(a) {
+ try {
+ throw 0;
+ } catch (Infinity) {
+ a = 1 / 0;
+ }
+ console.log(a);
+ }();
+ }
+ expect_stdout: "Infinity"
+}
--
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