microsoft / microsoft/TypeScript
Parser misinterprets async() calls in conditional expressions as async arrow functions
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 TypeScript 解析器中复现两个条件表达式示例,并比较 async() 与 async 箭头函数的分类方式。参考链接的 Oxc 修复来了解相关的解析行为。完成标准是两个示例都能成功解析且不再出现报告中的诊断,并且为所示案例添加回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100