fix corner case in collapse_vars (#4217)

fixes #4216
This commit is contained in:
Alex Lam S.L
2020-10-14 00:18:26 +01:00
committed by GitHub
parent b7b8435721
commit 9f8106e1d8
3 changed files with 25 additions and 4 deletions

View File

@@ -1501,9 +1501,9 @@ merge(Compressor.prototype, {
// Skip (non-executed) functions // Skip (non-executed) functions
if (node instanceof AST_Scope) return node; if (node instanceof AST_Scope) return node;
// Stop upon collision with block-scoped variables // Stop upon collision with block-scoped variables
if (node.variables && !node.variables.all(function(def) { if (!(node.variables && node.variables.all(function(def) {
return !lvalues.has(def.name); return !lvalues.has(def.name);
})) { }))) {
abort = true; abort = true;
return node; return node;
} }

View File

@@ -1385,8 +1385,6 @@ function OutputStream(options) {
make_block(stat, output); make_block(stat, output);
} else if (!stat || stat instanceof AST_EmptyStatement) { } else if (!stat || stat instanceof AST_EmptyStatement) {
output.force_semicolon(); output.force_semicolon();
} else if (stat instanceof AST_Const) {
make_block(stat, output);
} else { } else {
stat.print(output); stat.print(output);
} }

View File

@@ -1009,3 +1009,26 @@ issue_4212_2: {
} }
expect_stdout: true expect_stdout: true
} }
issue_4216: {
options = {
collapse_vars: true,
conditionals: true,
dead_code: true,
evaluate: true,
}
input: {
if (a = 0) {
const a = 0;
}
console.log(typeof a);
}
expect: {
a = 0;
{
const a = void 0;
}
console.log(typeof a);
}
expect_stdout: true
}