@@ -541,7 +541,7 @@ function wrapComponent(
541541 properties . push (
542542 t . objectProperty (
543543 t . identifier ( 'dependencies' ) ,
544- t . objectExpression ( dependencyKeys ) ,
544+ t . arrowFunctionExpression ( [ ] , t . objectExpression ( dependencyKeys ) ) ,
545545 ) ,
546546 ) ;
547547 }
@@ -587,8 +587,7 @@ function setupProgram(state: State, path: babel.NodePath<t.Program>): void {
587587 let shouldSkip = false ;
588588 const comments = state . file . ast . comments ;
589589 if ( comments ) {
590- for ( let i = 0 ; i < comments . length ; i ++ ) {
591- const comment = comments [ i ] . value ;
590+ for ( const { value : comment } of comments ) {
592591 if ( / ^ \s * @ r e f r e s h g r a n u l a r \s * $ / . test ( comment ) ) {
593592 state . granular = true ;
594593 break ;
@@ -712,59 +711,62 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
712711 this . imports = [ ...IMPORT_IDENTITIES , ...( this . opts . imports || [ ] ) ] ;
713712 } ,
714713 visitor : {
715- Program ( path , state ) {
716- setupProgram ( state , path ) ;
717- } ,
718- ExportNamedDeclaration ( path , state ) {
719- transformExportNamedDeclaration ( state , path ) ;
720- } ,
721- VariableDeclarator ( path , state ) {
722- transformVariableDeclarator ( state , path ) ;
723- } ,
724- FunctionDeclaration ( path , state ) {
725- if ( state . processed ) {
726- return ;
727- }
728- if (
729- path . parentPath . isProgram ( ) ||
730- path . parentPath . isExportDefaultDeclaration ( )
731- ) {
732- const decl = path . node ;
733- // Check if declaration is FunctionDeclaration
734- if (
735- // Check if the declaration has an identifier, and then check
736- decl . id &&
737- // if the name is component-ish
738- isComponentishName ( decl . id . name ) &&
739- ! ( decl . generator || decl . async ) &&
740- // Might be component-like, but the only valid components
741- // have zero or one parameter
742- decl . params . length < 2
743- ) {
744- const replacement = wrapComponent (
745- state ,
746- path ,
747- decl . id ,
748- t . functionExpression ( decl . id , decl . params , decl . body ) ,
749- decl ,
750- ) ;
751- const newDecl = t . variableDeclaration ( 'var' , [
752- t . variableDeclarator ( decl . id , replacement ) ,
753- ] ) ;
754- if ( path . parentPath . isExportDefaultDeclaration ( ) ) {
755- const parent = path . parentPath
756- . parentPath as babel . NodePath < t . Program > ;
757- const first = parent . get ( 'body' ) [ 0 ] ;
758- first . insertBefore ( newDecl ) ;
759- path . replaceWith ( decl . id ) ;
760- } else {
761- const parent = path . parentPath as babel . NodePath < t . Program > ;
762- const first = parent . get ( 'body' ) [ 0 ] ;
763- first . insertBefore ( newDecl ) ;
764- path . remove ( ) ;
714+ Program ( programPath , state ) {
715+ setupProgram ( state , programPath ) ;
716+
717+ programPath . traverse ( {
718+ ExportNamedDeclaration ( path ) {
719+ transformExportNamedDeclaration ( state , path ) ;
720+ } ,
721+ VariableDeclarator ( path ) {
722+ transformVariableDeclarator ( state , path ) ;
723+ } ,
724+ FunctionDeclaration ( path ) {
725+ if ( state . processed ) {
726+ return ;
765727 }
766- }
767- }
728+ if (
729+ path . parentPath . isProgram ( ) ||
730+ path . parentPath . isExportDefaultDeclaration ( )
731+ ) {
732+ const decl = path . node ;
733+ // Check if declaration is FunctionDeclaration
734+ if (
735+ // Check if the declaration has an identifier, and then check
736+ decl . id &&
737+ // if the name is component-ish
738+ isComponentishName ( decl . id . name ) &&
739+ ! ( decl . generator || decl . async ) &&
740+ // Might be component-like, but the only valid components
741+ // have zero or one parameter
742+ decl . params . length < 2
743+ ) {
744+ const replacement = wrapComponent (
745+ state ,
746+ path ,
747+ decl . id ,
748+ t . functionExpression ( decl . id , decl . params , decl . body ) ,
749+ decl ,
750+ ) ;
751+ const newDecl = t . variableDeclaration ( 'var' , [
752+ t . variableDeclarator ( decl . id , replacement ) ,
753+ ] ) ;
754+ if ( path . parentPath . isExportDefaultDeclaration ( ) ) {
755+ const parent = path . parentPath
756+ . parentPath as babel . NodePath < t . Program > ;
757+ const first = parent . get ( 'body' ) [ 0 ] ;
758+ first . insertBefore ( newDecl ) ;
759+ path . replaceWith ( decl . id ) ;
760+ } else {
761+ const parent = path . parentPath as babel . NodePath < t . Program > ;
762+ const first = parent . get ( 'body' ) [ 0 ] ;
763+ first . insertBefore ( newDecl ) ;
764+ path . remove ( ) ;
765+ }
766+ }
767+ }
768+ } ,
769+ } ) ;
768770 } ,
769771 } ,
770772 } ;
0 commit comments