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

Commit

Permalink
fix: backwards compat with older versions of compiler-sfc
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 15, 2020
1 parent c39ec13 commit 7cb9fa4
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 198 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/debug": "^4.1.5",
"@types/jest": "^25.2.3",
"@types/node": "^13.13.2",
"@vue/compiler-sfc": "^3.0.0-beta.14",
"@vue/compiler-sfc": "^3.0.0-beta.22",
"husky": "^4.2.0",
"jest": "^26.0.1",
"lint-staged": "^10.1.7",
Expand Down
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,19 @@ function getTemplateCode(
function getScriptCode(descriptor: SFCDescriptor, resourcePath: string) {
let scriptImport = `const script = {}`
if (descriptor.script || descriptor.scriptSetup) {
descriptor.script = compileScript(descriptor)
const src = descriptor.script.src || resourcePath
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
const srcQuery = descriptor.script.src ? `&src` : ``
const query = `?vue&type=script${srcQuery}${attrsQuery}`
const scriptRequest = _(src + query)
scriptImport =
`import script from ${scriptRequest}\n` + `export * from ${scriptRequest}` // support named exports
if (compileScript) {
descriptor.script = compileScript(descriptor)
}
if (descriptor.script) {
const src = descriptor.script.src || resourcePath
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
const srcQuery = descriptor.script.src ? `&src` : ``
const query = `?vue&type=script${srcQuery}${attrsQuery}`
const scriptRequest = _(src + query)
scriptImport =
`import script from ${scriptRequest}\n` +
`export * from ${scriptRequest}` // support named exports
}
}
return scriptImport
}
Expand Down
Loading

0 comments on commit 7cb9fa4

Please sign in to comment.