Skip to content

Commit

Permalink
[[FIX]] Relax singleGroups for async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Jun 6, 2019
1 parent 02f20b2 commit c5dcd90
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/jshint.js
Expand Up @@ -3173,6 +3173,12 @@ var JSHINT = (function() {
ret = first = last = exprs[0];

if (!isNecessary) {
// async functions are identified after parsing due to the complexity
// of disambiguating the `async` keyword.
if (!triggerFnExpr) {
triggerFnExpr = ret.id === "async";
}

isNecessary =
// Used to distinguish from an ExpressionStatement which may not
// begin with the `{` and `function` tokens
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/options.js
Expand Up @@ -3425,6 +3425,37 @@ singleGroups.exponentiation = function (test) {
test.done();
};

singleGroups.asyncFunction = function (test) {
TestRun(test, "Async Function Expression")
.test([
"(async function() {})();",
"(async function a() {})();"
], { singleGroups: true, esversion: 8 });

TestRun(test, "Async Generator Function Expression")
.test([
"(async function * () { yield; })();",
"(async function * a() { yield; })();"
], { singleGroups: true, esversion: 9 });


TestRun(test, "Async Arrow Function")
.test([
"(async () => {})();",
"(async x => x)();"
], { singleGroups: true, esversion: 8 });

TestRun(test, "async identifier")
.addError(1, 1, "Unnecessary grouping operator.")
.addError(2, 1, "Unnecessary grouping operator.")
.test([
"(async());",
"(async(x, y, z));"
], { singleGroups: true, esversion: 8 });

test.done();
};

singleGroups.objectLiterals = function (test) {
var code = [
"({}).method();",
Expand Down

0 comments on commit c5dcd90

Please sign in to comment.