Skip to content

Commit 92cfb14

Browse files
committed
fix(linter/plugins): fix types for walkProgram and walkProgramWithCfg (#20081)
Fix a mistake in our (internal) types: `walkProgramWithCfg` was missing that elements can be `CfgVisitFn`. Also refactor the types for `walkProgram`, importing the original `VisitFn` and `EnterExit` types from where they're defined.
1 parent 7365886 commit 92cfb14

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

apps/oxlint/src-js/generated/walk.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/estree_visit.rs`.
33

44
import type { Node, Program } from "./types.d.ts";
5+
import type { VisitFn, EnterExit } from "../plugins/visitor.ts";
56

6-
type VisitFn = ((node: Node) => void) | null;
7-
type EnterExitVisitor = { enter: VisitFn; exit: VisitFn } | null;
8-
type CompiledVisitors = (VisitFn | EnterExitVisitor)[];
7+
type CompiledVisitors = (VisitFn | EnterExit | null)[];
98

109
export declare function walkProgram(program: Program, visitors: CompiledVisitors): void;
1110
export declare const ancestors: Node[];

apps/oxlint/src-js/plugins/cfg.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import {
1717
import { ancestors } from "../generated/walk.js";
1818
import { debugAssert, debugAssertIsFunction } from "../utils/asserts.ts";
1919

20-
import type { CfgVisitFn, EnterExit } from "./visitor.ts";
20+
import type { CfgVisitFn, EnterExit, VisitFn } from "./visitor.ts";
2121
import type { Node, Program } from "../generated/types.d.ts";
22-
import type { CompiledVisitors } from "../generated/walk.js";
2322

2423
/**
2524
* Offset added to type IDs for exit visits to distinguish them from enter visits.
@@ -89,7 +88,10 @@ export function resetCfgWalk(): void {
8988
* @param ast - AST
9089
* @param visitors - Visitors array
9190
*/
92-
export function walkProgramWithCfg(ast: Program, visitors: CompiledVisitors): void {
91+
export function walkProgramWithCfg(
92+
ast: Program,
93+
visitors: (VisitFn | EnterExit | CfgVisitFn | null)[],
94+
): void {
9395
// Get the steps that need to be run to walk the AST
9496
prepareSteps(ast);
9597

napi/parser/src-js/generated/visit/walk.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import type * as ESTree from "@oxc-project/types";
55

6-
type VisitFn = ((node: ESTree.Node) => void) | null;
7-
type EnterExitVisitor = { enter: VisitFn; exit: VisitFn } | null;
8-
type CompiledVisitors = (VisitFn | EnterExitVisitor)[];
6+
type VisitFn = (node: ESTree.Node) => void;
7+
type EnterExit = { enter: VisitFn; exit: VisitFn };
8+
type CompiledVisitors = (VisitFn | EnterExit | null)[];
99

1010
export declare function walkProgram(program: ESTree.Program, visitors: CompiledVisitors): void;

tasks/ast_tools/src/generators/estree_visit.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,9 @@ fn generate(codegen: &Codegen) -> Codes {
535535
let walk_dts_parser = "
536536
import type * as ESTree from '@oxc-project/types';
537537
538-
type VisitFn = ((node: ESTree.Node) => void) | null;
539-
type EnterExitVisitor = { enter: VisitFn; exit: VisitFn } | null;
540-
type CompiledVisitors = (VisitFn | EnterExitVisitor)[];
538+
type VisitFn = (node: ESTree.Node) => void;
539+
type EnterExit = { enter: VisitFn; exit: VisitFn };
540+
type CompiledVisitors = (VisitFn | EnterExit | null)[];
541541
542542
export declare function walkProgram(program: ESTree.Program, visitors: CompiledVisitors): void;
543543
".to_string();
@@ -550,10 +550,9 @@ fn generate(codegen: &Codegen) -> Codes {
550550
#[rustfmt::skip]
551551
let walk_dts_oxlint = "
552552
import type { Node, Program } from './types.d.ts';
553+
import type { VisitFn, EnterExit } from '../plugins/visitor.ts';
553554
554-
type VisitFn = ((node: Node) => void) | null;
555-
type EnterExitVisitor = { enter: VisitFn; exit: VisitFn } | null;
556-
type CompiledVisitors = (VisitFn | EnterExitVisitor)[];
555+
type CompiledVisitors = (VisitFn | EnterExit | null)[];
557556
558557
export declare function walkProgram(program: Program, visitors: CompiledVisitors): void;
559558
export declare const ancestors: Node[];

0 commit comments

Comments
 (0)