@@ -3,7 +3,7 @@ import { source, set, get } from './runtime.js';
3
3
4
4
/**
5
5
* @template {any[]} ComponentArgs
6
- * @template {Record<string, any> | undefined} ComponentReturn
6
+ * @template {Record<string | symbol , any> | undefined} ComponentReturn
7
7
* @template {(...args: ComponentArgs) => ComponentReturn} Component
8
8
*
9
9
* @param {{
@@ -20,31 +20,28 @@ export function hmr(hot_data, component) {
20
20
21
21
// @ts -ignore
22
22
hot_data . proxy = function ( target , ...args ) {
23
- /** @type {ComponentReturn } */
24
- let current_accessors ;
23
+ const accessors = source ( /** @type {ComponentReturn } */ ( { } ) ) ;
25
24
26
25
key (
27
26
target ,
28
27
( ) => get ( component_signal ) ,
29
28
( $$anchor ) => {
30
29
const current_component = get ( component_signal ) ;
31
30
// @ts -ignore
32
- current_accessors = current_component ( $$anchor , ...args ) ;
31
+ const new_accessors = current_component ( $$anchor , ...args ) ;
32
+ set ( accessors , new_accessors ) ;
33
33
}
34
34
) ;
35
35
36
36
return new Proxy (
37
37
{ } ,
38
38
{
39
39
get ( _ , p ) {
40
- // we actually want to crash if no accessors, because no HMR code would crash
41
- // @ts -ignore
42
- return current_accessors [ p ] ;
40
+ return get ( accessors ) ?. [ p ] ;
43
41
} ,
44
42
set ( _ , p , value ) {
45
- // we actually want to crash if no accessors, because no HMR code would crash
46
- // @ts -ignore
47
- current_accessors [ p ] = value ;
43
+ // @ts -ignore (we actually want to crash on undefined, like non HMR code would do)
44
+ get ( accessors ) [ p ] = value ;
48
45
return true ;
49
46
}
50
47
}
0 commit comments