Skip to content

Commit

Permalink
feat(plugin-vue): support TS in template expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 18, 2021
1 parent 1f639a5 commit decc925
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
compileTemplate,
SFCDescriptor,
SFCTemplateCompileOptions,
SFCTemplateCompileResults
SFCTemplateCompileResults,
CompilerOptions
} from '@vue/compiler-sfc'
import { PluginContext, TransformPluginContext } from 'rollup'
import { ResolvedOptions } from '.'
Expand Down Expand Up @@ -157,6 +158,16 @@ export function resolveTemplateCompilerOptions(
}
}

// if using TS, support TS syntax in template expressions
const expressionPlugins: CompilerOptions['expressionPlugins'] =
options.template?.compilerOptions?.expressionPlugins || []
if (
descriptor.script?.lang === 'ts' ||
descriptor.scriptSetup?.lang === 'ts'
) {
expressionPlugins.push('typescript')
}

return {
...options.template,
id,
Expand All @@ -173,7 +184,8 @@ export function resolveTemplateCompilerOptions(
compilerOptions: {
...options.template?.compilerOptions,
scopeId: hasScoped ? `data-v-${id}` : undefined,
bindingMetadata: resolvedScript ? resolvedScript.bindings : undefined
bindingMetadata: resolvedScript ? resolvedScript.bindings : undefined,
expressionPlugins
}
}
}

0 comments on commit decc925

Please sign in to comment.