Skip to content

Commit

Permalink
Skip unresolved references in createReferenceMap
Browse files Browse the repository at this point in the history
  • Loading branch information
patriscus committed May 1, 2021
1 parent 89ae3ce commit b9728e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rules/require-atomic-updates.js
Expand Up @@ -13,6 +13,10 @@
*/
function createReferenceMap(scope, outReferenceMap = new Map()) {
for (const reference of scope.references) {
if (reference.resolved === null) {
continue;
}

outReferenceMap.set(reference.identifier, reference);
}
for (const childScope of scope.childScopes) {
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/rules/require-atomic-updates.js
Expand Up @@ -53,6 +53,7 @@ ruleTester.run("require-atomic-updates", rule, {
"let foo; async function x() { foo = condition ? foo : await bar; }",
"async function x() { let foo; bar(() => { let foo; blah(foo); }); foo += await result; }",
"let foo; async function x() { foo = foo + 1; await bar; }",
"async function x() { foo += await bar; }",


/*
Expand Down Expand Up @@ -201,6 +202,13 @@ ruleTester.run("require-atomic-updates", rule, {
entry = 1;
}
}
`,

`
async function run() {
await a;
b = 1;
}
`
],

Expand Down Expand Up @@ -290,7 +298,7 @@ ruleTester.run("require-atomic-updates", rule, {
errors: [COMPUTED_PROPERTY_ERROR, STATIC_PROPERTY_ERROR]
},
{
code: "async function x() { foo += await bar; }",
code: "let foo = ''; async function x() { foo += await bar; }",
errors: [VARIABLE_ERROR]
},
{
Expand Down

0 comments on commit b9728e9

Please sign in to comment.