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

Support optional try/catch binding as added in Node 10 & V8 6.6 #1953

Open
Avuxo opened this Issue Oct 19, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Avuxo

Avuxo commented Oct 19, 2018

Support for this ECMAScript Stage 4 proposal. This has already been implemented in v8 6.6 and as a result is already implemented in new versions of Google Chrome/Chromium and Node.js 10. This language feature is used in the Node.js `assert' standard library, so any users who attempt to apply the parser to that file will encounter this error.

Previously, try/catch statements required a binding to be syntactically valid. However, with this change they are no longer a requirement as the binding is now optional.

try {
    // something exceptional
} catch {
    // no longer has a required parameter
}

This issue would be a fairly simple implementation and would likely not add any significant overhead to the parsing process.

Steps to reproduce

// run in any environment using V8 6.6: Google Chrome or Node 10.x
esprima.parse('try { new Error(); } catch {}');

Expected output

// AST
{
  "type": "Program",
  "body": [
    {
      "type": "TryStatement",
      "block": {
        "type": "BlockStatement",
        "body": [
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "NewExpression",
              "callee": {
                "type": "Identifier",
                "name": "Error"
              },
              "arguments": []
            }
          }
        ]
      },
      "handler": {
        "type": "CatchClause",
        "param": null,
        "body": {
          "type": "BlockStatement",
          "body": []
        }
      },
      "finalizer": null
    }
  ],
  "sourceType": "script"
}

Actual output

/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:1995
	        throw this.unexpectedTokenError(token, message);
	        ^
Error: Line 1: Unexpected token {
    at ErrorHandler.constructError (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:1985:39)
    at Parser.throwUnexpectedToken (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:1995:21)
    at Parser.expect (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:2168:19)
    at Parser.parseCatchClause (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:4049:15)
    at Parser.parseTryStatement (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:4080:58)
    at Parser.parseStatement (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:4157:43)
    at Parser.parseStatementListItem (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:3388:39)
    at Parser.parseScript (/Users/ben/workspace/testing/catch-binding/node_modules/esprima/dist/esprima.js:4723:29)

Relevant references

@ariya

This comment has been minimized.

Contributor

ariya commented Oct 19, 2018

Hi @Avuxo, thanks for the report.

For a new language feature, we usually need more details, see this guide. For some examples, see e.g. #1550. Please review the issue description to include the necessary information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment