Permalink
Browse files

[[FIX]] parse `const` declarations in ForIn/Of loops

Closes #2334
Closes #2335
  • Loading branch information...
caitp committed Apr 23, 2015
1 parent dd768c2 commit 2b673d92107be93df80e48471dced0432a127f25
Showing with 12 additions and 5 deletions.
  1. +2 −2 src/jshint.js
  2. +10 −3 tests/unit/parser.js
@@ -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();
@@ -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"]});
@@ -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();
@@ -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();

0 comments on commit 2b673d9

Please sign in to comment.