Skip to content

Commit

Permalink
no-await-expression-member: Fix crash on TypeScript parser (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 20, 2022
1 parent fde97ab commit b002e75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rules/no-await-expression-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const create = context => {
&& memberExpression.parent.type === 'VariableDeclarator'
&& memberExpression.parent.init === memberExpression
&& memberExpression.parent.id.type === 'Identifier'
&& !memberExpression.parent.id.typeAnnotation
) {
problem.fix = function * (fixer) {
const variable = memberExpression.parent.id;
Expand All @@ -52,6 +53,7 @@ const create = context => {
&& memberExpression.parent.init === memberExpression
&& memberExpression.parent.id.type === 'Identifier'
&& memberExpression.parent.id.name === property.name
&& !memberExpression.parent.id.typeAnnotation
) {
problem.fix = function * (fixer) {
const variable = memberExpression.parent.id;
Expand Down
11 changes: 10 additions & 1 deletion test/no-await-expression-member.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,14 @@ test.typescript({
valid: [
'function foo () {return (await promise) as string;}',
],
invalid: [],
invalid: [
{
code: 'const foo: Type = (await promise)[0]',
errors: 1,
},
{
code: 'const foo: Type | A = (await promise).foo',
errors: 1,
},
],
});

0 comments on commit b002e75

Please sign in to comment.