Skip to content

Commit 8bd5f8e

Browse files
authored
Clean up the code structure of the AST utils and fix an issue where isNodeEqual did not handle as expressions correctly, closes #1340 (#1341)
1 parent b9ab289 commit 8bd5f8e

24 files changed

+98
-72
lines changed

packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,39 @@ ruleTester.run(RULE_NAME, rule, {
689689
}, []);
690690
}
691691
`,
692+
tsx`
693+
function Example() {
694+
useEffect(() => {
695+
const handleResize = () => {};
696+
window.addEventListener("resize", handleResize as EventListener);
697+
return () => {
698+
window.removeEventListener("resize", handleResize as EventListener);
699+
};
700+
}, []);
701+
}
702+
`,
703+
tsx`
704+
function Example() {
705+
useEffect(() => {
706+
const handleResize = () => {};
707+
window.addEventListener("resize", handleResize as EventListener);
708+
return () => {
709+
window.removeEventListener("resize", handleResize);
710+
};
711+
}, []);
712+
}
713+
`,
714+
tsx`
715+
function Example() {
716+
useEffect(() => {
717+
const handleResize = () => {};
718+
window.addEventListener("resize", handleResize);
719+
return () => {
720+
window.removeEventListener("resize", handleResize as EventListener);
721+
};
722+
}, []);
723+
}
724+
`,
692725
tsx`
693726
function Example() {
694727
useEffect(() => {

packages/utilities/ast/src/__tests__/class.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { describe, expect, it } from "vitest";
77
import { getFixturesRootDir } from "../../../../../test";
88

99
import { getClassId } from "../class-id";
10-
import type { TSESTreeClass } from "../node";
10+
import type { TSESTreeClass } from "../node-types";
1111

1212
function parse(code: string) {
1313
return parseForESLint(code, {

packages/utilities/ast/src/__tests__/expression.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import path from "node:path";
77
import { describe, expect, it } from "vitest";
88

99
import { getFixturesRootDir } from "../../../../../test";
10-
import { getNestedReturnStatements } from "../expression";
11-
import { type TSESTreeFunction, isFunction } from "../node";
10+
11+
import { getNestedReturnStatements } from "../expression-nested";
12+
import { isFunction } from "../node-is";
13+
import type { TSESTreeFunction } from "../node-types";
1214

1315
function parse(code: string) {
1416
return parseForESLint(code, {

packages/utilities/ast/src/__tests__/function.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { describe, expect, it } from "vitest";
77
import { getFixturesRootDir } from "../../../../../test";
88

99
import { getFunctionId } from "../function-id";
10-
import { type TSESTreeFunction, isFunction } from "../node";
10+
import { isFunction } from "../node-is";
11+
import type { TSESTreeFunction } from "../node-types";
1112

1213
function parse(code: string) {
1314
return parseForESLint(code, {

packages/utilities/ast/src/array.ts

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

packages/utilities/ast/src/class-id.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { unit } from "@eslint-react/eff";
22
import type { TSESTree } from "@typescript-eslint/types";
3-
import type { TSESTreeClass } from "./node";
4-
53
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
64

5+
import type { TSESTreeClass } from "./node-types";
6+
77
export function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit {
88
if (node.id != null) return node.id;
99
if (node.parent.type === T.VariableDeclarator && node.parent.id.type === T.Identifier) {

packages/utilities/ast/src/expression-base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { TSESTree } from "@typescript-eslint/types";
2-
import { type TSESTreeTypeExpression, isTypeExpression } from "./node";
2+
3+
import { isTypeExpression } from "./node-is";
4+
import type { TSESTreeTypeExpression } from "./node-types";
35

46
/**
57
* Unwraps any type expressions to get the underlying JavaScript expression node.

packages/utilities/ast/src/expression-is.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TSESTree } from "@typescript-eslint/types";
2-
32
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
3+
44
import { getUnderlyingExpression } from "./expression-base";
55

66
/**

packages/utilities/ast/src/expression-nested.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { TSESTree } from "@typescript-eslint/types";
22
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
33
import { simpleTraverse } from "@typescript-eslint/typescript-estree";
4-
import { is, isFunction } from "./node";
4+
5+
import { is, isFunction } from "./node-is";
56
import { findParentNode } from "./traverse";
67

78
/**

packages/utilities/ast/src/expression.ts

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

0 commit comments

Comments
 (0)