Skip to content

Commit

Permalink
fix: apply TS transform to template when inine is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 20, 2022
1 parent 7909c00 commit ec2ae81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function compileFile(
descriptor.template &&
(!descriptor.scriptSetup || store.options?.script?.inlineTemplate === false)
) {
const clientTemplateResult = doCompileTemplate(
const clientTemplateResult = await doCompileTemplate(
store,
descriptor,
id,
Expand All @@ -139,7 +139,7 @@ export async function compileFile(
}
clientCode += clientTemplateResult

const ssrTemplateResult = doCompileTemplate(
const ssrTemplateResult = await doCompileTemplate(
store,
descriptor,
id,
Expand Down Expand Up @@ -265,7 +265,7 @@ async function doCompileScript(
}
}

function doCompileTemplate(
async function doCompileTemplate(
store: Store,
descriptor: SFCDescriptor,
id: string,
Expand Down Expand Up @@ -296,12 +296,17 @@ function doCompileTemplate(

const fnName = ssr ? `ssrRender` : `render`

return (
let code =
`\n${templateResult.code.replace(
/\nexport (function|const) (render|ssrRender)/,
`$1 ${fnName}`
)}` + `\n${COMP_IDENTIFIER}.${fnName} = ${fnName}`
)

if ((descriptor.script || descriptor.scriptSetup)!.lang === 'ts') {
code = await transformTS(code)
}

return code
}

async function hashId(filename: string) {
Expand Down
7 changes: 6 additions & 1 deletion test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ const App = {
return () =>
h(Repl, {
store,
layout: 'vertical'
layout: 'vertical',
sfcOptions: {
script: {
// inlineTemplate: false
}
}
// showCompileOutput: false,
// showImportMap: false
})
Expand Down

0 comments on commit ec2ae81

Please sign in to comment.