aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-18 03:31:20 +0000
committerGitHub <noreply@github.com>2021-03-18 11:31:20 +0800
commit2508481e33271cb9a402401eecd6a51b2701c265 (patch)
treee284b3e52edca2bef52c0cd79d6727cd9da78303
parent48c46fa9a72e480ddae721548fc2de929a7e925a (diff)
downloadtracifyjs-2508481e33271cb9a402401eecd6a51b2701c265.tar.gz
tracifyjs-2508481e33271cb9a402401eecd6a51b2701c265.zip
fix corner case in `evaluate` (#4800)
fixes #4799
-rw-r--r--lib/compress.js25
-rw-r--r--test/compress/functions.js18
2 files changed, 30 insertions, 13 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2224e144..81298cb6 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1429,6 +1429,7 @@ merge(Compressor.prototype, {
}
}
+ var identifier_atom = makePredicate("Infinity NaN undefined");
function is_lhs_read_only(lhs, compressor) {
if (lhs instanceof AST_ObjectIdentity) return true;
if (lhs instanceof AST_PropAccess) {
@@ -1616,13 +1617,6 @@ merge(Compressor.prototype, {
|| compressor.option("unsafe") && global_names[this.name];
});
- var identifier_atom = makePredicate("Infinity NaN undefined");
- function is_identifier_atom(node) {
- return node instanceof AST_Infinity
- || node instanceof AST_NaN
- || node instanceof AST_Undefined;
- }
-
function declarations_only(node) {
return all(node.definitions, function(var_def) {
return !var_def.value;
@@ -9438,11 +9432,7 @@ merge(Compressor.prototype, {
OPT(AST_UnaryPrefix, function(self, compressor) {
var op = self.operator;
var exp = self.expression;
- if (compressor.option("evaluate")
- && op == "delete"
- && !(exp instanceof AST_SymbolRef
- || exp instanceof AST_PropAccess
- || is_identifier_atom(exp))) {
+ if (compressor.option("evaluate") && op == "delete" && !may_not_delete(exp)) {
return make_sequence(self, [ exp, make_node(AST_True, self) ]).optimize(compressor);
}
if (compressor.option("sequences") && can_lift()) {
@@ -9496,10 +9486,19 @@ merge(Compressor.prototype, {
return op == "-" && (exp instanceof AST_Number || exp instanceof AST_Infinity)
? self : try_evaluate(compressor, self);
+ function may_not_delete(node) {
+ return node instanceof AST_Infinity
+ || node instanceof AST_NaN
+ || node instanceof AST_NewTarget
+ || node instanceof AST_PropAccess
+ || node instanceof AST_SymbolRef
+ || node instanceof AST_Undefined;
+ }
+
function can_lift() {
switch (op) {
case "delete":
- return !is_identifier_atom(exp.tail_node());
+ return !may_not_delete(exp.tail_node());
case "typeof":
return !is_undeclared_ref(exp.tail_node());
default:
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 2c529f0f..f0e0d50f 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -5851,6 +5851,24 @@ new_target_collapse_vars: {
node_version: ">=6"
}
+new_target_delete: {
+ options = {
+ evaluate: true,
+ }
+ input: {
+ new function() {
+ console.log(delete new.target);
+ }();
+ }
+ expect: {
+ new function() {
+ console.log(delete new.target);
+ }();
+ }
+ expect_stdout: true
+ node_version: ">=6"
+}
+
new_target_reduce_vars: {
options = {
evaluate: true,