Skip to content

Commit

Permalink
chore: fix typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 26, 2024
1 parent 368f145 commit 2a34ec4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/detect-acorn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { BlockStatement, Node } from 'estree'
import type MagicString from 'magic-string'
import type { ArgumentsType } from 'vitest'
import type { DetectImportResult, Import, InjectImportsOptions, UnimportContext } from './types'
import { parse } from 'acorn'
import { walk } from 'estree-walker'
import { getMagicString } from './utils'

export type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never

export async function detectImportsAcorn(
code: string | MagicString,
ctx: UnimportContext,
Expand Down Expand Up @@ -236,7 +237,11 @@ export function traveseScopes(ast: Node, additionalWalk?: ArgumentsType<typeof w
export function createVirtualImportsAcronWalker(
importMap: Map<string, Import>,
virtualImports: string[] = [],
) {
): {
imports: Import[]
ranges: [number, number][]
walk: ArgumentsType<typeof walk>[1]
} {
const imports: Import[] = []
const ranges: [number, number][] = []

Expand All @@ -250,7 +255,7 @@ export function createVirtualImportsAcronWalker(
// @ts-expect-error missing types
ranges.push([node.start, node.end])
node.specifiers.forEach((i) => {
if (i.type === 'ImportSpecifier') {
if (i.type === 'ImportSpecifier' && i.imported.type === 'Identifier') {
const original = importMap.get(i.imported.name)
if (!original)
throw new Error(`[unimport] failed to find "${i.imported.name}" imported from "${node.source.value}"`)
Expand Down

0 comments on commit 2a34ec4

Please sign in to comment.