8000 feat(typescript-estree): support private fields in-in syntax (#4075) · FDIM/typescript-eslint@939d8ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 939d8ea

Browse files
authored
feat(typescript-estree): support private fields in-in syntax (typescript-eslint#4075)
1 parent ae0fb5a commit 939d8ea

File tree

13 files changed

+640
-20
lines changed

13 files changed

+640
-20
lines changed

packages/ast-spec/src/base/BinaryExpressionBase.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/ast-spec/src/expression/AssignmentExpression/spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { AST_NODE_TYPES } from '../../ast-node-types';
2-
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
2+
import type { BaseNode } from '../../base/BaseNode';
3+
import type { Expression } from '../../unions/Expression';
34

4-
export interface AssignmentExpression extends BinaryExpressionBase {
5+
export interface AssignmentExpression extends BaseNode {
56
type: AST_NODE_TYPES.AssignmentExpression;
67
operator:
78
| '-='
@@ -20,4 +21,6 @@ export interface AssignmentExpression extends BinaryExpressionBase {
2021
| '>>>='
2122
| '|='
2223
| '||=';
24+
left: Expression;
25+
right: Expression;
2326
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { AST_NODE_TYPES } from '../../ast-node-types';
2-
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
2+
import type { BaseNode } from '../../base/BaseNode';
3+
import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec';
4+
import type { Expression } from '../../unions/Expression';
35

4-
export interface BinaryExpression extends BinaryExpressionBase {
6+
export interface BinaryExpression extends BaseNode {
57
type: AST_NODE_TYPES.BinaryExpression;
8+
operator: string;
9+
left: Expression | PrivateIdentifier;
10+
right: Expression;
611
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { AST_NODE_TYPES } from '../../ast-node-types';
2-
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
2+
import type { BaseNode } from '../../base/BaseNode';
3+
import type { Expression } from '../../unions/Expression';
34

4-
export interface LogicalExpression extends BinaryExpressionBase {
5+
export interface LogicalExpression extends BaseNode {
56
type: AST_NODE_TYPES.LogicalExpression;
67
operator: '??' | '&&' | '||';
8+
left: Expression;
9+
right: Expression;
710
}

packages/eslint-plugin/src/rules/no-base-to-string.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ export default util.createRule<Options, MessageIds>({
166166

167167
if (util.getTypeName(typeChecker, leftType) === 'string') {
168168
checkExpression(node.right, rightType);
169-
} else if (util.getTypeName(typeChecker, rightType) === 'string') {
169+
} else if (
170+
util.getTypeName(typeChecker, rightType) === 'string' &&
171+
node.left.type !== AST_NODE_TYPES.PrivateIdentifier
172+
) {
170173
checkExpression(node.left, leftType);
171174
}
172175
},

packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default util.createRule({
3838
node: TSESTree.BinaryExpression | TSESTree.AssignmentExpression,
3939
): void {
4040
function isLeftHandPrimaryExpression(
41-
node: TSESTree.Expression,
41+
node: TSESTree.Expression | TSESTree.PrivateIdentifier,
4242
): boolean {
4343
return node.type === AST_NODE_TYPES.TSNonNullExpression;
4444
}

packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Options = [
2121
];
2222

2323
interface BooleanComparison {
24-
expression: TSESTree.Expression;
24+
expression: TSESTree.Expression | TSESTree.PrivateIdentifier;
2525
literalBooleanInComparison: boolean;
2626
forTruthy: boolean;
2727
negated: boolean;

packages/eslint-plugin/src/rules/prefer-for-of.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export default util.createRule({
3333
);
3434
}
3535

36-
function isLiteral(node: TSESTree.Expression, value: number): boolean {
36+
function isLiteral(
37+
node: TSESTree.Expression | TSESTree.PrivateIdentifier,
38+
value: number,
39+
): boolean {
3740
return node.type === AST_NODE_TYPES.Literal && node.value === value;
3841
}
3942

packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ export default createRule({
286286
return { isEndsWith, isStartsWith, text };
287287
}
288288

289-
function getLeftNode(node: TSESTree.Expression): TSESTree.MemberExpression {
289+
function getLeftNode(
290+
node: TSESTree.Expression | TSESTree.PrivateIdentifier,
291+
): TSESTree.MemberExpression {
290292
if (node.type === AST_NODE_TYPES.ChainExpression) {
291293
return getLeftNode(node.expression);
292294
}

packages/eslint-plugin/src/rules/restrict-plus-operands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export default util.createRule<Options, MessageIds>({
9393
* Helper function to get base type of node
9494
* @param node the node to be evaluated.
9595
*/
96-
function getNodeType(node: TSESTree.Expression): BaseLiteral {
96+
function getNodeType(
97+
node: TSESTree.Expression | TSESTree.PrivateIdentifier,
98+
): BaseLiteral {
9799
const tsNode = service.esTreeNodeToTSNodeMap.get(node);
98100
const type = util.getConstrainedTypeAtLocation(typeChecker, tsNode);
99101

0 commit comments

Comments
 (0)
0