jquery / esprima

ECMAScript parsing infrastructure for multipurpose analysis
http://esprima.org
BSD 2-Clause "Simplified" License
7.04k stars 786 forks source link

Per ECMAScript spec, `function` body `{...}` is not a block #2067

Open zhanzhenzhen opened 3 years ago

zhanzhenzhen commented 3 years ago

ECMAScript 2021: https://tc39.es/ecma262/#sec-function-definitions

ECMAScript 5.1: https://262.ecma-international.org/5.1/#sec-13

Meir017 commented 3 years ago

@zhanzhenzhen can you add some code to show your scenario?

zhanzhenzhen commented 3 years ago
function a() {}
{
  "type": "Program",
  "body": [
    {
      "type": "FunctionDeclaration",
      "id": {
        "type": "Identifier",
        "name": "a"
      },
      "params": [],
      "body": {
        "type": "BlockStatement",
        "body": []
      },
      "generator": false,
      "expression": false,
      "async": false
    }
  ],
  "sourceType": "script"
}

But the ECMAScript specification says function body is neither a block nor a statement.

function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] }