Skip to content

Commit

Permalink
Merge branch 'master' into feature/codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Mar 14, 2024
2 parents 6076856 + 1cdfba8 commit 96ce02a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lib/compress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3924,21 +3924,23 @@ function lift_key(self, compressor) {
if (!(self.key instanceof AST_Constant)) return self;
// allow certain acceptable props as not all AST_Constants are true constants
if (self.key instanceof AST_String || self.key instanceof AST_Number) {
if (self.key.value === "__proto__") return self;
if (self.key.value == "constructor"
const key = self.key.value.toString();

if (key === "__proto__") return self;
if (key == "constructor"
&& compressor.parent() instanceof AST_Class) return self;
if (self instanceof AST_ObjectKeyVal) {
self.quote = self.key.quote;
self.key = self.key.value;
self.key = key;
} else if (self instanceof AST_ClassProperty) {
self.quote = self.key.quote;
self.key = make_node(AST_SymbolClassProperty, self.key, {
name: self.key.value
name: key,
});
} else {
self.quote = self.key.quote;
self.key = make_node(AST_SymbolMethod, self.key, {
name: self.key.value
name: key,
});
}
}
Expand Down
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
14 changes: 14 additions & 0 deletions test/compress/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ convert_computed_props_to_regular_ones: {
]
}

convert_computed_props_and_keep_quotes: {
options = {
booleans: true,
computed_props: true,
evaluate: true,
}
format = { quote_keys: true }
input: {
console.log({ [11]: 22, 33: 44 });
}
expect_exact: 'console.log({"11":22,"33":44});'
expect_stdout: "{ '11': 22, '33': 44 }"
}

computed_property_names_evaluated_1: {
options = {
evaluate: true
Expand Down

0 comments on commit 96ce02a

Please sign in to comment.