Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for tsx #68

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import hashId from 'hash-sum'

export const COMP_IDENTIFIER = `__sfc__`

function testTs(lang: string | null | undefined) {
return ['ts', 'tsx'].includes(lang!)
}

async function transformTS(src: string) {
return transform(src, {
transforms: ['typescript']
transforms: ['jsx', 'typescript'],
jsxPragma: 'h',
jsxFragmentPragma: 'Fragment'
}).code
}

Expand Down Expand Up @@ -74,7 +80,7 @@ export async function compileFile(
const scriptLang =
(descriptor.script && descriptor.script.lang) ||
(descriptor.scriptSetup && descriptor.scriptSetup.lang)
const isTS = scriptLang === 'ts'
const isTS = testTs(scriptLang)
if (scriptLang && !isTS) {
store.state.errors = [`Only lang="ts" is supported for <script> blocks.`]
return
Expand Down Expand Up @@ -253,7 +259,7 @@ async function doCompileScript(
expressionPlugins
)

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

Expand Down Expand Up @@ -304,7 +310,7 @@ async function doCompileTemplate(
`$1 ${fnName}`
)}` + `\n${COMP_IDENTIFIER}.${fnName} = ${fnName}`

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

Expand Down