Skip to content

Commit

Permalink
avoid a class being inlined twice when identity can be compared. (close
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Oct 5, 2022
1 parent 13fe8ca commit 089e32a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/compress/inline.js
Expand Up @@ -210,7 +210,7 @@ export function inline_into_symbolref(self, compressor) {
}
}

if (single_use && fixed instanceof AST_Lambda) {
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
single_use =
def.scope === self.scope
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
Expand Down
4 changes: 2 additions & 2 deletions lib/parse.js
Expand Up @@ -2801,14 +2801,14 @@ function parse($TEXT, options) {
var end = prev();

name = name || new type({
name: "*",
start: start,
name: "*",
end: end,
});

foreign_name = new foreign_type({
name: "*",
start: start,
name: "*",
end: end,
});

Expand Down
34 changes: 34 additions & 0 deletions test/compress/inline.js
Expand Up @@ -238,6 +238,40 @@ inline_into_scope_conflict_enclosed_2: {
]
}

issue_1267_inline_breaks_compare_identity: {
options = {
toplevel: true
}
input: {
class ClassA {
}
class ClassB {
MyA = ClassA;
};

console.log(new ClassB().MyA == new ClassB().MyA)
}
expect_stdout: ["true"]
}

issue_1267_inline_breaks_compare_identity_2: {
options = {
toplevel: true
}
input: {
class ClassA {
}
const objA = {
prop: ClassA
}
const objB = {
prop: ClassA
}

console.log(objA.prop === objB.prop)
}
expect_stdout: ["true"]
}

noinline_annotation: {
options = {
Expand Down

0 comments on commit 089e32a

Please sign in to comment.