diff --git a/src/components/options.tsx b/src/components/options.tsx index 2a8c893..f7d7209 100644 --- a/src/components/options.tsx +++ b/src/components/options.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-handler-names */ 'use client'; import { diff --git a/src/lib/code-path-stack.ts b/src/lib/code-path-stack.ts index eddf5b9..e5204fd 100644 --- a/src/lib/code-path-stack.ts +++ b/src/lib/code-path-stack.ts @@ -1,7 +1,23 @@ -// @ts-nocheck -/* eslint-disable */ +interface CodePathSegment { + id: string; + allNextSegments: CodePathSegment[]; + returned: boolean; + thrown: boolean; + reachable: boolean; +} + +interface CodePath { + initialSegment: CodePathSegment; + returnedSegments: CodePathSegment[]; + thrownSegments: CodePathSegment[]; +} -const nodeToString = (node, label) => { +interface CodePathSegmentInfo { + segment: CodePathSegment; + nodes: string[]; +} + +const nodeToString = (node: any, label?: string): string => { const event = label ? `:${label}` : ''; switch (node.type) { @@ -18,37 +34,31 @@ const nodeToString = (node, label) => { }; export class CodePathStack { - /** - * @param {Rule.CodePath} codePath - * @param {CodePathStack|null} upper - * @param {ESTree.Node} node - */ - constructor(codePath, upper, node) { + codePath: CodePath; + upper: CodePathStack | null; + startNode: any; + currentSegments: Map; + allSegments: Map; + + constructor(codePath: CodePath, upper: CodePathStack | null, node: any) { this.codePath = codePath; this.upper = upper; this.startNode = node; - /** - * @type {Map} - */ this.currentSegments = new Map(); - - /** - * @type {Map} - */ this.allSegments = new Map(); } - getSegment(segment) { + getSegment(segment: CodePathSegment): CodePathSegmentInfo | undefined { return this.allSegments.get(segment); } - getAllSegments() { + getAllSegments(): IterableIterator { return this.allSegments.values(); } - enterSegment(segment) { - const info = { + enterSegment(segment: CodePathSegment): void { + const info: CodePathSegmentInfo = { segment, nodes: [], }; @@ -57,17 +67,17 @@ export class CodePathStack { this.allSegments.set(segment, info); } - exitSegment(segment) { + exitSegment(segment: CodePathSegment): void { this.currentSegments.delete(segment); } - enterNode(node) { + enterNode(node: any): void { for (const codePathSegment of this.currentSegments.values()) { codePathSegment.nodes.push(nodeToString(node, 'enter')); } } - exitNode(node) { + exitNode(node: any): void { for (const codePathSegment of this.currentSegments.values()) { const last = codePathSegment.nodes.length - 1; @@ -75,7 +85,7 @@ export class CodePathStack { last >= 0 && codePathSegment.nodes[last] === nodeToString(node, 'enter') ) { - codePathSegment.nodes[last] = nodeToString(node, void 0); + codePathSegment.nodes[last] = nodeToString(node, undefined); } else { codePathSegment.nodes.push(nodeToString(node, 'exit')); } diff --git a/src/lib/generate-code-path.ts b/src/lib/generate-code-path.ts index a472e6a..8ed32fe 100644 --- a/src/lib/generate-code-path.ts +++ b/src/lib/generate-code-path.ts @@ -1,20 +1,17 @@ -// @ts-nocheck -/* eslint-disable */ - 'use server'; import { Linter } from 'eslint-linter-browserify'; import { CodePathStack } from '@/lib/code-path-stack'; import type { SourceType, Version } from '@/hooks/use-explorer'; -const makeDotArrows = (codePath) => { +const makeDotArrows = (codePath: any) => { const stack = [{ segment: codePath.initialSegment, index: 0 }]; - const done = Object.create(null); + const done: Record = Object.create(null); let lastId = codePath.initialSegment.id; let text = `initial->${codePath.initialSegment.id}`; while (stack.length > 0) { - const { segment, index } = stack.pop(); + const { segment, index } = stack.pop()!; if (done[segment.id] && index === 0) { continue; @@ -62,19 +59,18 @@ export const generateCodePath = async ( sourceType: SourceType ): Promise< | { - error: string; - } + error: string; + } | { - response: string; - } - // eslint-disable-next-line @typescript-eslint/require-await + response: string; + } > => { const linter = new Linter({ configType: 'flat' }); let stack: CodePathStack | null = null; - const allCodePaths = []; + const allCodePaths: CodePathStack[] = []; - const config = { + const config: any = { files: ['**/*.js', '*.js'], plugins: { 'code-path': { @@ -82,36 +78,30 @@ export const generateCodePath = async ( 'extract-code-path': { create() { return { - onCodePathStart(codePath, node) { + onCodePathStart(codePath: any, node: any) { stack = new CodePathStack(codePath, stack, node); allCodePaths.push(stack); }, onCodePathEnd() { - stack = stack.upper || null; + stack = stack?.upper || null; }, - onCodePathSegmentStart(segment) { - stack.enterSegment(segment); + onCodePathSegmentStart(segment: any) { + stack?.enterSegment(segment); }, - onUnreachableCodePathSegmentStart(segment) { - stack.enterSegment(segment); + onUnreachableCodePathSegmentStart(segment: any) { + stack?.enterSegment(segment); }, - onCodePathSegmentEnd(segment) { - stack.exitSegment(segment); + onCodePathSegmentEnd(segment: any) { + stack?.exitSegment(segment); }, - onUnreachableCodePathSegmentEnd(segment) { - stack.exitSegment(segment); + onUnreachableCodePathSegmentEnd(segment: any) { + stack?.exitSegment(segment); }, - '*'(node) { - if (!stack) { - return; - } - stack.enterNode(node); + '*'(node: any) { + stack?.enterNode(node); }, - '*:exit'(node) { - if (!stack) { - return; - } - stack.exitNode(node); + '*:exit'(node: any) { + stack?.exitNode(node); }, }; }, @@ -141,7 +131,7 @@ export const generateCodePath = async ( } } catch (error) { return { - error: error.message, + error: (error as Error).message, }; } @@ -189,4 +179,4 @@ export const generateCodePath = async ( }; return { response: JSON.stringify(response, null, 2) }; -}; \ No newline at end of file +}; diff --git a/tsconfig.json b/tsconfig.json index 3b425bd..3150c65 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "target": "es5", + "downlevelIteration": true, "lib": [ "dom", "dom.iterable",