Skip to content

Commit

Permalink
Fix: Handle await expressions correctly in no-unused-expressions (#…
Browse files Browse the repository at this point in the history
…7175)

(refs #7101)
  • Loading branch information
not-an-aardvark authored and nzakas committed Sep 19, 2016
1 parent 16bb802 commit 7ea3e4b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-expressions.js
Expand Up @@ -101,7 +101,7 @@ module.exports = {
}
}

return /^(?:Assignment|Call|New|Update|Yield)Expression$/.test(node.type) ||
return /^(?:Assignment|Call|New|Update|Yield|Await)Expression$/.test(node.type) ||
(node.type === "UnaryExpression" && ["delete", "void"].indexOf(node.operator) >= 0);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/no-unused-expressions.js
Expand Up @@ -42,6 +42,24 @@ ruleTester.run("no-unused-expressions", rule, {
{
code: "function* foo(){ yield 0; }",
parserOptions: { ecmaVersion: 6 }
},
{
code: "async function foo() { await 5; }",
parserOptions: { ecmaVersion: 8 }
},
{
code: "async function foo() { await foo.bar; }",
parserOptions: { ecmaVersion: 8 }
},
{
code: "async function foo() { bar && await baz; }",
options: [{ allowShortCircuit: true }],
parserOptions: { ecmaVersion: 8 }
},
{
code: "async function foo() { foo ? await bar : await baz; }",
options: [{ allowTernary: true }],
parserOptions: { ecmaVersion: 8 }
}
],
invalid: [
Expand Down

0 comments on commit 7ea3e4b

Please sign in to comment.