esprima icon indicating copy to clipboard operation
esprima copied to clipboard

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

Open zhanzhenzhen opened this issue 4 years ago • 2 comments

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

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

zhanzhenzhen avatar Feb 01 '21 23:02 zhanzhenzhen

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

Meir017 avatar Feb 02 '21 03:02 Meir017

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] }

zhanzhenzhen avatar Feb 02 '21 06:02 zhanzhenzhen