From 736ecba509eab5698ce875fe76e9b595535fe282 Mon Sep 17 00:00:00 2001 From: TrickyPi <530257315@qq.com> Date: Sun, 23 Apr 2023 20:03:38 +0800 Subject: [PATCH] fix: mark Map is impure --- src/ast/nodes/shared/knownGlobals.ts | 2 +- .../samples/tree-shake-map-constructor/_config.js | 4 ++++ .../samples/tree-shake-map-constructor/main.js | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/tree-shake-map-constructor/_config.js create mode 100644 test/function/samples/tree-shake-map-constructor/main.js diff --git a/src/ast/nodes/shared/knownGlobals.ts b/src/ast/nodes/shared/knownGlobals.ts index 21d4e751af2..34b21ca9eb4 100644 --- a/src/ast/nodes/shared/knownGlobals.ts +++ b/src/ast/nodes/shared/knownGlobals.ts @@ -164,7 +164,7 @@ const knownGlobals: GlobalDescription = { isNaN: PF, isPrototypeOf: O, JSON: O, - Map: PC, + Map: C, Math: { __proto__: null, [ValueProperties]: IMPURE, diff --git a/test/function/samples/tree-shake-map-constructor/_config.js b/test/function/samples/tree-shake-map-constructor/_config.js new file mode 100644 index 00000000000..1de38a64953 --- /dev/null +++ b/test/function/samples/tree-shake-map-constructor/_config.js @@ -0,0 +1,4 @@ +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 new file mode 100644 index 00000000000..f088c82c32f --- /dev/null +++ b/test/function/samples/tree-shake-map-constructor/main.js @@ -0,0 +1,12 @@ +assert.ok( + new Map({ + [Symbol.iterator]() { + return { + next() { + console.log('side effect'); + return { done: true }; + } + }; + } + }) +);