microsoft / microsoft/TypeScript

API Suggestion: Add function for getting syntax kind name from syntax kind

Aperta
#40,090 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Search Terms

function get SyntaxKind name

Suggestion

A common mistake people will do when using the compiler api is getting the syntax kind name by doing ts.SyntaxKind[kind], where kind is the syntax kind number value (ex. I had this mistake in my presentation at tsconf in ts-ast-viewer, though that's been fixed for a couple years now, I've still seen people do it occasionally).

This is wrong because it will give the last entry in the enum, which could be an alias like LastTypeNode instead of ImportType.

It would be nice to...

  1. Add a function... maybe getSyntaxKindName(kind: SyntaxKind): string... that gets the syntax kind name from the provided syntax kind value.
  2. Add a doc comment above SyntaxKind to suggest using getSyntaxKindName to get the name.

Examples

ts.getSyntaxKindName(ts.SyntaxKind.ImportType); // "ImportType"

Checklist

My suggestion meets these guidelines:

  • 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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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 individuando la dichiarazione esportata di SyntaxKind e i punti di ingresso della compiler API che espongono helper relativi a enum. Traccia il modo in cui vengono rappresentati i valori di enum con alias, quindi aggiungi la coverage per l’esempio ImportType e la documentazione richiesta di SyntaxKind; il lavoro è completato quando l’helper pubblico restituisce il nome previsto invece di un alias.

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

Valutazione

Stack tecnologico
typescript
Ambito
api, compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.