@@ -158,14 +158,17 @@ function vueJsxPlugin(options: Options = {}): Plugin {
158158 enter (
159159 _path : babel . NodePath < types . ExportDefaultDeclaration > ,
160160 ) {
161+ const unwrappedDeclaration = unwrapTypeAssertion (
162+ _path . node . declaration ,
163+ )
161164 if (
162165 isDefineComponentCall (
163- _path . node . declaration ,
166+ unwrappedDeclaration ,
164167 defineComponentName ,
165168 )
166169 ) {
167- const declaration = _path . node
168- . declaration as types . CallExpression
170+ const declaration =
171+ unwrappedDeclaration as types . CallExpression
169172 const nodesPath = _path . replaceWithMultiple ( [
170173 // const __default__ = defineComponent(...)
171174 types . variableDeclaration ( 'const' , [
@@ -276,7 +279,10 @@ function vueJsxPlugin(options: Options = {}): Plugin {
276279 } )
277280 }
278281 } else if (
279- isDefineComponentCall ( node . declaration , defineComponentName )
282+ isDefineComponentCall (
283+ unwrapTypeAssertion ( node . declaration ) ,
284+ defineComponentName ,
285+ )
280286 ) {
281287 hotComponents . push ( {
282288 local : '__default__' ,
@@ -337,7 +343,7 @@ function parseComponentDecls(
337343 for ( const decl of node . declarations ) {
338344 if (
339345 decl . id . type === 'Identifier' &&
340- isDefineComponentCall ( decl . init , fnNames )
346+ isDefineComponentCall ( unwrapTypeAssertion ( decl . init ) , fnNames )
341347 ) {
342348 names . push ( decl . id . name )
343349 }
@@ -357,6 +363,25 @@ function isDefineComponentCall(
357363 )
358364}
359365
366+ function unwrapTypeAssertion ( node : types . Node ) : types . Node
367+ function unwrapTypeAssertion (
368+ node : types . Node | null | undefined ,
369+ ) : types . Node | null | undefined
370+ function unwrapTypeAssertion (
371+ node : types . Node | null | undefined ,
372+ ) : types . Node | null | undefined {
373+ if ( ! node ) return node
374+ let current = node
375+ while (
376+ current . type === 'TSAsExpression' ||
377+ current . type === 'TSSatisfiesExpression' ||
378+ current . type === 'TSTypeAssertion'
379+ ) {
380+ current = current . expression
381+ }
382+ return current
383+ }
384+
360385function getHash ( text : string ) {
361386 return crypto . hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
362387}
0 commit comments