microsoft / microsoft/TypeScript
Named Tuple elements should allow reserved words as their names
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
tuple elements label reserved word
named tuple elements
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common "Bugs" That Aren't Bugs"
⏯ Playground Link
Playground link with relevant code
💻 Code
type x = [if: any]
// but some keywords are allowed, e.g.
type y = [void: any]
🙁 Actual behavior
Unused label.
'any' only refers to a type, but is being used as a value here.
Type expected.
'(' expected.
Unexpected keyword or identifier.
Declaration or statement expected.
🙂 Expected behavior
No errors. As a label it should allow any identifiers, including reserved words.
👩💻 Possible solution
Although parseTupleElementNameOrTupleElementType allows any identifier as its name:
before it is invoked, the isListElement requires a tuple member start a type:
This is no longer true after we support named tuple member after 4.0, which should start with any valid identifiers / keywords. Because isListElement returns false, the parser does not parse them as tuple elements, which results to confusing parsing errors.
We can create a new ParsingContext for named tuple members, and returns token() === SyntaxKind.CommaToken || tokenIsIdentifierOrKeyword(token()) in isListElement.
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 in src/compiler/parser.ts, su isListElement e parseTupleElementNameOrTupleElementType, usando il codice Playground collegato come riproduzione. Traccia il modo in cui vengono classificati i membri di tupla denominati che iniziano con una parola riservata, quindi aggiungi un test di regressione che copra l'esempio e verifica che non produca errori di parsing.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 50/100