diff --git a/src/ast/nodes/shared/knownGlobals.ts b/src/ast/nodes/shared/knownGlobals.ts index 34b21ca9eb4..a6c7a6eaa10 100644 --- a/src/ast/nodes/shared/knownGlobals.ts +++ b/src/ast/nodes/shared/knownGlobals.ts @@ -94,7 +94,7 @@ const PC: GlobalDescription = { const ARRAY_TYPE: GlobalDescription = { __proto__: null, [ValueProperties]: PURE, - from: PF, + from: O, of: PF, prototype: O }; @@ -237,7 +237,7 @@ const knownGlobals: GlobalDescription = { isFrozen: PF, isSealed: PF, keys: PF, - fromEntries: PF, + fromEntries: O, entries: PF, prototype: O }, @@ -260,7 +260,7 @@ const knownGlobals: GlobalDescription = { ReferenceError: PC, Reflect: O, RegExp: PC, - Set: PC, + Set: C, SharedArrayBuffer: C, String: { __proto__: null, @@ -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, diff --git a/test/function/samples/tree-shake-iterator/_config.js b/test/function/samples/tree-shake-iterator/_config.js new file mode 100644 index 00000000000..ec40495a198 --- /dev/null +++ b/test/function/samples/tree-shake-iterator/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'Retain functions that consume iterators' +}; diff --git a/test/function/samples/tree-shake-iterator/main.js b/test/function/samples/tree-shake-iterator/main.js new file mode 100644 index 00000000000..6403e30f702 --- /dev/null +++ b/test/function/samples/tree-shake-iterator/main.js @@ -0,0 +1,29 @@ +let effects = []; + +const iterator = { + [Symbol.iterator]() { + return { + next() { + effects.push('effect'); + return { done: true }; + } + }; + } +}; + +new Map(iterator); +new Set(iterator); +new WeakMap(iterator); +new WeakSet(iterator); +Float32Array.from(iterator); +Float64Array.from(iterator); +Int16Array.from(iterator); +Int32Array.from(iterator); +Int8Array.from(iterator); +Uint16Array.from(iterator); +Uint32Array.from(iterator); +Uint8Array.from(iterator); +Uint8ClampedArray.from(iterator); +Object.fromEntries(iterator); + +assert.equal(effects.length, 14); diff --git a/test/function/samples/tree-shake-map-constructor/_config.js b/test/function/samples/tree-shake-map-constructor/_config.js deleted file mode 100644 index 1de38a64953..00000000000 --- a/test/function/samples/tree-shake-map-constructor/_config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - description: - 'Retain the Map constructor is called with the new keyword if the accepted param has side effects' -}; diff --git a/test/function/samples/tree-shake-map-constructor/main.js b/test/function/samples/tree-shake-map-constructor/main.js deleted file mode 100644 index fe883187019..00000000000 --- a/test/function/samples/tree-shake-map-constructor/main.js +++ /dev/null @@ -1,14 +0,0 @@ -let effect = false; - -new Map({ - [Symbol.iterator]() { - return { - next() { - effect = true; - return { done: true }; - } - }; - } -}); - -assert.ok(effect);