@@ -4,6 +4,21 @@ import { blank_object, is_function, run, run_all, noop, has_prop } from './utils
44import { children } from './dom' ;
55import { transition_in } from './transitions' ;
66
7+ interface Fragment {
8+ key : string | null ;
9+ first : null ;
10+ /* create */ c : ( ) => void ;
11+ /* claim */ l : ( nodes : any ) => void ;
12+ /* hydrate */ h : ( ) => void ;
13+ /* mount */ m : ( target : HTMLElement , anchor : any ) => void ;
14+ /* update */ p : ( changed : any , ctx : any ) => void ;
15+ /* measure */ r : ( ) => void ;
16+ /* fix */ f : ( ) => void ;
17+ /* animate */ a : ( ) => void ;
18+ /* intro */ i : ( local : any ) => void ;
19+ /* outro */ o : ( local : any ) => void ;
20+ /* destroy */ d : ( detaching : 0 | 1 ) => void ;
21+ }
722// eslint-disable-next-line @typescript-eslint/class-name-casing
823interface T$$ {
924 dirty : null ;
@@ -13,7 +28,7 @@ interface T$$ {
1328 callbacks : any ;
1429 after_update : any [ ] ;
1530 props : Record < string , 0 | string > ;
16- fragment : null | any ;
31+ fragment : null | false | Fragment ;
1732 not_equal : any ;
1833 before_update : any [ ] ;
1934 context : Map < any , any > ;
@@ -29,10 +44,18 @@ export function bind(component, name, callback) {
2944 }
3045}
3146
47+ export function create_component ( block ) {
48+ block && block . c ( ) ;
49+ }
50+
51+ export function claim_component ( block , parent_nodes ) {
52+ block && block . l ( parent_nodes ) ;
53+ }
54+
3255export function mount_component ( component , target , anchor ) {
3356 const { fragment, on_mount, on_destroy, after_update } = component . $$ ;
3457
35- fragment . m ( target , anchor ) ;
58+ fragment && fragment . m ( target , anchor ) ;
3659
3760 // onMount happens before the initial afterUpdate
3861 add_render_callback ( ( ) => {
@@ -51,15 +74,16 @@ export function mount_component(component, target, anchor) {
5174}
5275
5376export function destroy_component ( component , detaching ) {
54- if ( component . $$ . fragment ) {
55- run_all ( component . $$ . on_destroy ) ;
77+ const $$ = component . $$ ;
78+ if ( $$ . fragment !== null ) {
79+ run_all ( $$ . on_destroy ) ;
5680
57- component . $$ . fragment . d ( detaching ) ;
81+ $$ . fragment && $$ . fragment . d ( detaching ) ;
5882
5983 // TODO null out other refs, including component.$$ (but need to
6084 // preserve final state?)
61- component . $$ . on_destroy = component . $$ . fragment = null ;
62- component . $$ . ctx = { } ;
85+ $$ . on_destroy = $$ . fragment = null ;
86+ $$ . ctx = { } ;
6387 }
6488}
6589
@@ -115,15 +139,17 @@ export function init(component, options, instance, create_fragment, not_equal, p
115139 $$ . update ( ) ;
116140 ready = true ;
117141 run_all ( $$ . before_update ) ;
118- $$ . fragment = create_fragment ( $$ . ctx ) ;
142+
143+ // `false` as a special case of no DOM component
144+ $$ . fragment = create_fragment ? create_fragment ( $$ . ctx ) : false ;
119145
120146 if ( options . target ) {
121147 if ( options . hydrate ) {
122148 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
123- $$ . fragment ! . l ( children ( options . target ) ) ;
149+ $$ . fragment && $$ . fragment ! . l ( children ( options . target ) ) ;
124150 } else {
125151 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126- $$ . fragment ! . c ( ) ;
152+ $$ . fragment && $$ . fragment ! . c ( ) ;
127153 }
128154
129155 if ( options . intro ) transition_in ( component . $$ . fragment ) ;
0 commit comments