Skip to content

Commit

Permalink
fix corner case in join_vars (#5746)
Browse files Browse the repository at this point in the history
fixes #5745
  • Loading branch information
alexlamsl authored Nov 23, 2022
1 parent 4e7744a commit 2352909
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
63 changes: 63 additions & 0 deletions test/compress/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion tools/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2352909

Please sign in to comment.