Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Getter triggers yield to incorrectly parse as YieldExpression #1982

Open
FreeMasen opened this issue Jul 22, 2019 · 1 comment
Open

Object Getter triggers yield to incorrectly parse as YieldExpression #1982

FreeMasen opened this issue Jul 22, 2019 · 1 comment

Comments

@FreeMasen
Copy link

@FreeMasen FreeMasen commented Jul 22, 2019

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
@FreeMasen
Copy link
Author

@FreeMasen FreeMasen commented Jul 31, 2019

I think I had a problem originally with my expected and actual json blocks. I have corrected this block to correctly match what I was expecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.