aboutsummaryrefslogtreecommitdiff
path: root/test/reduce.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-13 13:15:11 +0000
committerGitHub <noreply@github.com>2021-02-13 21:15:11 +0800
commit94e8944f677f624d8ab4ae2b8731e87244f9476e (patch)
treefe98fd1093ee1cb82f69c4cfafa0ac9d80f2e81a /test/reduce.js
parent83197ffdb3c9055b5699674e111d2dee390d5560 (diff)
downloadtracifyjs-94e8944f677f624d8ab4ae2b8731e87244f9476e.tar.gz
tracifyjs-94e8944f677f624d8ab4ae2b8731e87244f9476e.zip
avoid false positive in `--reduce-test` (#4648)
Diffstat (limited to 'test/reduce.js')
-rw-r--r--test/reduce.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/test/reduce.js b/test/reduce.js
index d5758ccc..4d628aa2 100644
--- a/test/reduce.js
+++ b/test/reduce.js
@@ -300,7 +300,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
node.start._permute += step;
if (expr && (expr !== node.body || !has_loopcontrol(expr, node, parent))) {
CHANGED = true;
- return to_statement(expr);
+ return to_statement_init(expr);
}
}
else if (node instanceof U.AST_ForEnumeration) {
@@ -322,7 +322,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
node.start._permute += step;
if (expr) {
CHANGED = true;
- return to_statement(expr);
+ return to_statement_init(expr);
}
}
else if (node instanceof U.AST_If) {
@@ -695,6 +695,13 @@ function to_statement(node) {
});
}
+function to_statement_init(node) {
+ return node instanceof U.AST_Const || node instanceof U.AST_Let ? new U.AST_BlockStatement({
+ body: [ node ],
+ start: {},
+ }) : to_statement(node);;
+}
+
function wrap_with_console_log(node) {
// wrap with console.log()
return new U.AST_Call({