@ -33,21 +33,34 @@ export function SvelteBoundary(node, context) {
const nodes = [ ] ;
/** @type {Statement[]} */
const snippet _statements = [ ] ;
const external _statements = [ ] ;
const snippets _visits = [ ] ;
// Capture the `failed` implicit snippet prop
for ( const child of node . fragment . nodes ) {
if ( child . type === 'SnippetBlock' && child . expression . name === 'failed' ) {
// we need to delay the visit of the snippets in case they access a ConstTag that is declared
// after the snippets so that the visitor for the const tag can be updated
snippets _visits . push ( ( ) => {
/** @type {Statement[]} */
const init = [ ] ;
context . visit ( child , { ... context . state , init } ) ;
props . properties . push ( b . prop ( 'init' , child . expression , child . expression ) ) ;
external _statements . push ( ... init ) ;
} ) ;
} else if ( child . type === 'ConstTag' ) {
/** @type {Statement[]} */
const init = [ ] ;
context . visit ( child , { ... context . state , init } ) ;
props . properties . push ( b . prop ( 'init' , child . expression , child . expression ) ) ;
snippet _statements . push ( ... init ) ;
external _statements . push ( ... init ) ;
} else {
nodes . push ( child ) ;
}
}
snippets _visits . forEach ( ( visit ) => visit ( ) ) ;
const block = /** @type {BlockStatement} */ ( context . visit ( { ... node . fragment , nodes } ) ) ;
const boundary = b . stmt (
@ -56,6 +69,6 @@ export function SvelteBoundary(node, context) {
context . state . template . push ( '<!>' ) ;
context . state . init . push (
snipp et_statements . length > 0 ? b . block ( [ ... snipp et_statements , boundary ] ) : boundary
ex ternal _statements . length > 0 ? b . block ( [ ... ex ternal _statements , boundary ] ) : boundary
) ;
}