microsoft / microsoft/TypeScript

Compiler API: allow retrieving Symbols for anonymous function and classes

Aperta
#55,433 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔍 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso pubblico typeChecker.getSymbolAtLocation e confrontalo con la proprietà interna Node.symbol descritta nell’issue. Esamina l’issue correlata #26511 e determina la forma dell’API pubblica necessaria per le funzioni e le classi anonime; il lavoro è completato quando è possibile recuperare i loro Symbols senza accedere a proprietà interne.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.