Skip to content

Commit c80e2fa

Browse files
committed
Fix issue in property mangling
1 parent 0926f07 commit c80e2fa

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

rollup.config.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const isDev = (build === "development");
1717
*/
1818
function precache(cache)
1919
{
20-
const bans = [ "x", "y", "id", "on", "add", "get", "set", "gap", "pop", "min", "max", "top", "row", "for" ];
20+
const bans = new Set(["x", "y", "id", "on", "add", "get", "set", "gap", "pop", "min", "max", "top", "row", "for"]);
2121
const leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
2222
const all = (leading+"0123456789");
2323
let mangleId = 0;
@@ -32,17 +32,23 @@ function precache(cache)
3232
result += all[index % all.length];
3333
index = Math.floor(index / all.length) - 1;
3434
}
35-
return bans.includes(result) ? getName() : result;
35+
return bans.has(result) ? getName() : result;
3636
}
3737

3838
return {
3939
name: "Prepare property mangle cache",
40-
renderChunk(code)
40+
renderChunk(code, chunk)
4141
{
42-
[...code.matchAll(/(?:\.prototype|this)\.(_\w+)\s*=/g)]
43-
.map(m => `$${m[1]}`)
44-
.filter(m => !(m in cache))
45-
.forEach(m => cache[m] = getName());
42+
for (const [match,] of code.matchAll(/\b_[a-z0-9$]+\b/gi))
43+
{
44+
const key = `$${match}`; // terser requires $-prefix
45+
if (!(key in cache))
46+
{
47+
const token = getName();
48+
cache[key] = token;
49+
this.info(`${chunk.fileName}: ${match} -> ${token}`);
50+
}
51+
}
4652
}
4753
};
4854
}

0 commit comments

Comments
 (0)