Skip to content

Commit 425e062

Browse files
committed
perf: use native magic-string
1 parent c491cae commit 425e062

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
"dependencies": {
6868
"@vue/language-core": "^3.1.8",
6969
"ast-kit": "^2.2.0",
70-
"magic-string-ast": "^1.0.3",
7170
"muggle-string": "^0.4.1",
71+
"rolldown-string": "^0.2.1",
7272
"unplugin": "^2.3.11"
7373
},
7474
"devDependencies": {

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { babelParse, getLang } from 'ast-kit'
2-
import { generateTransform, MagicString } from 'magic-string-ast'
2+
import { withMagicString } from 'rolldown-string'
33
import { createUnplugin, type UnpluginInstance } from 'unplugin'
44
import { resolveOption, type Options } from './core/options'
55
import { resolveName } from './core/utils'
@@ -28,8 +28,9 @@ export const VueNamedExport: UnpluginInstance<Options | undefined, false> =
2828
exclude: options.exclude,
2929
},
3030
},
31-
async handler(code, id) {
31+
handler: withMagicString(async (s, id) => {
3232
const lang = getLang(id)
33+
const code = s.toString()
3334

3435
const program = babelParse(code, lang)
3536
const defaultExport = program.body.find(
@@ -38,7 +39,6 @@ export const VueNamedExport: UnpluginInstance<Options | undefined, false> =
3839
)
3940
if (!defaultExport) return
4041

41-
const s = new MagicString(code)
4242
const resolvedName = await (options.resolveName || resolveName)(id)
4343

4444
s.overwrite(
@@ -59,9 +59,7 @@ export const VueNamedExport: UnpluginInstance<Options | undefined, false> =
5959
`\nexport default ${resolvedName};`,
6060
)
6161
}
62-
63-
return generateTransform(s, id)
64-
},
62+
}),
6563
},
6664

6765
vite: {

0 commit comments

Comments
 (0)