From 383f93182599c00e231a0f0d36575ca0e19369a6 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 29 Apr 2020 13:32:51 -0700 Subject: [PATCH] fix(eslint-plugin): [dot-notation] handle missing declarations (#1947) also minor perf improvement --- .../eslint-plugin/src/rules/dot-notation.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/eslint-plugin/src/rules/dot-notation.ts b/packages/eslint-plugin/src/rules/dot-notation.ts index fb710187d29..d1d848aa2ef 100644 --- a/packages/eslint-plugin/src/rules/dot-notation.ts +++ b/packages/eslint-plugin/src/rules/dot-notation.ts @@ -62,16 +62,17 @@ export default createRule({ return { MemberExpression(node: TSESTree.MemberExpression): void { - const objectSymbol = typeChecker.getSymbolAtLocation( - parserServices.esTreeNodeToTSNodeMap.get(node.property), - ); - - if ( - allowPrivateClassPropertyAccess && - objectSymbol?.declarations[0]?.modifiers?.[0].kind === + if (allowPrivateClassPropertyAccess && node.computed) { + // for perf reasons - only fetch the symbol if we have to + const objectSymbol = typeChecker.getSymbolAtLocation( + parserServices.esTreeNodeToTSNodeMap.get(node.property), + ); + if ( + objectSymbol?.getDeclarations()?.[0]?.modifiers?.[0].kind === ts.SyntaxKind.PrivateKeyword - ) { - return; + ) { + return; + } } rules.MemberExpression(node); },