Skip to content

Commit

Permalink
Fix #35: property mangler using properties that already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Basssiiie committed Apr 22, 2024
1 parent 1841aab commit 6455359
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,32 @@ const isDev = (build === "development");
*/
function precache(cache)
{
const bans = [ "x", "y", "id", "on", "add", "get", "set", "gap", "pop", "min", "max", "top" ];
const leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
const all = (leading+"0123456789");
let mangleId = 0;

function getName(index)
function getName()
{
let index = mangleId++;
let result = leading[index % leading.length];
index = Math.floor(index / leading.length) - 1;
while (index >= 0)
{
result += all[index % all.length];
index = Math.floor(index / all.length) - 1;
}
return result;
return bans.includes(result) ? getName() : result;
}

return {
name: "Prepare property mangle cache",
renderChunk(code)
{
[...code.matchAll(/(?:\.prototype|this)\.(_[\w\d]+)\s*=/g)]
[...code.matchAll(/(?:\.prototype|this)\.(_\w+)\s*=/g)]
.map(m => `$${m[1]}`)
.filter(m => !(m in cache))
.forEach(m => cache[m] = getName(mangleId++));
.forEach(m => cache[m] = getName());
}
};
}
Expand Down

0 comments on commit 6455359

Please sign in to comment.