@@ -7,6 +7,8 @@ import SlotFlags from './slotFlags';
77
88const JSX_HELPER_KEY = 'JSX_HELPER_KEY' ;
99const FRAGMENT = 'Fragment' ;
10+ const KEEP_ALIVE = 'KeepAlive' ;
11+
1012/**
1113 * create Identifier
1214 * @param path NodePath
@@ -26,22 +28,11 @@ const isDirective = (src: string): boolean => src.startsWith('v-')
2628 || ( src . startsWith ( 'v' ) && src . length >= 2 && src [ 1 ] >= 'A' && src [ 1 ] <= 'Z' ) ;
2729
2830/**
29- * Check if a Node is fragment
30- * @param { * } path JSXIdentifier | JSXMemberExpression | JSXNamespacedName
31+ * Should transformed to slots
32+ * @param tag string
3133 * @returns boolean
3234 */
33- const isFragment = (
34- path :
35- NodePath < t . JSXIdentifier | t . JSXMemberExpression | t . JSXNamespacedName > ,
36- ) : boolean => {
37- if ( path . isJSXIdentifier ( ) ) {
38- return path . node . name . endsWith ( FRAGMENT ) ;
39- }
40- if ( path . isJSXMemberExpression ( ) ) {
41- return path . node . property . name . endsWith ( FRAGMENT ) ;
42- }
43- return false ;
44- } ;
35+ const shouldTransformedToSlots = ( tag : string ) => ! ( tag . endsWith ( FRAGMENT ) || tag === KEEP_ALIVE ) ;
4536
4637/**
4738 * Check if a Node is a component
@@ -53,13 +44,13 @@ const isFragment = (
5344const checkIsComponent = ( path : NodePath < t . JSXOpeningElement > ) : boolean => {
5445 const namePath = path . get ( 'name' ) ;
5546
56- if ( t . isJSXMemberExpression ( namePath ) ) {
57- return ! isFragment ( namePath ) ; // For withCtx
47+ if ( namePath . isJSXMemberExpression ( ) ) {
48+ return shouldTransformedToSlots ( namePath . node . property . name ) ; // For withCtx
5849 }
5950
6051 const tag = ( namePath as NodePath < t . JSXIdentifier > ) . node . name ;
6152
62- return ! tag . endsWith ( FRAGMENT ) && ! htmlTags . includes ( tag ) && ! svgTags . includes ( tag ) ;
53+ return shouldTransformedToSlots ( tag ) && ! htmlTags . includes ( tag ) && ! svgTags . includes ( tag ) ;
6354} ;
6455
6556/**
@@ -181,8 +172,8 @@ const transformJSXText = (path: NodePath<t.JSXText>): t.StringLiteral | null =>
181172const transformJSXExpressionContainer = (
182173 path : NodePath < t . JSXExpressionContainer > ,
183174) : (
184- t . Expression
185- ) => path . get ( 'expression' ) . node as t . Expression ;
175+ t . Expression
176+ ) => path . get ( 'expression' ) . node as t . Expression ;
186177
187178/**
188179 * Transform JSXSpreadChild
@@ -240,7 +231,7 @@ export {
240231 transformJSXText ,
241232 transformJSXSpreadChild ,
242233 transformJSXExpressionContainer ,
243- isFragment ,
234+ shouldTransformedToSlots ,
244235 FRAGMENT ,
245236 walksScope ,
246237 buildIIFE ,
0 commit comments