Skip to content

Commit

Permalink
enhance merge_vars (#5308)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jan 21, 2022
1 parent e24b255 commit 866cd4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions lib/compress.js
Expand Up @@ -6245,8 +6245,10 @@ Compressor.prototype.compress = function(node) {
|| !mergeable(head_refs, tail_refs)
|| (head_refs.start.loop || !same_scope(def)) && !mergeable(tail_refs, head_refs)
|| compressor.option("webkit") && is_funarg(def) !== is_funarg(head.definition)
|| !safe_to_rename(head_refs, def)
|| !safe_to_rename(references[def.id], head.definition)) {
|| head.definition.const_redefs
|| !all(head_refs, function(sym) {
return sym.scope.find_variable(def.name) === def;
})) {
skipped.push(head);
continue;
}
Expand Down Expand Up @@ -6348,12 +6350,6 @@ Compressor.prototype.compress = function(node) {
function mergeable(head, tail) {
return must_visit(head.start, head.end) || must_visit(head.start, tail.start);
}

function safe_to_rename(refs, def) {
return all(refs, function(sym) {
return sym.scope.find_variable(def.name) === def;
});
}
});

function fill_holes(orig, elements) {
Expand Down
4 changes: 2 additions & 2 deletions test/compress/let.js
Expand Up @@ -270,8 +270,8 @@ merge_vars_3: {
var b = console;
console.log(typeof b);
}
var a = 1;
console.log(typeof a);
var b = 1;
console.log(typeof b);
}
expect_stdout: [
"object",
Expand Down

0 comments on commit 866cd4a

Please sign in to comment.