Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: require-await crash on global await (#12571)
  • Loading branch information
bradzacher authored and platinumazure committed Nov 15, 2019
1 parent b8030fc commit fed20bb
Show file tree
Hide file tree
Showing 4 changed files with 655 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rules/require-await.js
Expand Up @@ -89,9 +89,17 @@ module.exports = {
"ArrowFunctionExpression:exit": exitFunction,

AwaitExpression() {
if (!scopeInfo) {
return;
}

scopeInfo.hasAwait = true;
},
ForOfStatement(node) {
if (!scopeInfo) {
return;
}

if (node.await) {
scopeInfo.hasAwait = true;
}
Expand Down
162 changes: 162 additions & 0 deletions tests/fixtures/parsers/typescript-parsers/global-await.js
@@ -0,0 +1,162 @@
"use strict";

/**
* Parser: @typescript-eslint/parser v2.6.1
* Source code:
* await foo();
*/

exports.parse = () => ({
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "AwaitExpression",
argument: {
type: "CallExpression",
callee: {
type: "Identifier",
name: "foo",
range: [6, 9],
loc: {
start: {
line: 1,
column: 6
},
end: {
line: 1,
column: 9
}
}
},
arguments: [],
optional: false,
range: [6, 11],
loc: {
start: {
line: 1,
column: 6
},
end: {
line: 1,
column: 11
}
}
},
range: [0, 11],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 11
}
}
},
range: [0, 12],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 12
}
}
}
],
sourceType: "module",
range: [0, 12],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 12
}
},
tokens: [
{
type: "Identifier",
value: "await",
range: [0, 5],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 5
}
}
},
{
type: "Identifier",
value: "foo",
range: [6, 9],
loc: {
start: {
line: 1,
column: 6
},
end: {
line: 1,
column: 9
}
}
},
{
type: "Punctuator",
value: "(",
range: [9, 10],
loc: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 10
}
}
},
{
type: "Punctuator",
value: ")",
range: [10, 11],
loc: {
start: {
line: 1,
column: 10
},
end: {
line: 1,
column: 11
}
}
},
{
type: "Punctuator",
value: ";",
range: [11, 12],
loc: {
start: {
line: 1,
column: 11
},
end: {
line: 1,
column: 12
}
}
}
],
comments: []
});

0 comments on commit fed20bb

Please sign in to comment.