diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-23 19:37:52 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 03:37:52 +0800 |
commit | acc443b2cf0614351aeb953e393260f13f783c96 (patch) | |
tree | 788ea95625b1a5c6972dad56a029b4b13d5b857c /test | |
parent | f87e7be12c7857ec0fc772a9ea4db6d24b5e3551 (diff) | |
download | tracifyjs-acc443b2cf0614351aeb953e393260f13f783c96.tar.gz tracifyjs-acc443b2cf0614351aeb953e393260f13f783c96.zip |
fix corner case in `reduce_vars` (#4585)
fixes #4584
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/destructured.js | 27 | ||||
-rw-r--r-- | test/ufuzz/index.js | 18 |
2 files changed, 39 insertions, 6 deletions
diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 7cc6f46d..58fec606 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -2487,3 +2487,30 @@ issue_4554: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4584: { + options = { + evaluate: true, + reduce_vars: true, + } + input: { + try { + (function f({ + [console.log(a = "FAIL")]: a, + }) {})(0); + } catch (e) { + console.log("PASS"); + } + } + expect: { + try { + (function f({ + [console.log(a = "FAIL")]: a, + }) {})(0); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index a6784ee7..0a6de2a3 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -431,12 +431,18 @@ function createAssignmentPairs(recurmax, stmtDepth, canThrow, nameLenBefore, was unique_vars.length = len; return pairs; - function mapShuffled(array, fn) { - var result = []; - for (var i = array.length; --i >= 0;) { - result.splice(rng(result.length + 1), 0, fn(array[i], i)); - } - return result; + function mapShuffled(values, fn) { + var ordered = []; + var shuffled = []; + values.forEach(function(value, index) { + value = fn(value, index); + if (/]:/.test(value) ? canThrow && rng(10) == 0 : rng(5)) { + shuffled.splice(rng(shuffled.length + 1), 0, value); + } else { + ordered.push(value); + } + }); + return shuffled.concat(ordered); } function convertToRest(names) { |