Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[[FIX]] TypeError accessing 'value' of undefined
Make sure that 'decl.first[0]' is defined before accessing its 'value'
attribute.

No breaking changes.

Fixes #3455
  • Loading branch information
stvcisco authored and jugglinmike committed Apr 12, 2020
1 parent 53298b3 commit 8884eb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jshint.js
Expand Up @@ -5219,7 +5219,7 @@ var JSHINT = (function() {
}
nolinebreak(state.tokens.curr);
advance(";");
if (decl) {
if (decl && decl.first && decl.first[0]) {
if (decl.value === "const" && !decl.hasInitializer) {
warning("E012", decl, decl.first[0].value);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/core.js
Expand Up @@ -2352,6 +2352,20 @@ exports.initializeCStyle = function(test) {
test.done();
};

// regression test for gh-3455
exports.constWithoutVar = function(test) {
TestRun(test)
.addError(1, 11, "Expected an identifier and instead saw ';'.")
.addError(1, 12, "Expected an identifier and instead saw ')'.")
.addError(1, 12, "Expected ';' and instead saw ''.")
.addError(1, 12, "Unrecoverable syntax error. (100% scanned).")
.test([
"for (const;)"
], { esversion: 6 });

test.done();
};

exports.constWithoutInit = function(test) {
TestRun(test, "single binding")
.addError(1, 6, "const 'x' is initialized to 'undefined'.")
Expand Down

0 comments on commit 8884eb9

Please sign in to comment.