microsoft / microsoft/TypeScript
Compiler API: allow retrieving Symbols for anonymous function and classes
Nessuno ha ancora preso questa issue.
- 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:
📃 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
-
What do you want to use this for?
It's needed for proper implementation of TS indexer in kythe.io. -
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. -
What workarounds are you using in the meantime?
Acessing internalNode.symbolproperty.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- 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