Skip to content

Commit

Permalink
take into account the evaluated size when inlining. Closes #1454
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Mar 13, 2024
1 parent 6f269e4 commit 03660f8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/compress/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export function inline_into_symbolref(self, compressor) {
let overhead = 0;
if (compressor.option("unused") && !compressor.exposed(def)) {
overhead =
(name_length + 2 + replace_size) /
(name_length + 2 + fixed.size(compressor)) /
(def.references.length - def.assignments);
}

Expand Down
45 changes: 44 additions & 1 deletion test/compress/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ do_not_repeat_when_variable_larger_than_inlined_node: {
options = {
toplevel: true,
reduce_vars: true,
inline: true
inline: true,
unused: true,
}

mangle = {
Expand Down Expand Up @@ -523,6 +524,48 @@ do_not_repeat_when_variable_larger_than_inlined_node: {
}
}

do_not_repeat_when_variable_larger_than_inlined_node_2: {
options = {
toplevel: true,
reduce_vars: true,
evaluate: true,
unused: true,
inline: true
}

input: {
const a=0.1, b=0.2, c=a+b;
console.log(c);
}

expect: {
const c=0.1+0.2;
console.log(c);
}
}

do_not_repeat_when_variable_larger_than_inlined_node_3: {
options = {
toplevel: true,
reduce_vars: true,
evaluate: true,
unused: true,
inline: true
}

input: {
const a = "string";
const b = "string";
const c = a + b;
console.log(c, c);
}

expect: {
const c = "stringstring";
console.log(c, c);
}
}

inline_using_correct_arguments: {
options = {
reduce_vars: true,
Expand Down

0 comments on commit 03660f8

Please sign in to comment.