shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
251 stars 28 forks source link

"await" as an ObjectBindingIdentifier in Formal Parameter for an async function not throwing error #416

Closed Shilpi3 closed 5 years ago

Shilpi3 commented 5 years ago

The scripts ``async ({await}) => 1 async function x({await}) { return 1 }

should throw an error in the parser. Instead, it is parsed as the following AST.
{
  "type": "Script",
  "directives": [],
  "statements": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "ArrowExpression",
        "isAsync": true,
        "params": {
          "type": "FormalParameters",
          "items": [
            {
              "type": "ObjectBinding",
              "properties": [
                {
                  "type": "BindingPropertyIdentifier",
                  "binding": {
                    "type": "BindingIdentifier",
                    "name": "await"
                  },
                  "init": null
                }
              ]
            }
          ],
          "rest": null
        },
        "body": {
          "type": "LiteralNumericExpression",
          "value": 1
        }
      }
    }
  ]
}

The script does not throw an early Error as well.

bakkot commented 5 years ago

It's also incorrectly allowed in the body of async functions:

async function f() { return { await }; }

should be a parse error, but is not.

bakkot commented 5 years ago

Fixed by #418.