sucrase
Version:
Super-fast alternative to Babel for when you can target modern JS runtimes
32 lines (31 loc) • 827 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class NameManager {
constructor(tokens) {
this.tokens = tokens;
this.usedNames = new Set();
}
preprocessNames() {
for (const token of this.tokens.tokens) {
if (token.type.label === "name") {
this.usedNames.add(token.value);
}
}
}
claimFreeName(name) {
const newName = this.findFreeName(name);
this.usedNames.add(newName);
return newName;
}
findFreeName(name) {
if (!this.usedNames.has(name)) {
return name;
}
let suffixNum = 2;
while (this.usedNames.has(name + suffixNum)) {
suffixNum++;
}
return name + suffixNum;
}
}
exports.default = NameManager;