Skip to content

Commit

Permalink
refactor: generate transform
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 29, 2023
1 parent eb0182d commit 289d273
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
walkAST,
walkImportDeclaration,
} from 'ast-kit'
import { MagicString } from 'magic-string-ast'
import { MagicString, generateTransform } from 'magic-string-ast'
import { type ImportAttribute, type Node } from '@babel/types'
import { type ViteNodeRunner } from 'vite-node/client'

Expand Down Expand Up @@ -149,7 +149,7 @@ export async function transformMacros(
deps.get(id)!.add(resolved)
}

return getTransformResult(s, id)
return generateTransform(s, id)

function recordImports() {
const imports: Record<string, ImportBinding> = {}
Expand All @@ -175,21 +175,3 @@ function checkAttributes(attrs: ImportAttribute[]) {
'type' && attr.value.value === 'macro'
)
}

export function getTransformResult(
s: MagicString | undefined,
id: string
): { code: string; map: any } | undefined {
if (s?.hasChanged()) {
return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
hires: true,
})
},
}
}
}

0 comments on commit 289d273

Please sign in to comment.