@@ -1877,6 +1877,11 @@ const visitors = {
18771877 ] ) ,
18781878 ) ;
18791879
1880+ func . metadata = {
1881+ ...func . metadata ,
1882+ is_component : true ,
1883+ } ;
1884+
18801885 return func ;
18811886 } ,
18821887
@@ -4748,7 +4753,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
47484753
47494754 const program = /** @type {AST.Program } */ ( walk ( analysis . ast , { ...state } , visitors ) ) ;
47504755
4751- /** @type {AST.Statement[ ] } */
4756+ /** @type {AST.RippleProgram['body' ] } */
47524757 let body = [ ] ;
47534758
47544759 for ( const import_node of state . imports ) {
@@ -4784,15 +4789,15 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
47844789 // Walk the body to find components and inject HMR wrapping.
47854790 // After the walk, Component nodes become FunctionExpression nodes
47864791 // (via b.function() which creates FunctionExpression).
4787- /** @type {AST.Statement[ ] } */
4792+ /** @type {AST.RippleProgram['body' ] } */
47884793 const hmr_body = [ ] ;
47894794
47904795 for ( const node of body ) {
47914796 hmr_body . push ( node ) ;
47924797
47934798 if ( node . type === 'ExportDefaultDeclaration' ) {
4794- const decl = node . declaration ;
4795- if ( decl . type === 'FunctionExpression' && decl . id && component_names . has ( decl . id . name ) ) {
4799+ const decl = /** @type { AST.FunctionExpression } */ ( node . declaration ) ;
4800+ if ( decl . metadata ?. is_component && decl . id && component_names . has ( decl . id . name ) ) {
47964801 const name = decl . id . name ;
47974802 exported_components . push ( { name, export_type : 'default' } ) ;
47984803 // Replace ExportDefaultDeclaration with plain FunctionExpression (printed as function declaration)
@@ -4803,13 +4808,8 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48034808 hmr_body . push ( b . export_default ( b . id ( name ) ) ) ;
48044809 }
48054810 } else if ( node . type === 'ExportNamedDeclaration' ) {
4806- const decl = node . declaration ;
4807- if (
4808- decl &&
4809- decl . type === 'FunctionExpression' &&
4810- decl . id &&
4811- component_names . has ( decl . id . name )
4812- ) {
4811+ const decl = /** @type {AST.FunctionExpression | null | undefined } */ ( node . declaration ) ;
4812+ if ( decl && decl . metadata ?. is_component && decl . id && component_names . has ( decl . id . name ) ) {
48134813 const name = decl . id . name ;
48144814 exported_components . push ( { name, export_type : 'named' } ) ;
48154815 // Replace ExportNamedDeclaration with plain FunctionExpression (printed as function declaration)
@@ -4830,6 +4830,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48304830 }
48314831 } else if (
48324832 node . type === 'FunctionExpression' &&
4833+ node . metadata ?. is_component &&
48334834 node . id &&
48344835 component_names . has ( node . id . name )
48354836 ) {
@@ -4859,7 +4860,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48594860 body = hmr_body ;
48604861 }
48614862
4862- program . body = body ;
4863+ /** @type { AST.RippleProgram['body'] } */ ( program . body ) = body ;
48634864
48644865 const language_handler = to_ts
48654866 ? create_tsx_with_typescript_support ( analysis . comments )
0 commit comments