From b002e75f904f31ee37e67e00891ce46785d0feea Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 20 Sep 2022 22:17:55 +0800 Subject: [PATCH] `no-await-expression-member`: Fix crash on TypeScript parser (#1910) --- rules/no-await-expression-member.js | 2 ++ test/no-await-expression-member.mjs | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rules/no-await-expression-member.js b/rules/no-await-expression-member.js index e3b872d7e7..93d62b9090 100644 --- a/rules/no-await-expression-member.js +++ b/rules/no-await-expression-member.js @@ -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; @@ -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; diff --git a/test/no-await-expression-member.mjs b/test/no-await-expression-member.mjs index 231894ed39..704de1f419 100644 --- a/test/no-await-expression-member.mjs +++ b/test/no-await-expression-member.mjs @@ -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, + }, + ], });