Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: ensure no-await-in-loop reports the correct node (fixes #9992) (#…
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Feb 20, 2018
1 parent 3e99363 commit f417506
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-await-in-loop.js
Expand Up @@ -84,7 +84,7 @@ module.exports = {
while (parent && !isBoundary(parent)) {
if (isLooped(node, parent)) {
context.report({
node,
node: awaitNode,
messageId: "unexpectedAwait"
});
return;
Expand Down
7 changes: 5 additions & 2 deletions tests/lib/rules/no-await-in-loop.js
Expand Up @@ -8,7 +8,7 @@
const rule = require("../../../lib/rules/no-await-in-loop"),
RuleTester = require("../../../lib/testers/rule-tester");

const error = { messageId: "unexpectedAwait" };
const error = { messageId: "unexpectedAwait", type: "AwaitExpression" };

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });

Expand Down Expand Up @@ -46,7 +46,10 @@ ruleTester.run("no-await-in-loop", rule, {
// While loops
{ code: "async function foo() { while (baz) { await bar; } }", errors: [error] },
{ code: "async function foo() { while (await foo()) { } }", errors: [error] },
{ code: "async function foo() { while (baz) { for await (x of xs); } }", errors: [error] },
{
code: "async function foo() { while (baz) { for await (x of xs); } }",
errors: [Object.assign({}, error, { type: "ForOfStatement" })]
},

// For of loops
{ code: "async function foo() { for (var bar of baz) { await bar; } }", errors: [error] },
Expand Down

0 comments on commit f417506

Please sign in to comment.