From 94e8944f677f624d8ab4ae2b8731e87244f9476e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 13 Feb 2021 13:15:11 +0000 Subject: avoid false positive in `--reduce-test` (#4648) --- test/reduce.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'test/reduce.js') 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({ -- cgit v1.2.3