aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-19 08:16:53 +0000
committerGitHub <noreply@github.com>2021-03-19 16:16:53 +0800
commitb89cc84c3a9cb7f250fbe218bc3e5ea3f7f80dae (patch)
tree1638024b05d91eb57b2b4f3f66bce11a9f97588d
parent3016a78d85025e435c55565e645835986db8c98f (diff)
downloadtracifyjs-b89cc84c3a9cb7f250fbe218bc3e5ea3f7f80dae.tar.gz
tracifyjs-b89cc84c3a9cb7f250fbe218bc3e5ea3f7f80dae.zip
fix corner case in `pure_getters` (#4804)
fixes #4803
-rw-r--r--lib/compress.js9
-rw-r--r--test/compress/pure_getters.js34
2 files changed, 32 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d920bc11..19806b98 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3601,14 +3601,7 @@ merge(Compressor.prototype, {
return true;
});
def(AST_Binary, function(compressor) {
- switch (this.operator) {
- case "&&":
- return this.left._dot_throw(compressor) || this.right._dot_throw(compressor);
- case "||":
- return this.right._dot_throw(compressor);
- default:
- return false;
- }
+ return lazy_op[this.operator] && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor));
});
def(AST_Class, return_false);
def(AST_Conditional, function(compressor) {
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js
index bf6f73ef..d1dd07ee 100644
--- a/test/compress/pure_getters.js
+++ b/test/compress/pure_getters.js
@@ -1320,11 +1320,10 @@ issue_2878: {
issue_3427: {
options = {
- assignments: true,
- collapse_vars: true,
+ evaluate: true,
inline: true,
- passes: 2,
pure_getters: "strict",
+ reduce_vars: true,
sequences: true,
side_effects: true,
toplevel: true,
@@ -1536,3 +1535,32 @@ this_toString: {
expect_stdout: "[object Object]"
node_version: ">=4"
}
+
+issue_4803: {
+ options = {
+ hoist_vars: true,
+ pure_getters: "strict",
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ }
+ input: {
+ var o = {
+ get f() {
+ console.log("PASS");
+ },
+ } || 42;
+ for (var k in o)
+ o[k];
+ }
+ expect: {
+ var k, o = {
+ get f() {
+ console.log("PASS");
+ },
+ } || 42;
+ for (k in o)
+ o[k];
+ }
+ expect_stdout: "PASS"
+}