diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-17 17:47:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 01:47:07 +0800 |
commit | e616916de5d28df06ae33bd4ed3b9431ae47d64b (patch) | |
tree | 1d006d6e8ebd0640eb041d4b4c098caaa6a002e3 /test/reduce.js | |
parent | 8d2151662355a05f1e2fde864168cfddd8eedcda (diff) | |
download | tracifyjs-e616916de5d28df06ae33bd4ed3b9431ae47d64b.tar.gz tracifyjs-e616916de5d28df06ae33bd4ed3b9431ae47d64b.zip |
fix corner case in `reduce_vars` (#4563)
fixes #4562
Diffstat (limited to 'test/reduce.js')
-rw-r--r-- | test/reduce.js | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/test/reduce.js b/test/reduce.js index 3f24b7b4..c478da5f 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -104,15 +104,14 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) // quick ignores if (node instanceof U.AST_Accessor) return; - if (node instanceof U.AST_Destructured) return; if (node instanceof U.AST_Directive) return; if (!in_list && node instanceof U.AST_EmptyStatement) return; if (node instanceof U.AST_Label) return; if (node instanceof U.AST_LabelRef) return; - if (!in_list && node instanceof U.AST_SymbolDeclaration) return; if (node instanceof U.AST_Toplevel) return; var parent = tt.parent(); if (node instanceof U.AST_SymbolFunarg && parent instanceof U.AST_Accessor) return; + if (!in_list && parent.rest !== node && node instanceof U.AST_SymbolDeclaration) return; // ensure that the _permute prop is a number. // can not use `node.start._permute |= 0;` as it will erase fractional part. @@ -124,6 +123,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) // ignore lvalues if (parent instanceof U.AST_Assign && parent.left === node) return; + if (parent instanceof U.AST_DefaultValue && parent.name === node) return; if (parent instanceof U.AST_DestructuredKeyVal && parent.value === node) return; if (parent instanceof U.AST_Unary && parent.expression === node) switch (parent.operator) { case "++": @@ -229,6 +229,23 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) CHANGED = true; return node.name; } + else if (node instanceof U.AST_DestructuredArray) { + var expr = node.elements[0]; + if (expr && !(expr instanceof U.AST_Hole)) { + node.start._permute++; + CHANGED = true; + return expr; + } + } + else if (node instanceof U.AST_DestructuredObject) { + // first property's value + var expr = node.properties[0]; + if (expr) { + node.start._permute++; + CHANGED = true; + return expr.value; + } + } else if (node instanceof U.AST_Defun) { switch (((node.start._permute += step) * steps | 0) % 2) { case 0: @@ -443,15 +460,6 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) CHANGED = true; return List.skip; } - - // skip element/property from (destructured) array/object - if (parent instanceof U.AST_Array - || parent instanceof U.AST_Destructured - || parent instanceof U.AST_Object) { - node.start._permute++; - CHANGED = true; - return List.skip; - } } else if (parent.rest === node) { node.start._permute++; CHANGED = true; |