@ -38,9 +38,11 @@ import { TEMPLATE_FRAGMENT } from '../../../../../constants.js';
* @ param { ComponentContext } context
* /
export function RegularElement ( node , context ) {
context . state . template . push _element ( node . name , node . start ) ;
const is _html = context . state . metadata . namespace === 'html' && node . name !== 'svg' ;
const name = is _html ? node . name . toLowerCase ( ) : node . name ;
context . state . template . push _element ( name , node . start , is _html ) ;
if ( node . name === 'noscript' ) {
if ( n ame === 'noscript' ) {
context . state . template . pop _element ( ) ;
return ;
}
@ -53,9 +55,9 @@ export function RegularElement(node, context) {
// Therefore we need to use importNode instead, which doesn't have this caveat.
// Additionally, Webkit browsers need importNode for video elements for autoplay
// to work correctly.
context . state . template . needs _import _node || = n ode. n ame === 'video' || is _custom _element ;
context . state . template . needs _import _node || = n ame === 'video' || is _custom _element ;
context . state . template . contains _script _tag || = n ode. n ame === 'script' ;
context . state . template . contains _script _tag || = n ame === 'script' ;
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
const attributes = [ ] ;
@ -161,7 +163,7 @@ export function RegularElement(node, context) {
}
}
if ( n ode. n ame === 'input' ) {
if ( n ame === 'input' ) {
const has _value _attribute = attributes . some (
( attribute ) =>
attribute . type === 'Attribute' &&
@ -190,7 +192,7 @@ export function RegularElement(node, context) {
}
}
if ( n ode. n ame === 'textarea' ) {
if ( n ame === 'textarea' ) {
const attribute = lookup . get ( 'value' ) ? ? lookup . get ( 'checked' ) ;
const needs _content _reset = attribute && ! is _text _attribute ( attribute ) ;
@ -206,10 +208,7 @@ export function RegularElement(node, context) {
/** If true, needs `__value` for inputs */
const needs _special _value _handling =
node . name === 'option' ||
node . name === 'select' ||
bindings . has ( 'group' ) ||
bindings . has ( 'checked' ) ;
name === 'option' || name === 'select' || bindings . has ( 'group' ) || bindings . has ( 'checked' ) ;
if ( has _spread ) {
build _attribute _effect (
@ -258,7 +257,6 @@ export function RegularElement(node, context) {
let { value } = build _attribute _value ( attribute . value , context ) ;
context . state . init . push ( b . stmt ( b . call ( '$.autofocus' , node _id , value ) ) ) ;
} else if ( name === 'class' ) {
const is _html = context . state . metadata . namespace === 'html' && node . name !== 'svg' ;
build _set _class ( node , node _id , attribute , class _directives , context , is _html ) ;
} else if ( name === 'style' ) {
build _set _style ( node _id , attribute , style _directives , context ) ;
@ -279,7 +277,7 @@ export function RegularElement(node, context) {
}
if (
is _load _error _element ( n ode. n ame) &&
is _load _error _element ( n ame) &&
( has _spread || has _use || lookup . has ( 'onload' ) || lookup . has ( 'onerror' ) )
) {
context . state . after _update . push ( b . stmt ( b . call ( '$.replay_events' , node _id ) ) ) ;
@ -307,8 +305,7 @@ export function RegularElement(node, context) {
... context . state ,
metadata ,
scope : /** @type {Scope} */ ( context . state . scopes . get ( node . fragment ) ) ,
preserve _whitespace :
context . state . preserve _whitespace || node . name === 'pre' || node . name === 'textarea'
preserve _whitespace : context . state . preserve _whitespace || name === 'pre' || name === 'textarea'
} ;
const { hoisted , trimmed } = clean _nodes (
@ -317,7 +314,7 @@ export function RegularElement(node, context) {
context . path ,
state . metadata . namespace ,
state ,
n ode. n ame === 'script' || state . preserve _whitespace ,
n ame === 'script' || state . preserve _whitespace ,
state . options . preserveComments
) ;
@ -363,7 +360,7 @@ export function RegularElement(node, context) {
context . state . template . push _comment ( ) ;
// Create a separate template for the rich content
const template _name = context . state . scope . root . unique ( ` ${ n ode. n ame} _content ` ) ;
const template _name = context . state . scope . root . unique ( ` ${ n ame} _content ` ) ;
const fragment _id = b . id ( context . state . scope . generate ( 'fragment' ) ) ;
const anchor _id = b . id ( context . state . scope . generate ( 'anchor' ) ) ;
@ -414,7 +411,7 @@ export function RegularElement(node, context) {
// The same applies if it's a `<template>` element, since we need to
// set the value of `hydrate_node` to `node.content`
if ( n ode. n ame === 'template' ) {
if ( n ame === 'template' ) {
needs _reset = true ;
child _state . init . push ( b . stmt ( b . call ( '$.hydrate_template' , arg ) ) ) ;
arg = b . member ( arg , 'content' ) ;
@ -451,7 +448,7 @@ export function RegularElement(node, context) {
context . state . after _update . push ( ... element _state . after _update ) ;
}
if ( n ode. n ame === 'selectedcontent' ) {
if ( n ame === 'selectedcontent' ) {
context . state . init . push (
b . stmt (
b . call (
@ -483,11 +480,11 @@ export function RegularElement(node, context) {
// this node is an `option` that didn't have a `value` attribute, but had
// a single-expression child, so we treat the value of that expression as
// the value of the option
build _element _special _value _attribute ( n ode. n ame, node _id , synthetic _attribute , context , true ) ;
build _element _special _value _attribute ( n ame, node _id , synthetic _attribute , context , true ) ;
} else {
for ( const attribute of /** @type {AST.Attribute[]} */ ( attributes ) ) {
if ( attribute . name === 'value' ) {
build _element _special _value _attribute ( n ode. n ame, node _id , attribute , context ) ;
build _element _special _value _attribute ( n ame, node _id , attribute , context ) ;
break ;
}
}