Skip to content

Commit

Permalink
Remove recursion in mangled var name transform [refactor]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 21, 2023
1 parent c27b748 commit b1e1a47
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/serialize/varNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ class MangledVarNameFactory extends VarNameFactory {
}

transform(originalName, isPrivate) {
let remainder = this.counter;
let name = '';
while (true) { // eslint-disable-line no-constant-condition
const code = remainder % NUM_CHARS;

name = `${CHARS[code]}${name}`;
let name;
do {
let remainder = this.counter++;
name = '';
while (true) { // eslint-disable-line no-constant-condition
const code = remainder % NUM_CHARS;

remainder = (remainder - code) / NUM_CHARS - 1;
if (remainder === -1) break;
}
name = `${CHARS[code]}${name}`;

this.counter++;
remainder = (remainder - code) / NUM_CHARS - 1;
if (remainder === -1) break;
}

if (isPrivate) name = `${PRIVATE_PREFIX}${name}`;
if (this.isReserved(name)) return this.transform(originalName, isPrivate);
if (isPrivate) name = `${PRIVATE_PREFIX}${name}`;
} while (this.isReserved(name));

return name;
}
Expand Down

0 comments on commit b1e1a47

Please sign in to comment.