@@ -560,23 +560,29 @@ export default function babelPluginKStyled(): PluginObj<PluginState> {
560560 // generate a lightweight component directly without styled() wrapper
561561 const isStaticOnly = dynamicProps . length === 0 && ! attrsMetadata ;
562562
563+ const baseComponent = styledCall . arguments [ 0 ] ;
564+ const canOptimizeBaseComponent = t . isIdentifier ( baseComponent ) ;
565+
563566 if ( opts . debug ) {
564567 console . log ( '[babel-plugin-kstyled] Optimization check:' ) ;
565568 console . log ( ' isStaticOnly:' , isStaticOnly ) ;
566569 console . log ( ' styleSheetNode exists:' , ! ! styleSheetNode ) ;
567570 console . log ( ' opts.optimizeStatic:' , opts . optimizeStatic ) ;
568571 console . log ( ' dynamicProps.length:' , dynamicProps . length ) ;
569572 console . log ( ' attrsMetadata:' , ! ! attrsMetadata ) ;
573+ console . log ( ' canOptimizeBaseComponent:' , canOptimizeBaseComponent ) ;
570574 }
571575
572- if ( isStaticOnly && styleSheetNode && opts . optimizeStatic !== false ) {
576+ if (
577+ isStaticOnly &&
578+ styleSheetNode &&
579+ opts . optimizeStatic !== false &&
580+ canOptimizeBaseComponent
581+ ) {
573582 // Import forwardRef from React
574583 const program = path . findParent ( ( p ) => p . isProgram ( ) ) as NodePath < t . Program > ;
575584 const forwardRefImport = addNamed ( program , 'forwardRef' , 'react' ) ;
576585
577- // Get the base component from styled(Component)
578- const baseComponent = styledCall . arguments [ 0 ] ;
579-
580586 // Generate ultra-optimized JSX:
581587 // forwardRef((props, ref) => (
582588 // <Component {...props} ref={ref} style={props.style ? [props.style, __ks.base] : __ks.base} />
@@ -585,15 +591,8 @@ export default function babelPluginKStyled(): PluginObj<PluginState> {
585591 // No memo: styled-components doesn't use memo either, so fair comparison
586592 // JSX spread: Let React handle prop spreading efficiently
587593
588- // Get component name for JSX
589- let componentName = 'View' ;
590- if ( t . isIdentifier ( baseComponent ) ) {
591- componentName = baseComponent . name ;
592- } else if ( t . isMemberExpression ( baseComponent ) ) {
593- if ( t . isIdentifier ( baseComponent . property ) ) {
594- componentName = baseComponent . property . name ;
595- }
596- }
594+ // Base component is guaranteed to be an Identifier here
595+ const componentName = ( baseComponent as t . Identifier ) . name ;
597596
598597 // Create style expression: props.style ? [__ks.base, props.style] : __ks.base
599598 // IMPORTANT: Base styles first, external styles last (external overrides base)
0 commit comments