microsoft / microsoft/TypeScript

Compiler API: allow retrieving Symbols for anonymous function and classes

Abierto
#55,433 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

In Discussion Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el punto de entrada público typeChecker.getSymbolAtLocation y compáralo con la propiedad interna Node.symbol descrita en el issue. Revisa el issue relacionado #26511 y determina la forma de la API pública necesaria para funciones y clases anónimas; se considera terminado cuando sus Symbols se pueden recuperar sin acceder a propiedades internas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.