diff --git a/packages/ast-spec/src/expression/AssignmentExpression/spec.ts b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts index 8d76be21bdcc..e8b20fd46b5b 100644 --- a/packages/ast-spec/src/expression/AssignmentExpression/spec.ts +++ b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts @@ -1,5 +1,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; +import type { Expression } from '../../unions/Expression'; export interface AssignmentExpression extends BinaryExpressionBase { type: AST_NODE_TYPES.AssignmentExpression; @@ -20,4 +21,5 @@ export interface AssignmentExpression extends BinaryExpressionBase { | '>>>=' | '|=' | '||='; + left: Expression; } diff --git a/packages/ast-spec/src/expression/BinaryExpression/spec.ts b/packages/ast-spec/src/expression/BinaryExpression/spec.ts index 5df33cc3e16a..fc14f981b8ec 100644 --- a/packages/ast-spec/src/expression/BinaryExpression/spec.ts +++ b/packages/ast-spec/src/expression/BinaryExpression/spec.ts @@ -1,6 +1,9 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; +import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec'; +import type { Expression } from '../../unions/Expression'; export interface BinaryExpression extends BinaryExpressionBase { type: AST_NODE_TYPES.BinaryExpression; + left: Expression | PrivateIdentifier; } diff --git a/packages/ast-spec/src/expression/LogicalExpression/spec.ts b/packages/ast-spec/src/expression/LogicalExpression/spec.ts index 6d2b56b50dd4..786ad815bf11 100644 --- a/packages/ast-spec/src/expression/LogicalExpression/spec.ts +++ b/packages/ast-spec/src/expression/LogicalExpression/spec.ts @@ -1,7 +1,9 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; +import type { Expression } from '../../unions/Expression'; export interface LogicalExpression extends BinaryExpressionBase { type: AST_NODE_TYPES.LogicalExpression; operator: '??' | '&&' | '||'; + left: Expression; } diff --git a/packages/eslint-plugin/src/rules/no-base-to-string.ts b/packages/eslint-plugin/src/rules/no-base-to-string.ts index 11962363c642..644bb88152a5 100644 --- a/packages/eslint-plugin/src/rules/no-base-to-string.ts +++ b/packages/eslint-plugin/src/rules/no-base-to-string.ts @@ -166,7 +166,10 @@ export default util.createRule({ if (util.getTypeName(typeChecker, leftType) === 'string') { checkExpression(node.right, rightType); - } else if (util.getTypeName(typeChecker, rightType) === 'string') { + } else if ( + util.getTypeName(typeChecker, rightType) === 'string' && + node.left.type !== AST_NODE_TYPES.PrivateIdentifier + ) { checkExpression(node.left, leftType); } }, diff --git a/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts index f578c5d3a1da..1535a6433978 100644 --- a/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts @@ -38,7 +38,7 @@ export default util.createRule({ node: TSESTree.BinaryExpression | TSESTree.AssignmentExpression, ): void { function isLeftHandPrimaryExpression( - node: TSESTree.Expression, + node: TSESTree.Expression | TSESTree.PrivateIdentifier, ): boolean { return node.type === AST_NODE_TYPES.TSNonNullExpression; } diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts index 8583e657f915..41367d4115b6 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts @@ -21,7 +21,7 @@ type Options = [ ]; interface BooleanComparison { - expression: TSESTree.Expression; + expression: TSESTree.Expression | TSESTree.PrivateIdentifier; literalBooleanInComparison: boolean; forTruthy: boolean; negated: boolean; diff --git a/packages/eslint-plugin/src/rules/prefer-for-of.ts b/packages/eslint-plugin/src/rules/prefer-for-of.ts index f00868d04097..e1c3a0580166 100644 --- a/packages/eslint-plugin/src/rules/prefer-for-of.ts +++ b/packages/eslint-plugin/src/rules/prefer-for-of.ts @@ -33,7 +33,10 @@ export default util.createRule({ ); } - function isLiteral(node: TSESTree.Expression, value: number): boolean { + function isLiteral( + node: TSESTree.Expression | TSESTree.PrivateIdentifier, + value: number, + ): boolean { return node.type === AST_NODE_TYPES.Literal && node.value === value; } diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index c90bb0a1a746..9bf63c08431a 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -286,7 +286,9 @@ export default createRule({ return { isEndsWith, isStartsWith, text }; } - function getLeftNode(node: TSESTree.Expression): TSESTree.MemberExpression { + function getLeftNode( + node: TSESTree.Expression | TSESTree.PrivateIdentifier, + ): TSESTree.MemberExpression { if (node.type === AST_NODE_TYPES.ChainExpression) { return getLeftNode(node.expression); } diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 51b4da9be466..30c155e3dcde 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -93,7 +93,9 @@ export default util.createRule({ * Helper function to get base type of node * @param node the node to be evaluated. */ - function getNodeType(node: TSESTree.Expression): BaseLiteral { + function getNodeType( + node: TSESTree.Expression | TSESTree.PrivateIdentifier, + ): BaseLiteral { const tsNode = service.esTreeNodeToTSNodeMap.get(node); const type = util.getConstrainedTypeAtLocation(typeChecker, tsNode);