From d33d83189355923c53d80ea5d48eaee2466c5801 Mon Sep 17 00:00:00 2001 From: "William C. Johnson" Date: Wed, 25 Oct 2017 00:08:23 -0400 Subject: [PATCH] Fix bound catchExprs --- src/plugins/catchExpression.js | 2 +- .../catch-expression/binding/basic/actual.js | 2 + .../binding/basic/expected.json | 166 ++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/catch-expression/binding/basic/actual.js create mode 100644 test/fixtures/catch-expression/binding/basic/expected.json diff --git a/src/plugins/catchExpression.js b/src/plugins/catchExpression.js index d555171143..a5492059ab 100644 --- a/src/plugins/catchExpression.js +++ b/src/plugins/catchExpression.js @@ -47,7 +47,7 @@ export default function(parser) { this.state.inMatchCaseTest = true; this.parseCatchCaseAtoms(node); - if (this.isContextual("as")) { + if (this.eatContextual("as")) { this.parseCatchCaseBinding(node); } diff --git a/test/fixtures/catch-expression/binding/basic/actual.js b/test/fixtures/catch-expression/binding/basic/actual.js new file mode 100644 index 0000000000..ac17909fce --- /dev/null +++ b/test/fixtures/catch-expression/binding/basic/actual.js @@ -0,0 +1,2 @@ +a + catch Error as err: err diff --git a/test/fixtures/catch-expression/binding/basic/expected.json b/test/fixtures/catch-expression/binding/basic/expected.json new file mode 100644 index 0000000000..27138f3329 --- /dev/null +++ b/test/fixtures/catch-expression/binding/basic/expected.json @@ -0,0 +1,166 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "CatchExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "cases": [ + { + "type": "CatchCase", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "atoms": [ + { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "Error" + }, + "name": "Error" + } + ], + "binding": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "err" + }, + "name": "err" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "Identifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "err" + }, + "name": "err" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file