[Pkg-javascript-commits] [uglifyjs] 211/228: fix corner cases with `delete` (#1796)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:31 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 e3c9c22c757112327b83f598b124690baf13ac52
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Apr 7 15:39:59 2017 +0800
fix corner cases with `delete` (#1796)
`delete Infinity` returns `false` where as `delete (1/0)` returns `true`
---
lib/compress.js | 43 ++++++++++++++++++++++++++++++++-----------
test/compress/evaluate.js | 23 +++++++++++++++++++++++
2 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index c199d13..b001d35 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3620,6 +3620,11 @@ merge(Compressor.prototype, {
return ref;
}
}
+ var parent = compressor.parent();
+ if (parent instanceof AST_UnaryPrefix
+ && parent.operator == "delete"
+ && (parent.expression instanceof AST_SymbolRef
+ || parent.expression.TYPE === self.TYPE)) return self;
return make_node(AST_UnaryPrefix, self, {
operator: "void",
expression: make_node(AST_Number, self, {
@@ -3629,8 +3634,16 @@ merge(Compressor.prototype, {
});
OPT(AST_Infinity, function(self, compressor){
- var retain = compressor.option("keep_infinity") && !find_variable(compressor, "Infinity");
- return retain ? self : make_node(AST_Binary, self, {
+ var parent = compressor.parent();
+ if (parent instanceof AST_UnaryPrefix
+ && parent.operator == "delete"
+ && (parent.expression instanceof AST_SymbolRef
+ || parent.expression.TYPE === self.TYPE))
+ return self;
+ if (compressor.option("keep_infinity")
+ && !find_variable(compressor, "Infinity"))
+ return self;
+ return make_node(AST_Binary, self, {
operator: "/",
left: make_node(AST_Number, self, {
value: 1
@@ -3642,15 +3655,23 @@ merge(Compressor.prototype, {
});
OPT(AST_NaN, function(self, compressor){
- return find_variable(compressor, "NaN") ? make_node(AST_Binary, self, {
- operator: "/",
- left: make_node(AST_Number, self, {
- value: 0
- }),
- right: make_node(AST_Number, self, {
- value: 0
- })
- }) : self;
+ var parent = compressor.parent();
+ if (parent instanceof AST_UnaryPrefix
+ && parent.operator == "delete"
+ && !(parent.expression instanceof AST_SymbolRef
+ || parent.expression.TYPE === self.TYPE)
+ || find_variable(compressor, "NaN")) {
+ return make_node(AST_Binary, self, {
+ operator: "/",
+ left: make_node(AST_Number, self, {
+ value: 0
+ }),
+ right: make_node(AST_Number, self, {
+ value: 0
+ })
+ });
+ }
+ return self;
});
var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index fa432c4..e660071 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -857,3 +857,26 @@ issue_1760_2: {
}
expect_stdout: "Infinity"
}
+
+delete_expr: {
+ options = {
+ evaluate: true,
+ }
+ input: {
+ console.log(delete undefined);
+ console.log(delete void 0);
+ console.log(delete Infinity);
+ console.log(delete (1 / 0));
+ console.log(delete NaN);
+ console.log(delete (0 / 0));
+ }
+ expect: {
+ console.log(delete undefined);
+ console.log(delete void 0);
+ console.log(delete Infinity);
+ console.log(delete (1 / 0));
+ console.log(delete NaN);
+ console.log(delete (0 / 0));
+ }
+ expect_stdout: true
+}
--
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