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.

Bewertung

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

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.

Beschreibung

Bug
🔎 Search Terms

parser, async, conditional

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

No response

💻 Code
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

Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoft/TypeScript

Alle Issues in microsoft/TypeScript

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

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