Skip to content

Commit

Permalink
refactor: simplify generate source map
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 3, 2024
1 parent 31412f0 commit 883de5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@babel/parser": "^7.24.5",
"@rollup/pluginutils": "^5.1.0",
"ast-kit": "^0.12.1",
"magic-string-ast": "^0.5.0",
"magic-string-ast": "^0.6.0",
"unplugin": "^1.10.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions src/core/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { MagicStringAST, type SourceMap } from 'magic-string-ast'
import {
MagicStringAST,
type SourceMap,
generateTransform,
} from 'magic-string-ast'
import generate from '@babel/generator'
import { babelParse, getLang, walkASTAsync } from 'ast-kit'
import { useNodeRef } from './utils'
Expand Down Expand Up @@ -87,15 +91,6 @@ export async function transform(
}
}
}
if (!s.hasChanged()) return undefined

return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
})
},
}
return generateTransform(s, id)
}
2 changes: 1 addition & 1 deletion src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NodeRef } from './types'
export function useNodeRef() {
const nodeRefs: Map<Node, NodeRef<Node | undefined>> = new Map()

const getNodeRef = (node: Node) => {
function getNodeRef(node: Node) {
if (nodeRefs.has(node)) return nodeRefs.get(node)!
const ref: NodeRef<Node | undefined> = {
value: node,
Expand Down

0 comments on commit 883de5c

Please sign in to comment.