microsoft / microsoft/TypeScript

Compiler API: allow retrieving Symbols for anonymous function and classes

Offen
#55,433 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔍 Search Terms

"compiler api anonymous"
"anonymous getSymbolAtLocation"

✅ Viability Checklist
  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion

Today when working with AST tree it's convenient to retrieve Symbols of function/classes/variables and use them to represent program "entities". For named function and classes Symbol can be retrieved from a node using typeChecker.getSymbolAtLocation(node.name). Unfortunately for anonymous nodes there doesn't seem to be a way to get Symbol. Even though Symbol is present on the Node object but it's not in public API.

Additionally mentally it's easier to assume that all functions, classes and variables have Symbols.

This is similar to https://github.com/microsoft/TypeScript/issues/26511

Example using ts-ast-viewer:
image

📃 Motivating Example

No motivating example really. It's pretty niche compiler API improvement that makes working with Compiler more consistent and helps to avoid implementing workarounds.

💻 Use Cases
  1. What do you want to use this for?
    It's needed for proper implementation of TS indexer in kythe.io.

  2. What shortcomings exist with current approaches?
    Code indexing is built around having Symbols. Places where Symbol is possible to retrieve using public API (e.g. anonymous functions) require hacks or introducing custom symbol-like entity.

  3. What workarounds are you using in the meantime?
    Acessing internal Node.symbol property.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem öffentlichen Einstiegspunkt typeChecker.getSymbolAtLocation und vergleiche ihn mit der internen Node.symbol-Eigenschaft, die im Issue beschrieben wird. Prüfe das verwandte Issue #26511 und bestimme die erforderliche Form der öffentlichen API für anonyme Funktionen und Klassen; als abgeschlossen gilt die Aufgabe, wenn ihre Symbols abgerufen werden können, ohne auf interne Eigenschaften zuzugreifen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.