diff --git a/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts b/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts index 429b5a59cee6..a7db43689a7b 100644 --- a/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts +++ b/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts @@ -37,7 +37,6 @@ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( const getPropertyName = eslintUtils.getPropertyName as ( node: | TSESTree.MemberExpression - | TSESTree.OptionalMemberExpression | TSESTree.Property | TSESTree.MethodDefinition, initialScope?: TSESLint.Scope.Scope, diff --git a/packages/experimental-utils/src/ast-utils/predicates.ts b/packages/experimental-utils/src/ast-utils/predicates.ts index b12f5d9ad6fc..c23f30f17077 100644 --- a/packages/experimental-utils/src/ast-utils/predicates.ts +++ b/packages/experimental-utils/src/ast-utils/predicates.ts @@ -25,11 +25,11 @@ function isNotNonNullAssertionPunctuator( /** * Returns true if and only if the node represents: foo?.() or foo.bar?.() */ -function isOptionalOptionalCallExpression( +function isOptionalCallExpression( node: TSESTree.Node, -): node is TSESTree.OptionalCallExpression & { optional: true } { +): node is TSESTree.CallExpression & { optional: true } { return ( - node.type === AST_NODE_TYPES.OptionalCallExpression && + node.type === AST_NODE_TYPES.CallExpression && // this flag means the call expression itself is option // i.e. it is foo.bar?.() and not foo?.bar() node.optional @@ -214,15 +214,6 @@ function isAwaitKeyword( return node?.type === AST_TOKEN_TYPES.Identifier && node.value === 'await'; } -function isMemberOrOptionalMemberExpression( - node: TSESTree.Node, -): node is TSESTree.MemberExpression | TSESTree.OptionalMemberExpression { - return ( - node.type === AST_NODE_TYPES.MemberExpression || - node.type === AST_NODE_TYPES.OptionalMemberExpression - ); -} - export { isAwaitExpression, isAwaitKeyword, @@ -233,12 +224,11 @@ export { isFunctionType, isIdentifier, isLogicalOrOperator, - isMemberOrOptionalMemberExpression, isNonNullAssertionPunctuator, isNotNonNullAssertionPunctuator, isNotOptionalChainPunctuator, isOptionalChainPunctuator, - isOptionalOptionalCallExpression, + isOptionalCallExpression, isSetter, isTSConstructorType, isTSFunctionType, diff --git a/packages/experimental-utils/src/ts-eslint/Rule.ts b/packages/experimental-utils/src/ts-eslint/Rule.ts index 287ea3f43692..d305b29125b9 100644 --- a/packages/experimental-utils/src/ts-eslint/Rule.ts +++ b/packages/experimental-utils/src/ts-eslint/Rule.ts @@ -258,6 +258,7 @@ interface RuleListener { BreakStatement?: RuleFunction; CallExpression?: RuleFunction; CatchClause?: RuleFunction; + ChainExpression?: RuleFunction; ClassBody?: RuleFunction; ClassDeclaration?: RuleFunction; ClassExpression?: RuleFunction; @@ -309,8 +310,6 @@ interface RuleListener { NewExpression?: RuleFunction; ObjectExpression?: RuleFunction; ObjectPattern?: RuleFunction; - OptionalCallExpression?: RuleFunction; - OptionalMemberExpression?: RuleFunction; Program?: RuleFunction; Property?: RuleFunction; RestElement?: RuleFunction; diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index 2b6a7420c862..b2b9f056311a 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -341,29 +341,6 @@ class Referencer extends TSESLintScope.Referencer { node.arguments.forEach(this.visit, this); } - /** - * Visit optional member expression. - * @param node The OptionalMemberExpression node to visit. - */ - OptionalMemberExpression(node: TSESTree.OptionalMemberExpression): void { - this.visit(node.object); - if (node.computed) { - this.visit(node.property); - } - } - - /** - * Visit optional call expression. - * @param node The OptionalMemberExpression node to visit. - */ - OptionalCallExpression(node: TSESTree.OptionalCallExpression): void { - this.visitTypeParameters(node); - - this.visit(node.callee); - - node.arguments.forEach(this.visit, this); - } - /** * Define the variable of this function declaration only once. * Because to avoid confusion of `no-redeclare` rule by overloading. diff --git a/packages/scope-manager/src/referencer/Referencer.ts b/packages/scope-manager/src/referencer/Referencer.ts index d3d13982340f..302dda1c4574 100644 --- a/packages/scope-manager/src/referencer/Referencer.ts +++ b/packages/scope-manager/src/referencer/Referencer.ts @@ -377,9 +377,7 @@ class Referencer extends Visitor { // don't reference the break statement's label } - protected CallExpression( - node: TSESTree.CallExpression | TSESTree.OptionalCallExpression, - ): void { + protected CallExpression(node: TSESTree.CallExpression): void { this.visitChildren(node, ['typeParameters']); this.visitType(node.typeParameters); } @@ -498,9 +496,7 @@ class Referencer extends Visitor { this.visit(node.body); } - protected MemberExpression( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { + protected MemberExpression(node: TSESTree.MemberExpression): void { this.visit(node.object); if (node.computed) { this.visit(node.property); @@ -520,18 +516,6 @@ class Referencer extends Visitor { this.visitType(node.typeParameters); } - protected OptionalCallExpression( - node: TSESTree.OptionalCallExpression, - ): void { - this.CallExpression(node); - } - - protected OptionalMemberExpression( - node: TSESTree.OptionalMemberExpression, - ): void { - this.MemberExpression(node); - } - protected Program(node: TSESTree.Program): void { const globalScope = this.scopeManager.nestGlobalScope(node); this.populateGlobalsFromLib(globalScope); diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index 0a4e9e164fa0..a4e3534d0e26 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -36,10 +36,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "eslint-visitor-keys": "^1.1.0" - }, - "devDependencies": { - "@typescript-eslint/types": "3.6.1" + "@typescript-eslint/types": "3.6.1", + "eslint-visitor-keys": "^1.3.0" }, "funding": { "type": "opencollective", diff --git a/packages/visitor-keys/src/get-keys.ts b/packages/visitor-keys/src/get-keys.ts new file mode 100644 index 000000000000..f1219ca196a2 --- /dev/null +++ b/packages/visitor-keys/src/get-keys.ts @@ -0,0 +1,6 @@ +import { TSESTree } from '@typescript-eslint/types'; +import { getKeys as getKeysOriginal } from 'eslint-visitor-keys'; + +const getKeys: (node: TSESTree.Node) => ReadonlyArray = getKeysOriginal; + +export { getKeys }; diff --git a/packages/visitor-keys/src/index.ts b/packages/visitor-keys/src/index.ts index 24571eff0c33..04aa65158635 100644 --- a/packages/visitor-keys/src/index.ts +++ b/packages/visitor-keys/src/index.ts @@ -1 +1,2 @@ +export { getKeys } from './get-keys'; export { visitorKeys, VisitorKeys } from './visitor-keys'; diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 66b7db0ea136..6ba772034020 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -48,8 +48,6 @@ const visitorKeys: VisitorKeys = eslintVisitorKeys.unionWith({ // Additional Nodes. ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], Decorator: ['expression'], - OptionalCallExpression: ['callee', 'typeParameters', 'arguments'], - OptionalMemberExpression: eslintVisitorKeys.KEYS.MemberExpression, TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], TSAbstractKeyword: [], TSAbstractMethodDefinition: ['key', 'value'], diff --git a/yarn.lock b/yarn.lock index 2a4e539b470e..102d3a50f9a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3667,6 +3667,11 @@ eslint-visitor-keys@^1.2.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa" integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ== +eslint-visitor-keys@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" + integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== + eslint@^7.2.0: version "7.2.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6"