Object Getter triggers yield to incorrectly parse as YieldExpression
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, typescript
- 领域
- compilers
调研方向
从 parser.ts 第 3257 行附近开始,使用提供的 esprima.parse 示例复现该问题。将生成的 AST 与预期输出进行比较,重点关注解析 getter 是否会使 context.allowYield 保持为已更改的状态。完成的标准是后面的 yield 被表示为 Identifier,并且 getter 仍能被正确解析。
由索引模型根据 Issue 内容生成。
描述
When any get property is encountered the context.allowYield property is set to false and not reverted after parsing the getter body. This results in any future yield to be parsed as a yield expression incorrectly.
esprima.parse(`
({get a(){}});
yield;
`)
Expected output
{
"type": "Program",
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ObjectExpression",
"properties": [
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "a"
},
"computed": false,
"kind": "get",
"method": false,
"shorthand": false,
"value": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": []
},
"generator": false,
"async": false,
"expression": false
}
}
]
}
},
{
"type": "ExpressionStatement",
"expression": {
"type": "Identifier",
"name": "yield"
}
}
]
}
Actual output
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ObjectExpression",
"properties": [
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "a"
},
"computed": false,
"value": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false,
"async": false
},
"kind": "get",
"method": false,
"shorthand": false
}
]
}
},
{
"type": "ExpressionStatement",
"expression": {
"type": "YieldExpression",
"argument": null,
"delegate": false
}
}
],
"sourceType": "script"
}
This is pulled directly from everything.js
Using this file as and example, I was surprised that removing line 84 will cause this to parse differently as they are completely unrelated.
I believe the offending code is located on line 3257 of parser.ts.
I believe the correct path in the ecma262 spec for line 200 would be
- StatementListItem
- Statement
- ExpressionStatement
- Expression
- AssignmentExpression
- ConditionalExpression
- LogicalORExpression
- LogicalANDExpression
- BitwiseORExpression
- BitwiseXORExpression
- BitwiseANDExpression
- EqualityExpression
- RelationalExpression
- ShiftExpression
- AdditiveExpression
- MultiplicativeExpression
- ExponentiationExpression
- UnaryExpression
- UpdateExpression
- LeftHandSideExpression
- NewExpression
- MemberExpression
- PrimaryExpression
- IdentifierReference
- Identifier
- 主要语言
- TypeScript
- 星标
- 7.1k
- 派生
- 772
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jquery/esprima 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 52/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
automated-triage type/bug type/ci
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
📦 expo-router Android contributor: external needs review sdk-58 severity: medium
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
documentation good first issue
难度 2/5 1-3 小时 新手友好度 84/100
asasemahmed/openboard#68 ·
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 72/100
-
Document PowerShell shell semantics and read-only Bash deduplication in Built-in Tools reference未关闭documentation
难度 2/5 1-3 小时 新手友好度 78/100