Skip to content

[api] Add back missing: factory.createUniqueName / createTempVariable (generated identifiers) #64860

Open

Description

@Smrtnyk

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

typescript/ast/factory has no counterpart to these classic APIs:

  • ts.factory.createUniqueName(text, flags?)
  • ts.factory.createTempVariable(...) / createLoopVariable(...)
  • ts.factory.getGeneratedNameForNode(node)

In 6.0, the printer resolved these at print time to names that don't collide with any identifier in the file (callId_1, callId_2, …). In 7.1, the only option is createIdentifier with a hand-picked name, and the caller has to check for collisions.

Our use case: a build-time transformer wraps function bodies in var callId_1; try { callId_1 = enterFunction(...); ... } finally { leaveFunction(callId_1); }, and return x.apply(...) in var tempApplyValue_1 = x.apply(...); return tempApplyValue_1;. It needs fresh local names in arbitrary user code.

Related: #64429 (also asks for emit-time metadata on synthesized nodes).

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions