Skip to content

Commit b54dfa0

Browse files
fix(minify): keep a new Set or new Map a with or eval may rebind
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 772c00c commit b54dfa0

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22567,12 +22567,14 @@ const installImprove = (modules) => {
2256722567
* What a `Set` or `Map` built from an array literal holds, which it reads
2256822568
* through no code of the program's: a `Map`'s entries each an array literal.
2256922569
* @param {Node} self a `new`
22570+
* @param {Compressor} compressor the compressor
2257022571
* @returns {Node[] | undefined} the values it holds, if it is one
2257122572
*/
22572-
const collectionEntries = (self) => {
22573+
const collectionEntries = (self, compressor) => {
2257322574
if (
2257422575
!improvements.enabled ||
2257522576
!isBuiltInGlobal(self.callee) ||
22577+
!readsUnassignedGlobal(self.callee, compressor) ||
2257622578
(self.callee.name !== "Set" && self.callee.name !== "Map") ||
2257722579
self.arguments.length > 1
2257822580
) {
@@ -22604,7 +22606,7 @@ const installImprove = (modules) => {
2260422606
/** @type {(self: Node, compressor: Compressor) => Node | null} */ original
2260522607
) =>
2260622608
(/** @type {Node} */ self, /** @type {Compressor} */ compressor) => {
22607-
const entries = collectionEntries(self);
22609+
const entries = collectionEntries(self, compressor);
2260822610
if (entries !== undefined) {
2260922611
const left = entries
2261022612
.map((entry) => A.dropSideEffectFree(entry, compressor))

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,8 @@ const IMPROVED_CASES = [
20792079
/** @type {[string, string][]} */
20802080
const KEPT_CASES = [
20812081
["a computed key of a loop head's pattern, which the body writes", 'function f(o) { let k = 1; for ({ [k]: x } of o) { console.log(x); k = 2; } } var x; f([{ 1: "a", 2: "b" }, { 1: "c", 2: "d" }]);'],
2082+
["a `Set` built from an array literal where a direct `eval` may rebind `Set`", 'function f() { eval("var Set = function () { console.log(1); }"); new Set([1]); } f();'],
2083+
["a `Set` built from an array literal where a `with` object may rebind `Set`", "with ({ Set: function () { console.log(1); } }) { new Set([1]); }"],
20822084
["an element of an array literal written through as a property of a destructuring assignment", "var a = 1, value = { x: 5 }; ({ x: [a][0] } = value); console.log(a);"],
20832085
["a direct `eval` kept out of a `for…in` head whose `let` it may read in its dead zone", "function f(o) { let x = 1; eval('console.log(x)'); for (let x in o) console.log(x); } f({ a: 1 });"],
20842086
["an element of an array literal called, read as a place, or beside one with effects", "function f(o, g) { [o][0] = 1; [o][0]++; delete [o][0]; return [[o][0](), [g(), o][1], [, o][0]]; } console.log(f(function () { return this.length; }, () => 1));"],

0 commit comments

Comments
 (0)