@ -5,6 +5,7 @@ import {
regex _whitespaces _strict
} from '../patterns.js' ;
import * as b from '../../utils/builders.js' ;
import { walk } from 'zimmerframe' ;
/ * *
* @ param { string } s
@ -249,52 +250,50 @@ export function infer_namespace(namespace, parent, nodes, path) {
* @ param { import ( '#compiler' ) . Namespace | 'keep' | 'maybe_html' } namespace
* /
function check _nodes _for _namespace ( nodes , namespace ) {
for ( const node of nodes ) {
if ( node . type === 'RegularElement' || node . type === 'SvelteElement' ) {
/ * *
* @ param { import ( '#compiler' ) . SvelteElement | import ( '#compiler' ) . RegularElement } node }
* @ param { { stop : ( ) => void } } context
* /
const RegularElement = ( node , { stop } ) => {
if ( ! node . metadata . svg ) {
namespace = 'html' ;
break ;
stop ( ) ;
} else if ( namespace === 'keep' ) {
namespace = 'svg' ;
}
} else if (
( node . type === 'Text' && node . data . trim ( ) !== '' ) ||
node . type === 'HtmlTag' ||
node . type === 'RenderTag'
} ;
for ( const node of nodes ) {
walk (
node ,
{ } ,
{
_ ( node , { next } ) {
if (
node . type === 'EachBlock' ||
node . type === 'IfBlock' ||
node . type === 'AwaitBlock' ||
node . type === 'Fragment' ||
node . type === 'KeyBlock' ||
node . type === 'RegularElement' ||
node . type === 'SvelteElement' ||
node . type === 'Text'
) {
next ( ) ;
}
} ,
SvelteElement : RegularElement ,
RegularElement ,
Text ( node ) {
if ( node . data . trim ( ) !== '' ) {
namespace = 'maybe_html' ;
} else if ( node . type === 'EachBlock' ) {
namespace = check _nodes _for _namespace ( node . body . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
if ( node . fallback ) {
namespace = check _nodes _for _namespace ( node . fallback . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
} else if ( node . type === 'IfBlock' ) {
namespace = check _nodes _for _namespace ( node . consequent . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
if ( node . alternate ) {
namespace = check _nodes _for _namespace ( node . alternate . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
} else if ( node . type === 'AwaitBlock' ) {
if ( node . pending ) {
namespace = check _nodes _for _namespace ( node . pending . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
if ( node . then ) {
namespace = check _nodes _for _namespace ( node . then . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
if ( node . catch ) {
namespace = check _nodes _for _namespace ( node . catch . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
} else if ( node . type === 'KeyBlock' ) {
namespace = check _nodes _for _namespace ( node . fragment . nodes , namespace ) ;
if ( namespace === 'html' ) break ;
}
}
}
) ;
if ( namespace === 'html' ) return namespace ;
}
return namespace ;
}