Skip to content

Commit 2352909

Browse files
authored
fix corner case in join_vars (#5746)
fixes #5745
1 parent 4e7744a commit 2352909

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

Diff for: lib/compress.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -10255,8 +10255,18 @@ Compressor.prototype.compress = function(node) {
1025510255
return all(this.definitions, function(defn) {
1025610256
return !defn.name.match_symbol(function(node) {
1025710257
if (!(node instanceof AST_SymbolDeclaration)) return false;
10258-
if (node.definition().first_decl !== node) return true;
10259-
return !safe_from_tdz(compressor, node);
10258+
var def = node.definition();
10259+
if (def.first_decl !== node) return true;
10260+
if (!safe_from_tdz(compressor, node)) return true;
10261+
var defn_scope = node.scope;
10262+
if (defn_scope instanceof AST_Scope) return false;
10263+
return !all(def.references, function(ref) {
10264+
var scope = ref.scope;
10265+
do {
10266+
if (scope === defn_scope) return true;
10267+
} while (scope = scope.parent_scope);
10268+
return false;
10269+
});
1026010270
}, true);
1026110271
});
1026210272
});

Diff for: test/compress/let.js

+63
Original file line numberDiff line numberDiff line change
@@ -2328,3 +2328,66 @@ issue_5741: {
23282328
expect_stdout: "PASS"
23292329
node_version: ">=4"
23302330
}
2331+
2332+
issue_5745_1: {
2333+
options = {
2334+
join_vars: true,
2335+
reduce_vars: true,
2336+
toplevel: true,
2337+
}
2338+
input: {
2339+
"use strict";
2340+
{
2341+
let f = function() {
2342+
return f && "PASS";
2343+
};
2344+
var a = f();
2345+
}
2346+
a;
2347+
console.log(a);
2348+
}
2349+
expect: {
2350+
"use strict";
2351+
{
2352+
let f = function() {
2353+
return f && "PASS";
2354+
};
2355+
var a = f();
2356+
}
2357+
a;
2358+
console.log(a);
2359+
}
2360+
expect_stdout: "PASS"
2361+
node_version: ">=4"
2362+
}
2363+
2364+
issue_5745_2: {
2365+
options = {
2366+
join_vars: true,
2367+
reduce_vars: true,
2368+
toplevel: true,
2369+
}
2370+
input: {
2371+
"use strict";
2372+
{
2373+
let f = function() {
2374+
return f && "PASS";
2375+
};
2376+
var a = f();
2377+
a;
2378+
console.log(a);
2379+
}
2380+
}
2381+
expect: {
2382+
"use strict";
2383+
{
2384+
let f = function() {
2385+
return f && "PASS";
2386+
}, a = f();
2387+
a;
2388+
console.log(a);
2389+
}
2390+
}
2391+
expect_stdout: "PASS"
2392+
node_version: ">=4"
2393+
}

Diff for: tools/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function infer_options(options) {
100100
exports.default_options = function() {
101101
var defs = infer_options({ 0: 0 });
102102
Object.keys(defs).forEach(function(component) {
103-
var options = {};
103+
var options = { module: false };
104104
options[component] = { 0: 0 };
105105
if (options = infer_options(options)) {
106106
defs[component] = options;

0 commit comments

Comments
 (0)