@@ -158,14 +158,17 @@ function vueJsxPlugin(options: Options = {}): Plugin {
158
158
enter (
159
159
_path : babel . NodePath < types . ExportDefaultDeclaration > ,
160
160
) {
161
+ const unwrappedDeclaration = unwrapTypeAssertion (
162
+ _path . node . declaration ,
163
+ )
161
164
if (
162
165
isDefineComponentCall (
163
- _path . node . declaration ,
166
+ unwrappedDeclaration ,
164
167
defineComponentName ,
165
168
)
166
169
) {
167
- const declaration = _path . node
168
- . declaration as types . CallExpression
170
+ const declaration =
171
+ unwrappedDeclaration as types . CallExpression
169
172
const nodesPath = _path . replaceWithMultiple ( [
170
173
// const __default__ = defineComponent(...)
171
174
types . variableDeclaration ( 'const' , [
@@ -276,7 +279,10 @@ function vueJsxPlugin(options: Options = {}): Plugin {
276
279
} )
277
280
}
278
281
} else if (
279
- isDefineComponentCall ( node . declaration , defineComponentName )
282
+ isDefineComponentCall (
283
+ unwrapTypeAssertion ( node . declaration ) ,
284
+ defineComponentName ,
285
+ )
280
286
) {
281
287
hotComponents . push ( {
282
288
local : '__default__' ,
@@ -337,7 +343,7 @@ function parseComponentDecls(
337
343
for ( const decl of node . declarations ) {
338
344
if (
339
345
decl . id . type === 'Identifier' &&
340
- isDefineComponentCall ( decl . init , fnNames )
346
+ isDefineComponentCall ( unwrapTypeAssertion ( decl . init ) , fnNames )
341
347
) {
342
348
names . push ( decl . id . name )
343
349
}
@@ -357,6 +363,25 @@ function isDefineComponentCall(
357
363
)
358
364
}
359
365
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
+
360
385
function getHash ( text : string ) {
361
386
return crypto . hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
362
387
}
0 commit comments