Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): support private fields in-in syntax #4075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/ast-spec/src/base/BinaryExpressionBase.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/ast-spec/src/expression/AssignmentExpression/spec.ts
@@ -1,7 +1,8 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
import type { BaseNode } from '../../base/BaseNode';
import type { Expression } from '../../unions/Expression';

export interface AssignmentExpression extends BinaryExpressionBase {
export interface AssignmentExpression extends BaseNode {
type: AST_NODE_TYPES.AssignmentExpression;
operator:
| '-='
Expand All @@ -20,4 +21,6 @@ export interface AssignmentExpression extends BinaryExpressionBase {
| '>>>='
| '|='
| '||=';
left: Expression;
right: Expression;
}
9 changes: 7 additions & 2 deletions packages/ast-spec/src/expression/BinaryExpression/spec.ts
@@ -1,6 +1,11 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
import type { BaseNode } from '../../base/BaseNode';
import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec';
import type { Expression } from '../../unions/Expression';

export interface BinaryExpression extends BinaryExpressionBase {
export interface BinaryExpression extends BaseNode {
type: AST_NODE_TYPES.BinaryExpression;
operator: string;
left: Expression | PrivateIdentifier;
right: Expression;
}
7 changes: 5 additions & 2 deletions packages/ast-spec/src/expression/LogicalExpression/spec.ts
@@ -1,7 +1,10 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase';
import type { BaseNode } from '../../base/BaseNode';
import type { Expression } from '../../unions/Expression';

export interface LogicalExpression extends BinaryExpressionBase {
export interface LogicalExpression extends BaseNode {
type: AST_NODE_TYPES.LogicalExpression;
operator: '??' | '&&' | '||';
left: Expression;
right: Expression;
}
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/no-base-to-string.ts
Expand Up @@ -166,7 +166,10 @@ export default util.createRule<Options, MessageIds>({

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);
}
},
Expand Down
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ type Options = [
];

interface BooleanComparison {
expression: TSESTree.Expression;
expression: TSESTree.Expression | TSESTree.PrivateIdentifier;
literalBooleanInComparison: boolean;
forTruthy: boolean;
negated: boolean;
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/prefer-for-of.ts
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/rules/restrict-plus-operands.ts
Expand Up @@ -93,7 +93,9 @@ export default util.createRule<Options, MessageIds>({
* 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);

Expand Down
@@ -0,0 +1,6 @@
class Foo {
#prop1;
method(arg) {
return #prop1 in arg;
}
}
Expand Up @@ -2072,6 +2072,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/parenthesized-use-strict.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/private-fields-in-in.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/readonly-arrays.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/readonly-tuples.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down