Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 7cb9fa4

Browse files
committed
fix: backwards compat with older versions of compiler-sfc
1 parent c39ec13 commit 7cb9fa4

File tree

3 files changed

+150
-198
lines changed

3 files changed

+150
-198
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/debug": "^4.1.5",
2929
"@types/jest": "^25.2.3",
3030
"@types/node": "^13.13.2",
31-
"@vue/compiler-sfc": "^3.0.0-beta.14",
31+
"@vue/compiler-sfc": "^3.0.0-beta.22",
3232
"husky": "^4.2.0",
3333
"jest": "^26.0.1",
3434
"lint-staged": "^10.1.7",

src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,19 @@ function getTemplateCode(
452452
function getScriptCode(descriptor: SFCDescriptor, resourcePath: string) {
453453
let scriptImport = `const script = {}`
454454
if (descriptor.script || descriptor.scriptSetup) {
455-
descriptor.script = compileScript(descriptor)
456-
const src = descriptor.script.src || resourcePath
457-
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
458-
const srcQuery = descriptor.script.src ? `&src` : ``
459-
const query = `?vue&type=script${srcQuery}${attrsQuery}`
460-
const scriptRequest = _(src + query)
461-
scriptImport =
462-
`import script from ${scriptRequest}\n` + `export * from ${scriptRequest}` // support named exports
455+
if (compileScript) {
456+
descriptor.script = compileScript(descriptor)
457+
}
458+
if (descriptor.script) {
459+
const src = descriptor.script.src || resourcePath
460+
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
461+
const srcQuery = descriptor.script.src ? `&src` : ``
462+
const query = `?vue&type=script${srcQuery}${attrsQuery}`
463+
const scriptRequest = _(src + query)
464+
scriptImport =
465+
`import script from ${scriptRequest}\n` +
466+
`export * from ${scriptRequest}` // support named exports
467+
}
463468
}
464469
return scriptImport
465470
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy