Skip to content

Commit

Permalink
[[FIX]] Do not create binding for illegal syntax
Browse files Browse the repository at this point in the history
When a function declaration without an identifier is encountered, JSHint
issues a warning and attempts to continue parsing the declaration.

Previously, JSHint created a new binding for the "function" keyword, and
because such a binding can never be referenced, this would generate
spurious warnings when the "unused" option was enabled.

Do not create a faulty binding in the presence of this syntax error.
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 15, 2017
1 parent a5ff715 commit 9fe8c94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3909,14 +3909,16 @@ var JSHINT = (function() {
}
var i = optionalidentifier();

state.funct["(scope)"].addlabel(i, {
type: "function",
token: state.tokens.curr });

if (i === undefined) {
warning("W025");
} else if (inexport) {
state.funct["(scope)"].setExported(i, state.tokens.prev);
} else {
state.funct["(scope)"].addlabel(i, {
type: "function",
token: state.tokens.curr });

if (inexport) {
state.funct["(scope)"].setExported(i, state.tokens.prev);
}
}

doFunction({
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,10 @@ exports.testUnnamedFuncStatement = function (test) {
.addError(1, "Missing name in function declaration.")
.test("function() {}");

TestRun(test, "with 'unused' option")
.addError(1, "Missing name in function declaration.")
.test("function() {}", { unused: true });

test.done();
};

Expand Down

0 comments on commit 9fe8c94

Please sign in to comment.