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

Support optional catch binding #382

Open
cixel opened this issue Oct 23, 2018 · 1 comment
Open

Support optional catch binding #382

cixel opened this issue Oct 23, 2018 · 1 comment

Comments

@cixel
Copy link

cixel commented Oct 23, 2018

Support this Stage 4 proposal to allow omission of catch variable in cases where the error is unused:

try {
  // ...
} catch {
  // ...
}

See Why? for justification and more details.

This has already been implemented in v8 6.6 and is available in recent versions of Chrome and in Node.js 10.

To reproduce

escodegen.generate({
  type: 'TryStatement',
  block: {
    type: 'BlockStatement',
    body: []
  },
  handler: {
    type: 'CatchClause',
    param: null,
    body: {
      type: 'BlockStatement',
      body: []
    }
  },
  finalizer: null
})

Output

/Users/ehdens/misc-oss/escodegen/escodegen.js:2446
        type = expr.type || Syntax.Property;
                    ^

TypeError: Cannot read property 'type' of null
    at CodeGenerator.generateExpression (/Users/ehdens/misc-oss/escodegen/escodegen.js:2446:21)
    at /Users/ehdens/misc-oss/escodegen/escodegen.js:1181:26
    at withIndent (/Users/ehdens/misc-oss/escodegen/escodegen.js:574:9)
    at CodeGenerator.CatchClause (/Users/ehdens/misc-oss/escodegen/escodegen.js:1176:13)
    at CodeGenerator.generateStatement (/Users/ehdens/misc-oss/escodegen/escodegen.js:2465:33)
    at CodeGenerator.TryStatement (/Users/ehdens/misc-oss/escodegen/escodegen.js:1526:52)
    at CodeGenerator.generateStatement (/Users/ehdens/misc-oss/escodegen/escodegen.js:2465:33)
    at generateInternal (/Users/ehdens/misc-oss/escodegen/escodegen.js:2486:28)
    at Object.generate (/Users/ehdens/misc-oss/escodegen/escodegen.js:2554:18)
    at Object.<anonymous> (/Users/ehdens/misc-oss/escodegen/demo.js:3:24)

Expected Output

try {
} catch {
}
@sanex3339
Copy link
Contributor

sanex3339 commented Jan 11, 2020

Support in master now

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

Successfully merging a pull request may close this issue.

2 participants