Skip to content

Commit

Permalink
enhance varify (#5658)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Sep 10, 2022
1 parent 88dfc49 commit edf1bf1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10120,9 +10120,11 @@ Compressor.prototype.compress = function(node) {
}

function can_varify(compressor, sym) {
if (!sym.fixed_value()) return false;
var def = sym.definition();
return is_safe_lexical(def) && same_scope(def) && !may_overlap(compressor, def);
return (def.fixed || def.fixed === 0)
&& is_safe_lexical(def)
&& same_scope(def)
&& !may_overlap(compressor, def);
}

function varify(self, compressor) {
Expand Down
37 changes: 37 additions & 0 deletions test/compress/varify.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,43 @@ scope_adjustment_let: {
node_version: ">=4"
}

escaped_const: {
options = {
reduce_vars: true,
toplevel: true,
varify: true,
}
input: {
const log = console.log;
log("PASS");
}
expect: {
var log = console.log;
log("PASS");
}
expect_stdout: "PASS"
}

escaped_let: {
options = {
reduce_vars: true,
toplevel: true,
varify: true,
}
input: {
"use strict";
let log = console.log;
log("PASS");
}
expect: {
"use strict";
var log = console.log;
log("PASS");
}
expect_stdout: "PASS"
node_version: ">=4"
}

issue_4191_const: {
options = {
functions: true,
Expand Down

0 comments on commit edf1bf1

Please sign in to comment.