Skip to content

Commit

Permalink
Merge 3ce6a99 into 02f20b2
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed May 4, 2019
2 parents 02f20b2 + 3ce6a99 commit 166cd97
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
8 changes: 7 additions & 1 deletion 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 Expand Up @@ -5292,7 +5298,7 @@ var JSHINT = (function() {
error("E024", this, "await");
}

expression(context, 0);
expression(context, 10);
return this;
} else {
this.exps = false;
Expand Down
80 changes: 80 additions & 0 deletions tests/unit/options.js
Expand Up @@ -3425,6 +3425,86 @@ 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.await = function (test) {
TestRun(test, "MultiplicativeExpression")
.addError(2, 3, "Unnecessary grouping operator.")
.test([
"(async function() {",
" (await 2) * 3;",
"})();"
], { singleGroups: true, expr: true, esversion: 8 });

TestRun(test, "ExponentiationExpression")
.addError(2, 3, "Unnecessary grouping operator.")
.test([
"(async function() {",
" (await 2) ** 3;",
"})();"
], { singleGroups: true, expr: true, esversion: 8 });

TestRun(test, "CallExpression")
.test([
"(async function() {",
" (await 2)();",
"})();"
], { singleGroups: true, expr: true, esversion: 8 });

TestRun(test, "EqualityExpression")
.addError(2, 3, "Unnecessary grouping operator.")
.addError(3, 3, "Unnecessary grouping operator.")
.addError(4, 3, "Unnecessary grouping operator.")
.addError(5, 3, "Unnecessary grouping operator.")
.test([
"(async function() {",
" (await 2) == 2;",
" (await 2) != 2;",
" (await 2) === 2;",
" (await 2) !== 2;",
"})();"
], { singleGroups: true, expr: true, esversion: 8 });

TestRun(test, "Expression")
.addError(2, 3, "Unnecessary grouping operator.")
.test([
"(async function() {",
" (await 0), 0;",
"})();"
], { singleGroups: true, expr: true, esversion: 8 });

test.done();
};

singleGroups.objectLiterals = function (test) {
var code = [
"({}).method();",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -9591,6 +9591,16 @@ exports.asyncFunctions.awaitOperator = function (test) {
"};",
], { esversion: 8 });

// Regression test for gh-3395
TestRun(test, "within object initializer")
.test([
"void async function() {",
" void {",
" x: await 0,",
" };",
"};"
], { esversion: 8 });

test.done();
};

Expand Down

0 comments on commit 166cd97

Please sign in to comment.