Skip to content

Commit edf1bf1

Browse files
authored
enhance varify (#5658)
1 parent 88dfc49 commit edf1bf1

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Diff for: lib/compress.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -10120,9 +10120,11 @@ Compressor.prototype.compress = function(node) {
1012010120
}
1012110121

1012210122
function can_varify(compressor, sym) {
10123-
if (!sym.fixed_value()) return false;
1012410123
var def = sym.definition();
10125-
return is_safe_lexical(def) && same_scope(def) && !may_overlap(compressor, def);
10124+
return (def.fixed || def.fixed === 0)
10125+
&& is_safe_lexical(def)
10126+
&& same_scope(def)
10127+
&& !may_overlap(compressor, def);
1012610128
}
1012710129

1012810130
function varify(self, compressor) {

Diff for: test/compress/varify.js

+37
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,43 @@ scope_adjustment_let: {
194194
node_version: ">=4"
195195
}
196196

197+
escaped_const: {
198+
options = {
199+
reduce_vars: true,
200+
toplevel: true,
201+
varify: true,
202+
}
203+
input: {
204+
const log = console.log;
205+
log("PASS");
206+
}
207+
expect: {
208+
var log = console.log;
209+
log("PASS");
210+
}
211+
expect_stdout: "PASS"
212+
}
213+
214+
escaped_let: {
215+
options = {
216+
reduce_vars: true,
217+
toplevel: true,
218+
varify: true,
219+
}
220+
input: {
221+
"use strict";
222+
let log = console.log;
223+
log("PASS");
224+
}
225+
expect: {
226+
"use strict";
227+
var log = console.log;
228+
log("PASS");
229+
}
230+
expect_stdout: "PASS"
231+
node_version: ">=4"
232+
}
233+
197234
issue_4191_const: {
198235
options = {
199236
functions: true,

0 commit comments

Comments
 (0)