@@ -14,6 +14,9 @@ import jsx from '@vue/babel-plugin-transform-vue-jsx'
14
14
// @ts -ignore
15
15
import babelSugarInjectH from '@vue/babel-sugar-inject-h'
16
16
17
+ // @ts -ignore (TS7016: Could not find a declaration file for module '@babel/plugin-transform-typescript'.)
18
+ import babelPlugin_typescript from '@babel/plugin-transform-typescript'
19
+
17
20
import {
18
21
formatError ,
19
22
formatErrorStartEnd ,
@@ -134,9 +137,18 @@ export async function createSFCModule(source : string, filename : AbstractPath,
134
137
135
138
const src = descriptor . script . src ? ( await ( await getResource ( { refPath : filename , relPath : descriptor . script . src } , options ) . getContent ( ) ) . getContentData ( false ) ) as string : descriptor . script . content ;
136
139
137
- const [ depsList , transformedScriptSource ] = await withCache ( compiledCache , [ componentHash , src , additionalBabelParserPlugins , Object . keys ( additionalBabelPlugins ) ] , async ( { preventCache } ) => {
140
+ const [ depsList , transformedScriptSource ] = await withCache ( compiledCache , [ componentHash , src , descriptor . script . lang , additionalBabelParserPlugins , Object . keys ( additionalBabelPlugins ) ] , async ( { preventCache } ) => {
141
+
142
+ let contextBabelParserPlugins : Options [ 'additionalBabelParserPlugins' ] = [ 'jsx' ] ;
143
+ let contextBabelPlugins : Options [ 'additionalBabelPlugins' ] = { jsx, babelSugarInjectH } ;
144
+
145
+ if ( descriptor . script ?. lang === 'ts' ) {
146
+
147
+ contextBabelParserPlugins = [ ...contextBabelParserPlugins , 'typescript' ] ;
148
+ contextBabelPlugins = { ...contextBabelPlugins , typescript : babelPlugin_typescript } ;
149
+ }
138
150
139
- return await transformJSCode ( src , true , strFilename , [ ...additionalBabelParserPlugins , 'jsx' ] , { ...additionalBabelPlugins , jsx , babelSugarInjectH } , log , devMode ) ;
151
+ return await transformJSCode ( src , true , strFilename , [ ...contextBabelParserPlugins , ... additionalBabelParserPlugins ] , { ...contextBabelPlugins , ... additionalBabelPlugins } , log , devMode ) ;
140
152
} ) ;
141
153
142
154
await loadDeps ( filename , depsList , options ) ;
0 commit comments