diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-10 16:06:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 00:06:13 +0800 |
commit | fba27bfb71cd973f76e8d1007edec935f25ace77 (patch) | |
tree | ca3173c102dea8a4dfab916244f19a4aa7737766 | |
parent | 41310e6404951cf9be119cb7cb478be73a98300d (diff) | |
download | tracifyjs-fba27bfb71cd973f76e8d1007edec935f25ace77.tar.gz tracifyjs-fba27bfb71cd973f76e8d1007edec935f25ace77.zip |
fix corner case in `evaluate` (#4272)
fixes #4271
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/evaluate.js | 27 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js index ef775b9e..f44552aa 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3592,10 +3592,7 @@ merge(Compressor.prototype, { key = key._eval(compressor, ignore_side_effects, cached, depth); if (key === prop.key) return this; } - if (prop.value instanceof AST_Function) { - if (typeof Object.prototype[key] == "function") return this; - continue; - } + if (prop.value instanceof AST_Function && typeof Object.prototype[key] == "function") return this; val[key] = prop.value._eval(compressor, ignore_side_effects, cached, depth); if (val[key] === prop.value) return this; } diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 9fa65202..46a92ee3 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -3047,3 +3047,30 @@ issue_4214: { } expect_stdout: "NaN" } + +issue_4271: { + options = { + evaluate: true, + unsafe: true, + } + input: { + ({ + p: null, + q: (console.log("foo"), 42), + p: function() {} + })[console.log("bar"), "p"] && console.log("PASS"); + } + expect: { + ({ + p: null, + q: (console.log("foo"), 42), + p: function() {} + })[console.log("bar"), "p"], + console.log("PASS"); + } + expect_stdout: [ + "foo", + "bar", + "PASS", + ] +} |