Skip to content

Commit

Permalink
Only consider Object.freeze a side effect if the argument is used (#4720
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lukastaegert committed Nov 22, 2022
1 parent 9a74163 commit 780e342
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ast/nodes/shared/knownGlobals.ts
Expand Up @@ -214,6 +214,7 @@ const knownGlobals: GlobalDescription = {
// deoptimizes everything anyway
defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
freeze: MUTATES_ARG_WITHOUT_ACCESSOR,
getOwnPropertyDescriptor: PF,
getOwnPropertyNames: PF,
getOwnPropertySymbols: PF,
Expand Down
3 changes: 1 addition & 2 deletions test/form/samples/big-int/_config.js
@@ -1,4 +1,3 @@
module.exports = {
description: 'supports bigint via acorn plugin',
options: {}
description: 'supports bigint via acorn plugin'
};
3 changes: 3 additions & 0 deletions test/form/samples/object-freeze-effects/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'Only treats Object.freeze as a side effect if the argument is used'
};
6 changes: 6 additions & 0 deletions test/form/samples/object-freeze-effects/_expected.js
@@ -0,0 +1,6 @@
const b = Object.freeze({ foo: 'bar' });
console.log(b);

const c = { foo: 'bar' };
Object.freeze(c); // retained
console.log(c);
11 changes: 11 additions & 0 deletions test/form/samples/object-freeze-effects/main.js
@@ -0,0 +1,11 @@
Object.freeze({ foo: 'bar' }); // removed

const a = { foo: 'bar' }; // removed
Object.freeze(a); // removed

const b = Object.freeze({ foo: 'bar' });
console.log(b);

const c = { foo: 'bar' };
Object.freeze(c); // retained
console.log(c);

0 comments on commit 780e342

Please sign in to comment.