Skip to content

Commit fe62b19

Browse files
committed
Merge pull request #106 from eslint/issue105
Fix: Destructured arg for catch (fixes #105)
2 parents f5d1b5a + d8a6f69 commit fe62b19

File tree

5 files changed

+1091
-3
lines changed

5 files changed

+1091
-3
lines changed

espree.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,7 +4132,11 @@ function parseThrowStatement() {
41324132

41334133
function parseCatchClause() {
41344134
var param, body,
4135-
marker = markerCreate();
4135+
marker = markerCreate(),
4136+
allowDestructuring = extra.ecmaFeatures.destructuring,
4137+
options = {
4138+
paramSet: new StringMap()
4139+
};
41364140

41374141
expectKeyword("catch");
41384142

@@ -4141,9 +4145,25 @@ function parseCatchClause() {
41414145
throwUnexpected(lookahead);
41424146
}
41434147

4144-
param = parseVariableIdentifier();
4148+
if (match("[")) {
4149+
if (!allowDestructuring) {
4150+
throwUnexpected(lookahead);
4151+
}
4152+
param = parseArrayInitialiser();
4153+
reinterpretAsDestructuredParameter(options, param);
4154+
} else if (match("{")) {
4155+
4156+
if (!allowDestructuring) {
4157+
throwUnexpected(lookahead);
4158+
}
4159+
param = parseObjectInitialiser();
4160+
reinterpretAsDestructuredParameter(options, param);
4161+
} else {
4162+
param = parseVariableIdentifier();
4163+
}
4164+
41454165
// 12.14.1
4146-
if (strict && syntax.isRestrictedWord(param.name)) {
4166+
if (strict && param.name && syntax.isRestrictedWord(param.name)) {
41474167
throwErrorTolerant({}, Messages.StrictCatchVariable);
41484168
}
41494169

0 commit comments

Comments
 (0)