@@ -1851,6 +1851,7 @@ impl Printer {
1851
1851
ComponentTypeDeclaration :: Export { name, ty } => {
1852
1852
self . start_group ( "export " ) ;
1853
1853
self . print_component_kind_name ( states. last_mut ( ) . unwrap ( ) , ty. kind ( ) ) ?;
1854
+ self . result . push ( ' ' ) ;
1854
1855
self . print_str ( name. 0 ) ?;
1855
1856
self . result . push ( ' ' ) ;
1856
1857
self . print_component_import_ty ( states. last_mut ( ) . unwrap ( ) , & ty, false ) ?;
@@ -1885,6 +1886,7 @@ impl Printer {
1885
1886
InstanceTypeDeclaration :: Export { name, ty } => {
1886
1887
self . start_group ( "export " ) ;
1887
1888
self . print_component_kind_name ( states. last_mut ( ) . unwrap ( ) , ty. kind ( ) ) ?;
1889
+ self . result . push ( ' ' ) ;
1888
1890
self . print_str ( name. 0 ) ?;
1889
1891
self . result . push ( ' ' ) ;
1890
1892
self . print_component_import_ty ( states. last_mut ( ) . unwrap ( ) , & ty, false ) ?;
@@ -2163,6 +2165,7 @@ impl Printer {
2163
2165
self . start_group ( "export " ) ;
2164
2166
if named {
2165
2167
self . print_component_kind_name ( state, export. kind ) ?;
2168
+ self . result . push ( ' ' ) ;
2166
2169
}
2167
2170
self . print_str ( export. name . 0 ) ?;
2168
2171
self . result . push ( ' ' ) ;
@@ -2206,7 +2209,30 @@ impl Printer {
2206
2209
state. component . components += 1 ;
2207
2210
}
2208
2211
}
2209
- self . result . push ( ' ' ) ;
2212
+ Ok ( ( ) )
2213
+ }
2214
+
2215
+ fn start_component_external_kind_group ( & mut self , kind : ComponentExternalKind ) -> Result < ( ) > {
2216
+ match kind {
2217
+ ComponentExternalKind :: Module => {
2218
+ self . start_group ( "core module " ) ;
2219
+ }
2220
+ ComponentExternalKind :: Component => {
2221
+ self . start_group ( "component " ) ;
2222
+ }
2223
+ ComponentExternalKind :: Instance => {
2224
+ self . start_group ( "instance " ) ;
2225
+ }
2226
+ ComponentExternalKind :: Func => {
2227
+ self . start_group ( "func " ) ;
2228
+ }
2229
+ ComponentExternalKind :: Value => {
2230
+ self . start_group ( "value " ) ;
2231
+ }
2232
+ ComponentExternalKind :: Type => {
2233
+ self . start_group ( "type " ) ;
2234
+ }
2235
+ }
2210
2236
Ok ( ( ) )
2211
2237
}
2212
2238
@@ -2216,29 +2242,24 @@ impl Printer {
2216
2242
kind : ComponentExternalKind ,
2217
2243
index : u32 ,
2218
2244
) -> Result < ( ) > {
2245
+ self . start_component_external_kind_group ( kind) ?;
2219
2246
match kind {
2220
2247
ComponentExternalKind :: Module => {
2221
- self . start_group ( "core module " ) ;
2222
2248
self . print_idx ( & state. core . module_names , index) ?;
2223
2249
}
2224
2250
ComponentExternalKind :: Component => {
2225
- self . start_group ( "component " ) ;
2226
2251
self . print_idx ( & state. component . component_names , index) ?;
2227
2252
}
2228
2253
ComponentExternalKind :: Instance => {
2229
- self . start_group ( "instance " ) ;
2230
2254
self . print_idx ( & state. component . instance_names , index) ?;
2231
2255
}
2232
2256
ComponentExternalKind :: Func => {
2233
- self . start_group ( "func " ) ;
2234
2257
self . print_idx ( & state. component . func_names , index) ?;
2235
2258
}
2236
2259
ComponentExternalKind :: Value => {
2237
- self . start_group ( "value " ) ;
2238
2260
self . print_idx ( & state. component . value_names , index) ?;
2239
2261
}
2240
2262
ComponentExternalKind :: Type => {
2241
- self . start_group ( "type " ) ;
2242
2263
self . print_idx ( & state. component . type_names , index) ?;
2243
2264
}
2244
2265
}
@@ -2519,50 +2540,9 @@ impl Printer {
2519
2540
self . result . push ( ' ' ) ;
2520
2541
self . print_str ( name) ?;
2521
2542
self . result . push ( ' ' ) ;
2522
- match kind {
2523
- ComponentExternalKind :: Module => {
2524
- self . start_group ( "core module " ) ;
2525
- self . print_name ( & state. core . module_names , state. core . modules ) ?;
2526
- self . end_group ( ) ;
2527
- state. core . modules += 1 ;
2528
- }
2529
- ComponentExternalKind :: Component => {
2530
- self . start_group ( "component " ) ;
2531
- self . print_name (
2532
- & state. component . component_names ,
2533
- state. component . components ,
2534
- ) ?;
2535
- self . end_group ( ) ;
2536
- state. component . components += 1 ;
2537
- }
2538
- ComponentExternalKind :: Instance => {
2539
- self . start_group ( "instance " ) ;
2540
- self . print_name (
2541
- & state. component . instance_names ,
2542
- state. component . instances ,
2543
- ) ?;
2544
- self . end_group ( ) ;
2545
- state. component . instances += 1 ;
2546
- }
2547
- ComponentExternalKind :: Func => {
2548
- self . start_group ( "func " ) ;
2549
- self . print_name ( & state. component . func_names , state. component . funcs ) ?;
2550
- self . end_group ( ) ;
2551
- state. component . funcs += 1 ;
2552
- }
2553
- ComponentExternalKind :: Value => {
2554
- self . start_group ( "value " ) ;
2555
- self . print_name ( & state. component . value_names , state. component . values ) ?;
2556
- self . end_group ( ) ;
2557
- state. component . values += 1 ;
2558
- }
2559
- ComponentExternalKind :: Type => {
2560
- self . start_group ( "type " ) ;
2561
- self . print_name ( & state. component . type_names , state. component . types ) ?;
2562
- self . end_group ( ) ;
2563
- state. component . types += 1 ;
2564
- }
2565
- }
2543
+ self . start_component_external_kind_group ( kind) ?;
2544
+ self . print_component_kind_name ( state, kind) ?;
2545
+ self . end_group ( ) ;
2566
2546
2567
2547
self . end_group ( ) ; // alias export
2568
2548
}
0 commit comments