Skip to content

Commit

Permalink
Support optional catch binding (stage 4 / ES2019) (#2455)
Browse files Browse the repository at this point in the history
* support optional catch binding (stage 4 / ES2019)

* correct test indentation: looks like this is a tabs codebase(!)

* switch default ecmaVersion to 2019; remove acorn options from option catch param test
  • Loading branch information
bathos authored and lukastaegert committed Sep 13, 2018
1 parent 6eb8036 commit 007f42b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -101,7 +101,7 @@ export interface AstContext {

export const defaultAcornOptions: AcornOptions = {
// TODO TypeScript waiting for acorn types to be updated
ecmaVersion: <any>2018,
ecmaVersion: <any>2019,
sourceType: 'module',
preserveParens: false
};
Expand Down
13 changes: 7 additions & 6 deletions src/ast/nodes/CatchClause.ts
Expand Up @@ -8,7 +8,7 @@ import { PatternNode } from './shared/Pattern';

export default class CatchClause extends NodeBase {
type: NodeType.tCatchClause;
param: PatternNode;
param: PatternNode | null;
body: BlockStatement;

scope: CatchScope;
Expand All @@ -20,14 +20,15 @@ export default class CatchClause extends NodeBase {

initialise() {
this.included = false;
this.param.declare('parameter', UNKNOWN_EXPRESSION);

if (this.param) {
this.param.declare('parameter', UNKNOWN_EXPRESSION);
}
}

parseNode(esTreeNode: GenericEsTreeNode) {
this.body = <BlockStatement>new this.context.nodeConstructors.BlockStatement(
esTreeNode.body,
this,
this.scope
this.body = <BlockStatement>(
new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, this.scope)
);
super.parseNode(esTreeNode);
}
Expand Down
9 changes: 9 additions & 0 deletions test/function/samples/optional-catch-binding/_config.js
@@ -0,0 +1,9 @@
const assert = require('assert');

module.exports = {
description: 'allows optional catch binding with appropriate acorn settings',
minNodeVersion: 10,
exports(exports) {
assert.equal(exports.foo, true);
}
};
7 changes: 7 additions & 0 deletions test/function/samples/optional-catch-binding/main.js
@@ -0,0 +1,7 @@
export let foo;

try {
foo();
} catch {
foo = true;
}

0 comments on commit 007f42b

Please sign in to comment.