microsoft / microsoft/TypeScript
Tolerate invalid identifier syntax errors in list parsing
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Search Terms
parser variable name list identifiers
Suggestion
Instead of aborting parsing a list when an invalid identifier is reached, have the parser emit a syntax error but otherwise parsing. In other words: it should successfully parse lists such as variable declarations as if the identifiers were valid, with the one difference of emitting a syntax error that doesn't affect parsing.
Use Cases
Issues such as #11648 and #19352 pop up from situations where the parser attempts to read in a list, such as one of variable declarations, and cannot because an identifier is invalid.
const case = 123;
// ~~~~ 'case' is not allowed as a variable declaration name.(1389)
// ~ Variable declaration expected.(1134)
// ~~~ Variable declaration expected.(1134)
Although #40105 improved the first error message (previously it was also Variable declaration expected.), the underlying issue remains: the parser aborts reading in the list, resulting in an odd error message and surprising emitted JavaScript.
const ;
123;
Examples
Collecting a few examples from the linked issues...
const data = { in: 1 };
const { in } = data;
for (const case of [1, 2, 3]) console.log(case);
const case = 123;
let delete = true;
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Implementierungsdateien oder Tests. Beginne damit, die aufgeführten Fälle von ungültigen Identifiern im TypeScript-Parser zu reproduzieren und nachzuverfolgen, wie das Parsen von Listen mit dem ersten Syntaxfehler umgeht. Als erledigt gilt die Aufgabe, wenn der Parser den Identifier-Fehler meldet und weiterhin die umgebende Deklaration oder Liste parst, ohne die aktuelle fehlerhafte Ausgabe zu erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100