Skip to content

Commit

Permalink
[[FIX]] Don't crash on uncomplete typeof expression
Browse files Browse the repository at this point in the history
Fixes #2506
  • Loading branch information
nicolo-ribaudo authored and lukeapage committed Jul 2, 2015
1 parent aa8a023 commit a32cf50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,10 @@ var JSHINT = (function() {
var p = expression(150);
this.first = p;

if (!p) { // 'typeof' followed by nothing? Give up.
quit("E041", this.line || 0, this.character || 0);
}

// The `typeof` operator accepts unresolvable references, so the operand
// may be undefined.
if (p.identifier) {
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ exports.other = function (test) {
.addError(1, "Unrecoverable syntax error. (100% scanned).")
.test("if (product < ) {}", {es3: true});

// GH-2506
TestRun(test)
.addError(1, "Expected an identifier and instead saw ';'.")
.addError(1, "Unrecoverable syntax error. (100% scanned).")
.test("typeof;");

test.done();
};

Expand Down

0 comments on commit a32cf50

Please sign in to comment.