@ -2,7 +2,8 @@ import { set_current_component, current_component } from './lifecycle';
import { run _all , blank _object } from './utils' ;
import { boolean _attributes } from '../../shared/boolean_attributes' ;
export { is _void } from '../../shared/utils/names' ;
export const invalid _attribute _name _character = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u ;
export const invalid _attribute _name _character =
/[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u ;
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
// https://infra.spec.whatwg.org/#noncharacter
/** @returns {string} */
@ -14,32 +15,28 @@ export function spread(args, attrs_to_add) {
if ( classes _to _add ) {
if ( attributes . class == null ) {
attributes . class = classes _to _add ;
}
else {
} else {
attributes . class += ' ' + classes _to _add ;
}
}
if ( styles _to _add ) {
if ( attributes . style == null ) {
attributes . style = style _object _to _string ( styles _to _add ) ;
}
else {
attributes . style = style _object _to _string ( merge _ssr _styles ( attributes . style , styles _to _add ) ) ;
} else {
attributes . style = style _object _to _string (
merge _ssr _styles ( attributes . style , styles _to _add )
) ;
}
}
}
let str = '' ;
Object . keys ( attributes ) . forEach ( ( name ) => {
if ( invalid _attribute _name _character . test ( name ) )
return ;
if ( invalid _attribute _name _character . test ( name ) ) return ;
const value = attributes [ name ] ;
if ( value === true )
str += ' ' + name ;
if ( value === true ) str += ' ' + name ;
else if ( boolean _attributes . has ( name . toLowerCase ( ) ) ) {
if ( value )
str += ' ' + name ;
}
else if ( value != null ) {
if ( value ) str += ' ' + name ;
} else if ( value != null ) {
str += ` ${ name } =" ${ value } " ` ;
}
} ) ;
@ -52,16 +49,14 @@ export function merge_ssr_styles(style_attribute, style_directive) {
const colon _index = individual _style . indexOf ( ':' ) ;
const name = individual _style . slice ( 0 , colon _index ) . trim ( ) ;
const value = individual _style . slice ( colon _index + 1 ) . trim ( ) ;
if ( ! name )
continue ;
if ( ! name ) continue ;
style _object [ name ] = value ;
}
for ( const name in style _directive ) {
const value = style _directive [ name ] ;
if ( value ) {
style _object [ name ] = value ;
}
else {
} else {
delete style _object [ name ] ;
}
}
@ -117,9 +112,10 @@ export const missing_component = {
/** @returns {any} */
export function validate _component ( component , name ) {
if ( ! component || ! component . $$render ) {
if ( name === 'svelte:component' )
name += ' this={...}' ;
throw new Error ( ` < ${ name } > is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix a < ${ name } >. ` ) ;
if ( name === 'svelte:component' ) name += ' this={...}' ;
throw new Error (
` < ${ name } > is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix a < ${ name } >. `
) ;
}
return component ;
}
@ -171,8 +167,7 @@ export function create_ssr_component(fn) {
}
/** @returns {string} */
export function add _attribute ( name , value , boolean ) {
if ( value == null || ( boolean && ! value ) )
return '' ;
if ( value == null || ( boolean && ! value ) ) return '' ;
const assignment = boolean && value === true ? '' : ` =" ${ escape ( value , true ) } " ` ;
return ` ${ name } ${ assignment } ` ;
}
@ -192,7 +187,3 @@ export function add_styles(style_object) {
const styles = style _object _to _string ( style _object ) ;
return styles ? ` style=" ${ styles } " ` : '' ;
}