Skip to content

Commit

Permalink
[[FIX]] Do not crash on improper use of delete
Browse files Browse the repository at this point in the history
In valid JavaScript code, when the `delete` token is parsed as a prefix,
it will be followed by an expression of some kind. Invalid code may
include any sequence of characters after the `delete` token, and JSHint
should be capable of gracefully warning about the syntax error.

Avoid crashing in cases where the `delete` appears as a "prefix" token
but is not followed by an expression.
  • Loading branch information
jugglinmike committed Feb 23, 2015
1 parent 69b3187 commit 35df49f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/jshint.js
Expand Up @@ -2224,7 +2224,11 @@ var JSHINT = (function() {
state.syntax["--"].exps = true;
prefix("delete", function() {
var p = expression(10);
if (!p || (p.id !== "." && p.id !== "[")) {
if (!p) {
return this;
}

if (p.id !== "." && p.id !== "[") {
warning("W051");
}
this.first = p;
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -5261,3 +5261,12 @@ exports.testStrictDirectiveASI = function (test) {

test.done();
};

exports.dereferenceDelete = function (test) {
TestRun(test)
.addError(1, "Expected an identifier and instead saw '.'.")
.addError(1, "Missing semicolon.")
.test("delete.foo();");

test.done();
};

0 comments on commit 35df49f

Please sign in to comment.