fix corner case in join_vars (#5746)

fixes #5745
This commit is contained in:
Alex Lam S.L
2022-11-23 15:49:30 +02:00
committed by GitHub
parent 4e7744af2d
commit 2352909c3d
3 changed files with 76 additions and 3 deletions

View File

@@ -10255,8 +10255,18 @@ Compressor.prototype.compress = function(node) {
return all(this.definitions, function(defn) {
return !defn.name.match_symbol(function(node) {
if (!(node instanceof AST_SymbolDeclaration)) return false;
if (node.definition().first_decl !== node) return true;
return !safe_from_tdz(compressor, node);
var def = node.definition();
if (def.first_decl !== node) return true;
if (!safe_from_tdz(compressor, node)) return true;
var defn_scope = node.scope;
if (defn_scope instanceof AST_Scope) return false;
return !all(def.references, function(ref) {
var scope = ref.scope;
do {
if (scope === defn_scope) return true;
} while (scope = scope.parent_scope);
return false;
});
}, true);
});
});

View File

@@ -2328,3 +2328,66 @@ issue_5741: {
expect_stdout: "PASS"
node_version: ">=4"
}
issue_5745_1: {
options = {
join_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
"use strict";
{
let f = function() {
return f && "PASS";
};
var a = f();
}
a;
console.log(a);
}
expect: {
"use strict";
{
let f = function() {
return f && "PASS";
};
var a = f();
}
a;
console.log(a);
}
expect_stdout: "PASS"
node_version: ">=4"
}
issue_5745_2: {
options = {
join_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
"use strict";
{
let f = function() {
return f && "PASS";
};
var a = f();
a;
console.log(a);
}
}
expect: {
"use strict";
{
let f = function() {
return f && "PASS";
}, a = f();
a;
console.log(a);
}
}
expect_stdout: "PASS"
node_version: ">=4"
}

View File

@@ -100,7 +100,7 @@ function infer_options(options) {
exports.default_options = function() {
var defs = infer_options({ 0: 0 });
Object.keys(defs).forEach(function(component) {
var options = {};
var options = { module: false };
options[component] = { 0: 0 };
if (options = infer_options(options)) {
defs[component] = options;