Skip to content

Commit

Permalink
Allow lexical declaration with const in a ForInStatement.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Feb 23, 2015
1 parent dae6e7d commit 9a62208
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
6 changes: 4 additions & 2 deletions esprima.js
Expand Up @@ -3095,8 +3095,10 @@
}

if (kind === 'const') {
expect('=');
init = parseAssignmentExpression();
if (!matchKeyword('in')) {
expect('=');
init = parseAssignmentExpression();
}
} else if (match('=')) {
lex();
init = parseAssignmentExpression();
Expand Down
55 changes: 55 additions & 0 deletions test/test.js
Expand Up @@ -21024,6 +21024,61 @@ var testFixture = {
}
},

'for (const x in y){}': {
type: 'ForInStatement',
left: {
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 'x',
range: [11, 12],
loc: {
start: { line: 1, column: 11 },
end: { line: 1, column: 12 }
}
},
init: null,
range: [11, 12],
loc: {
start: { line: 1, column: 11 },
end: { line: 1, column: 12 }
}
}],
kind: 'const',
range: [5, 12],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 12 }
}
},
right: {
type: 'Identifier',
name: 'y',
range: [16, 17],
loc: {
start: { line: 1, column: 16 },
end: { line: 1, column: 17 }
}
},
body: {
type: 'BlockStatement',
body: [],
range: [18, 20],
loc: {
start: { line: 1, column: 18 },
end: { line: 1, column: 20 }
}
},
each: false,
range: [0, 20],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 20 }
}
},

'for (var x = y = z in q);': {
type: 'ForInStatement',
left: {
Expand Down

0 comments on commit 9a62208

Please sign in to comment.