Skip to content

Commit 0f3f645

Browse files
authoredDec 21, 2022
fix(ast-spec): correct some incorrect ast types (#6257)
* fix(ast-spec): correct some ast types * type error
1 parent ccd45d4 commit 0f3f645

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed
 

‎packages/ast-spec/src/expression/ArrayExpression/spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ import type { Expression } from '../../unions/Expression';
55

66
export interface ArrayExpression extends BaseNode {
77
type: AST_NODE_TYPES.ArrayExpression;
8-
elements: (Expression | SpreadElement)[];
8+
/**
9+
* an element will be `null` in the case of a sparse array: `[1, ,3]`
10+
*/
11+
elements: (Expression | SpreadElement | null)[];
912
}

‎packages/ast-spec/src/expression/MemberExpression/spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import type { AST_NODE_TYPES } from '../../ast-node-types';
22
import type { BaseNode } from '../../base/BaseNode';
33
import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec';
44
import type { Expression } from '../../unions/Expression';
5-
import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression';
65
import type { Identifier } from '../Identifier/spec';
76

87
interface MemberExpressionBase extends BaseNode {
9-
object: LeftHandSideExpression;
8+
object: Expression;
109
property: Expression | Identifier | PrivateIdentifier;
1110
computed: boolean;
1211
optional: boolean;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { MethodDefinition } from '../element/MethodDefinition/spec';
21
import type { Property } from '../element/Property/spec';
32
import type { SpreadElement } from '../element/SpreadElement/spec';
43

5-
export type ObjectLiteralElement = MethodDefinition | Property | SpreadElement;
4+
export type ObjectLiteralElement = Property | SpreadElement;
65

76
// TODO - breaking change remove this
87
export type ObjectLiteralElementLike = ObjectLiteralElement;

‎packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,11 @@ export default createRule<Options, MessageIds>({
197197
}
198198
}
199199

200-
function checkExpression(node: TSESTree.Node, isErrorTest: boolean): void {
201-
switch (node.type) {
200+
function checkExpression(
201+
node: TSESTree.Node | null,
202+
isErrorTest: boolean,
203+
): void {
204+
switch (node?.type) {
202205
case AST_NODE_TYPES.Literal:
203206
checkLiteral(node, isErrorTest);
204207
break;
@@ -478,7 +481,7 @@ export default createRule<Options, MessageIds>({
478481

479482
function checkValidTest(tests: TSESTree.ArrayExpression): void {
480483
for (const test of tests.elements) {
481-
switch (test.type) {
484+
switch (test?.type) {
482485
case AST_NODE_TYPES.ObjectExpression:
483486
// delegate object-style tests to the invalid checker
484487
checkInvalidTest(test, false);
@@ -546,7 +549,7 @@ export default createRule<Options, MessageIds>({
546549

547550
case 'invalid':
548551
for (const element of prop.value.elements) {
549-
if (element.type === AST_NODE_TYPES.ObjectExpression) {
552+
if (element?.type === AST_NODE_TYPES.ObjectExpression) {
550553
checkInvalidTest(element);
551554
}
552555
}
@@ -575,7 +578,7 @@ export default createRule<Options, MessageIds>({
575578
}
576579

577580
for (const errorElement of testProp.value.elements) {
578-
if (errorElement.type !== AST_NODE_TYPES.ObjectExpression) {
581+
if (errorElement?.type !== AST_NODE_TYPES.ObjectExpression) {
579582
continue;
580583
}
581584

‎packages/eslint-plugin/src/rules/no-unnecessary-condition.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,7 @@ export default createRule<Options, MessageId>({
568568
return false;
569569
}
570570

571-
function isOptionableExpression(
572-
node: TSESTree.LeftHandSideExpression,
573-
): boolean {
571+
function isOptionableExpression(node: TSESTree.Expression): boolean {
574572
const type = getNodeType(node);
575573
const isOwnNullable =
576574
node.type === AST_NODE_TYPES.MemberExpression

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default createRule({
4747
* Check if a given node is a string.
4848
* @param node The node to check.
4949
*/
50-
function isStringType(node: TSESTree.LeftHandSideExpression): boolean {
50+
function isStringType(node: TSESTree.Expression): boolean {
5151
const objectType = typeChecker.getTypeAtLocation(
5252
service.esTreeNodeToTSNodeMap.get(node),
5353
);

‎packages/eslint-plugin/src/rules/require-array-sort-compare.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default util.createRule<Options, MessageIds>({
5050
* Check if a given node is an array which all elements are string.
5151
* @param node
5252
*/
53-
function isStringArrayNode(node: TSESTree.LeftHandSideExpression): boolean {
53+
function isStringArrayNode(node: TSESTree.Expression): boolean {
5454
const type = checker.getTypeAtLocation(
5555
service.esTreeNodeToTSNodeMap.get(node),
5656
);

‎packages/typescript-estree/tests/lib/semanticInfo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ function testIsolatedFile(
365365
const declaration = (parseResult.ast.body[0] as TSESTree.VariableDeclaration)
366366
.declarations[0];
367367
const arrayMember = (declaration.init! as TSESTree.ArrayExpression)
368-
.elements[0];
368+
.elements[0]!;
369369
expect(parseResult).toHaveProperty('services.esTreeNodeToTSNodeMap');
370370

371371
// get corresponding TS node

0 commit comments

Comments
 (0)
Please sign in to comment.