Skip to content

[RFC] nameRegistry bug? #2071

@cieplypolar

Description

@cieplypolar

I am not sure if the condition in makeValid method is sufficient.

makeValid(primer: string): string {
  if (isValidIdentifier(primer) && !this.#usedNames.has(primer)) {
    this.usedFunctionScopeNames?.add(primer);
    return primer;
  }
  return this.makeUnique(primer, false);
}

In the resolution of a forOf loop, I need to check if an identifier is free by calling ctx.getById method

let index = 'i'; // it will be valid name, no need to call this.ctx.makeNameValid
  while (ctx.getById(index) !== null) {
    index += 'i';
  }

If we were checking the function scope in the makeValid method, the while loop could be replaced with a single call to makeNameValid

Please tell me if I am correct.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions