Skip to content

Commit

Permalink
[[FIX]] parse const declarations in ForIn/Of loops
Browse files Browse the repository at this point in the history
Closes #2334
Closes #2335
  • Loading branch information
caitp committed Apr 24, 2015
1 parent dd768c2 commit 2b673d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4189,8 +4189,8 @@ var JSHINT = (function() {
if (state.tokens.next.id === "var") {
advance("var");
state.tokens.curr.fud({ prefix: true });
} else if (state.tokens.next.id === "let") {
advance("let");
} else if (state.tokens.next.id === "let" || state.tokens.next.id === "const") {
advance(state.tokens.next.id);
// create a new block scope
letscope = true;
funct["(blockscope)"].stack();
Expand Down
13 changes: 10 additions & 3 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3658,7 +3658,8 @@ exports["for of as esnext"] = function (test) {
"for (let x of [1,2,3,4]) {",
" print(x);",
"}",
"for (let x of [1,2,3,4]) print(x);"
"for (let x of [1,2,3,4]) print(x);",
"for (const x of [1,2,3,4]) print(x);"
];
TestRun(test)
.test(code, {esnext: true, undef: true, predef: ["print"]});
Expand All @@ -3671,13 +3672,16 @@ exports["for of as es5"] = function (test) {
"for (let x of [1,2,3,4]) {",
" print(x);",
"}",
"for (let x of [1,2,3,4]) print(x);"
"for (let x of [1,2,3,4]) print(x);",
"for (const x of [1,2,3,4]) print(x);"
];
TestRun(test)
.addError(1, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(1, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(4, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(4, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(5, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(5, "'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.test(code, {undef: true, predef: ["print"]}); // es5

test.done();
Expand All @@ -3688,13 +3692,16 @@ exports["for of as legacy JS"] = function (test) {
"for (let x of [1,2,3,4]) {",
" print(x);",
"}",
"for (let x of [1,2,3,4]) print(x);"
"for (let x of [1,2,3,4]) print(x);",
"for (const x of [1,2,3,4]) print(x);"
];
TestRun(test)
.addError(1, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(1, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(4, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(4, "'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(5, "'for of' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.addError(5, "'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).")
.test(code, {undef: true, predef: ["print"]}); // es5

test.done();
Expand Down

0 comments on commit 2b673d9

Please sign in to comment.