Skip to content

Commit

Permalink
[[FIX]] Improve declaration parsing
Browse files Browse the repository at this point in the history
Add an internal test so the coverage analysis tool recognizes that the
modified branch is verified.
  • Loading branch information
jugglinmike committed Mar 1, 2021
1 parent 2c1a5f8 commit a9bdc93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/jshint.js
Expand Up @@ -4670,8 +4670,11 @@ var JSHINT = (function() {
error("E008", this.name);
}

if (state.tokens.next.id === "(" && state.tokens.next.line === state.tokens.curr.line) {
/* istanbul ignore next */
// Although the parser correctly recognizes the statement boundary in this
// condition, it's support for the invalid "empty grouping" expression
// makes it tolerant of productions such as `function f() {}();`.
if (state.tokens.next.id === "(" && peek().id === ")" && peek(1).id !== "=>" &&
state.tokens.next.line === state.tokens.curr.line) {
error("E039");
}
return this;
Expand Down
6 changes: 0 additions & 6 deletions tests/test262/expectations.txt
Expand Up @@ -9028,12 +9028,6 @@ test/language/statementList/class-regexp-literal-flags.js(default)
test/language/statementList/class-regexp-literal-flags.js(strict mode)
test/language/statementList/class-regexp-literal.js(default)
test/language/statementList/class-regexp-literal.js(strict mode)
test/language/statementList/fn-arrow-function-assignment-expr.js(default)
test/language/statementList/fn-arrow-function-assignment-expr.js(strict mode)
test/language/statementList/fn-arrow-function-functionbody.js(default)
test/language/statementList/fn-arrow-function-functionbody.js(strict mode)
test/language/statementList/fn-expr-arrow-function-boolean-literal.js(default)
test/language/statementList/fn-expr-arrow-function-boolean-literal.js(strict mode)
test/language/statementList/fn-regexp-literal-flags.js(default)
test/language/statementList/fn-regexp-literal-flags.js(strict mode)
test/language/statementList/fn-regexp-literal.js(default)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -10263,3 +10263,20 @@ exports.asyncIteration = function (test) {

test.done();
};

exports.parensAfterDeclaration = function (test) {
TestRun(test)
.addError(1, 17, "Function declarations are not invocable. Wrap the whole function invocation in parens.")
.addError(1, 18, "Expected an assignment or function call and instead saw an expression.")
.test("function f () {}();");

TestRun(test)
.addError(1, 19, "Expected an assignment or function call and instead saw an expression.")
.test("function f () {}(0);");

TestRun(test)
.addError(1, 24, "Expected an assignment or function call and instead saw an expression.")
.test("function f () {}() => {};", {esversion: 6});

test.done();
};

0 comments on commit a9bdc93

Please sign in to comment.