Skip to content

Commit

Permalink
fix: mark some known globals or their functions as impure
Browse files Browse the repository at this point in the history
  • Loading branch information
TrickyPi committed Apr 25, 2023
1 parent 56bf8aa commit d571ee2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/ast/nodes/shared/knownGlobals.ts
Expand Up @@ -94,7 +94,7 @@ const PC: GlobalDescription = {
const ARRAY_TYPE: GlobalDescription = {
__proto__: null,
[ValueProperties]: PURE,
from: PF,
from: O,
of: PF,
prototype: O
};
Expand Down Expand Up @@ -237,7 +237,7 @@ const knownGlobals: GlobalDescription = {
isFrozen: PF,
isSealed: PF,
keys: PF,
fromEntries: PF,
fromEntries: O,
entries: PF,
prototype: O
},
Expand All @@ -260,7 +260,7 @@ const knownGlobals: GlobalDescription = {
ReferenceError: PC,
Reflect: O,
RegExp: PC,
Set: PC,
Set: C,
SharedArrayBuffer: C,
String: {
__proto__: null,
Expand Down Expand Up @@ -300,8 +300,8 @@ const knownGlobals: GlobalDescription = {
unescape: PF,
URIError: PC,
valueOf: O,
WeakMap: PC,
WeakSet: PC,
WeakMap: C,
WeakSet: C,

// Additional globals shared by Node and Browser that are not strictly part of the language
clearInterval: C,
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/tree-shake-iterable/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'Retain functions that consume iterable'
};
29 changes: 29 additions & 0 deletions test/function/samples/tree-shake-iterable/main.js
@@ -0,0 +1,29 @@
let effects = [];

const iterable = {
[Symbol.iterator]() {
return {
next() {
effects.push('effect');
return { done: true };
}
};
}
};

new Map(iterable);
new Set(iterable);
new WeakMap(iterable);
new WeakSet(iterable);
Float32Array.from(iterable);
Float64Array.from(iterable);
Int16Array.from(iterable);
Int32Array.from(iterable);
Int8Array.from(iterable);
Uint16Array.from(iterable);
Uint32Array.from(iterable);
Uint8Array.from(iterable);
Uint8ClampedArray.from(iterable);
Object.fromEntries(iterable);

assert.equal(effects.length, 14);
4 changes: 0 additions & 4 deletions test/function/samples/tree-shake-map-constructor/_config.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/function/samples/tree-shake-map-constructor/main.js

This file was deleted.

0 comments on commit d571ee2

Please sign in to comment.