Object Getter triggers yield to incorrectly parse as YieldExpression

オープン
#1,982 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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

  1. StatementListItem
  2. Statement
  3. ExpressionStatement
  4. Expression
  5. AssignmentExpression
  6. ConditionalExpression
  7. LogicalORExpression
  8. LogicalANDExpression
  9. BitwiseORExpression
  10. BitwiseXORExpression
  11. BitwiseANDExpression
  12. EqualityExpression
  13. RelationalExpression
  14. ShiftExpression
  15. AdditiveExpression
  16. MultiplicativeExpression
  17. ExponentiationExpression
  18. UnaryExpression
  19. UpdateExpression
  20. LeftHandSideExpression
  21. NewExpression
  22. MemberExpression
  23. PrimaryExpression
  24. IdentifierReference
  25. Identifier
主要言語
TypeScript
スター
7.1k
フォーク
772
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jquery/esprima のほかの issue

jquery/esprima の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。