microsoft / microsoft/TypeScript

Parser misinterprets async() calls in conditional expressions as async arrow functions

Offen
#64,231 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔎 Search Terms

parser, async, conditional

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

_No response_

### 💻 Code

```ts
const a = true;
const b = 1;

function async(): number {
return b;
}

const first = a ? async() : 0;
// TS1005: '=>' expected.

const second = a ? async() : x => x;
// TS1005: ':' expected.
```

### 🙁 Actual behavior

The parser appears to interpret async() as the beginning of an async arrow function and the conditional separator as a return-type annotation.
The first case also produces a syntax diagnostic when parsed as JavaScript after removing the : number annotation. Node accepts and executes that JavaScript equivalent

### 🙂 Expected behavior

Both conditional expressions should parse successfully. async() is a call to the function named async, and the following colon separates the conditional’s branches.

### Additional information about the issue

Oxc fix: https://github.com/oxc-project/oxc/pull/26537

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die beiden Beispiele für bedingte Ausdrücke im TypeScript-Parser nachzustellen und zu vergleichen, wie async() im Vergleich zu einer async-Pfeilfunktion klassifiziert wird. Verwende den verlinkten Oxc-Fix als Referenz für das relevante Parsing-Verhalten. Als erledigt gilt die Aufgabe, wenn beide Beispiele erfolgreich ohne die gemeldeten Diagnosen geparst werden und eine Regressionstestabdeckung für die gezeigten Fälle vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.