Skip to content

Commit

Permalink
fix: vue vapor compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 17, 2024
1 parent f478091 commit e0044fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 6 additions & 2 deletions composables/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export interface Parser<C = unknown, O = unknown> {
pkgName: string
version:
| string
| ((this: C | Promise<C>, pkgName: string) => string | Promise<string>)
| ((
this: C | Promise<C>,
pkgName: string,
version?: string,
) => string | Promise<string>)
versionOverridable?: boolean
getModuleUrl?: (pkgName: string) => string
getModuleUrl?: (pkgName: string, version?: string) => string
init?: (moduleUrl: string, pkgId: string) => C | Promise<C>
parse: (this: C, code: string, options: O) => unknown
options: {
Expand Down
12 changes: 9 additions & 3 deletions composables/parser/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ const vueVapor: Parser<
editorLanguage: 'javascript',
},
pkgName: '@vue-vapor/compiler-vapor',
getModuleUrl: (pkg) =>
getJsdelivrUrl(pkg, `/dist/compiler-vapor.esm-browser.js`),
version: fetchVersion,
getModuleUrl: (pkg, version) =>
`https://next.esm.sh/pr/vuejs/vue-vapor/@vue/compiler-vapor@${version || 'main'}`,
version: async (pkg, version) => {
if (version) return version
const { url } = await fetch(
'https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-vapor@main',
)
return url.split('@').pop()!
},
parse(code, options) {
return this.compile(code, { ...options }).ast
},
Expand Down
10 changes: 8 additions & 2 deletions composables/state/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ async function initParser() {
: `${pkgName}${overrideVersion.value ? `@${overrideVersion.value}` : ''}`
if (parserModuleCache[pkgId]) return parserModuleCache[pkgId]

const moduleUrl = isUrlVersion.value ? pkgId : getModuleUrl(pkgId)
const moduleUrl = isUrlVersion.value
? pkgId
: getModuleUrl(pkgId, overrideVersion.value)
return (parserModuleCache[pkgId] = await init(moduleUrl, pkgId))
}

Expand Down Expand Up @@ -174,7 +176,11 @@ if (import.meta.client) {
} else {
displayVersion.value = ''
const res = await Promise.resolve(
parser.version.call(parserModulePromise.value, parser.pkgName),
parser.version.call(
parserModulePromise.value,
parser.pkgName,
overrideVersion.value,
),
)
if (currentParser.value.id === parser.id) {
displayVersion.value = res
Expand Down

0 comments on commit e0044fb

Please sign in to comment.