@ -1,5 +1,4 @@
/** @import { Expression } from 'estree' */
/** @import { Expression } from 'estree' */
/** @import { Location } from 'locate-character' */
/** @import { AST } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext, ComponentServerTransformState } from '../types.js' */
/** @import { ComponentContext, ComponentServerTransformState } from '../types.js' */
/** @import { Scope } from '../../../scope.js' */
/** @import { Scope } from '../../../scope.js' */
@ -8,13 +7,7 @@ import { dev, locator } from '../../../../state.js';
import * as b from '#compiler/builders' ;
import * as b from '#compiler/builders' ;
import { clean _nodes , determine _namespace _for _children } from '../../utils.js' ;
import { clean _nodes , determine _namespace _for _children } from '../../utils.js' ;
import { build _element _attributes , prepare _element _spread _object } from './shared/element.js' ;
import { build _element _attributes , prepare _element _spread _object } from './shared/element.js' ;
import {
import { process _children , build _template , PromiseOptimiser } from './shared/utils.js' ;
process _children ,
build _template ,
create _child _block ,
PromiseOptimiser ,
create _async _block
} from './shared/utils.js' ;
import { is _customizable _select _element } from '../../../nodes.js' ;
import { is _customizable _select _element } from '../../../nodes.js' ;
/ * *
/ * *
@ -66,17 +59,9 @@ export function RegularElement(node, context) {
b . literal ( ` </ ${ node . name } > ` )
b . literal ( ` </ ${ node . name } > ` )
) ;
) ;
// TODO this is a real edge case, would be good to DRY this out
context . state . template . push (
if ( optimiser . expressions . length > 0 ) {
... optimiser . render ( [ ... state . init , ... build _template ( state . template ) ] )
context . state . template . push (
) ;
create _child _block (
b . block ( [ optimiser . apply ( ) , ... state . init , ... build _template ( state . template ) ] )
)
) ;
} else {
context . state . init . push ( ... state . init ) ;
context . state . template . push ( ... state . template ) ;
}
return ;
return ;
}
}
@ -130,13 +115,7 @@ export function RegularElement(node, context) {
const statement = b . stmt ( b . call ( '$$renderer.select' , attributes , fn , ... rest ) ) ;
const statement = b . stmt ( b . call ( '$$renderer.select' , attributes , fn , ... rest ) ) ;
if ( optimiser . expressions . length > 0 ) {
context . state . template . push ( ... optimiser . render ( [ ... state . init , statement ] ) ) ;
context . state . template . push (
create _child _block ( b . block ( [ optimiser . apply ( ) , ... state . init , statement ] ) )
) ;
} else {
context . state . template . push ( ... state . init , statement ) ;
}
return ;
return ;
}
}
@ -183,13 +162,7 @@ export function RegularElement(node, context) {
const statement = b . stmt ( b . call ( '$$renderer.option' , attributes , body , ... rest ) ) ;
const statement = b . stmt ( b . call ( '$$renderer.option' , attributes , body , ... rest ) ) ;
if ( optimiser . expressions . length > 0 ) {
context . state . template . push ( ... optimiser . render ( [ ... state . init , statement ] ) ) ;
context . state . template . push (
create _child _block ( b . block ( [ optimiser . apply ( ) , ... state . init , statement ] ) )
) ;
} else {
context . state . template . push ( ... state . init , statement ) ;
}
return ;
return ;
}
}
@ -235,19 +208,9 @@ export function RegularElement(node, context) {
}
}
if ( optimiser . is _async ( ) ) {
if ( optimiser . is _async ( ) ) {
let statements = [ ... state . init , ... build _template ( state . template ) ] ;
context . state . template . push (
... optimiser . render ( [ ... state . init , ... build _template ( state . template ) ] )
if ( optimiser . has _await ) {
) ;
statements = [ create _child _block ( b . block ( [ optimiser . apply ( ) , ... statements ] ) ) ] ;
}
const blockers = optimiser . blockers ( ) ;
if ( blockers . elements . length > 0 ) {
statements = [ create _async _block ( b . block ( statements ) , blockers , false , false ) ] ;
}
context . state . template . push ( ... statements ) ;
} else {
} else {
context . state . init . push ( ... state . init ) ;
context . state . init . push ( ... state . init ) ;
context . state . template . push ( ... state . template ) ;
context . state . template . push ( ... state . template ) ;