Skip to content

Commit

Permalink
[[FIX]] Tolerate keyword in object shorthand
Browse files Browse the repository at this point in the history
Ensure that JSHint reports a syntax error rather than crashing.
  • Loading branch information
jugglinmike authored and rwaldron committed Sep 23, 2021
1 parent ecae54a commit 057b1c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4075,8 +4075,10 @@ var JSHINT = (function() {
warning("W104", state.tokens.next, "object short notation", "6");
}
t = expression(context, 10);
i = t.value;
saveProperty(props, i, t);
i = t && t.value;
if (t) {
saveProperty(props, i, t);
}

} else if (peek().id !== ":" && (nextVal === "get" || nextVal === "set")) {
advance(nextVal);
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10647,3 +10647,21 @@ exports.loneNullishCoalescing = function (test) {

test.done();
};

// gh-3571: "Cannot read properties of undefined at Object.e.nud"
exports.keywordAsShorthandObjectProperty = function (test) {
TestRun(test, "as reported")
.addError(1, 12, "Expected an identifier and instead saw 'do'.")
.addError(1, 15, "Missing semicolon.")
.test("const a = {do}", {esversion: 6});

TestRun(test, "simplified")
.addError(1, 7, "Expected an identifier and instead saw 'do'.")
.test("void {do};", {esversion: 6});

TestRun(test, "alternate - penultimate member")
.addError(1, 7, "Expected an identifier and instead saw 'for'.")
.test("void {for, baz};", {esversion: 6});

test.done();
};

0 comments on commit 057b1c6

Please sign in to comment.