/**
 * Production h() function based on Preact by
 * Jason Miller (@developit)
 * Licensed under the MIT License
 * https://github.com/developit/preact/blob/master/LICENSE
 *
 * Modified for Stencil's compiler and vdom
 */ import type * as d from '../../declarations' ; import { BUILD } from '@app-data' ; import { consoleDevError , consoleDevWarn } from '@platform' ; import { isComplexType } from '@utils' ; export const h = ( nodeName , vnodeData , ... children ) : d . VNode => { let child = null ; let key = null ; let slotName = null ; let simple = false ; let lastSimple = false ; let vNodeChildren = [ ] ; const walk = ( c ) => { for ( let i = 0 ; i < c . length ; i ++ ) { child = c [ i ] ; if ( Array . isArray ( child ) ) { walk ( child ) ; } else if ( child != null && typeof child !== 'boolean' ) { if ( ( simple = typeof nodeName !== 'function' && ! isComplexType ( child ) ) ) { child = String ( child ) ; } else if ( BUILD . isDev && typeof nodeName !== 'function' && child . $flags$ === undefined ) { consoleDevError ( `vNode passed as children has unexpected type.
Make sure it's using the correct h() function.
Empty objects can also be the cause, look for JSX comments that became objects.` ) ; } if ( simple && lastSimple ) { vNodeChildren [ vNodeChildren . length - 1 ] . $text$ += child ; } else { vNodeChildren . push ( simple ? newVNode ( null , child ) : child ) ; } lastSimple = simple ; } } } ; walk ( children ) ; if ( vnodeData ) { if ( BUILD . isDev && nodeName === 'input' ) { validateInputProperties ( vnodeData ) ; } if ( BUILD . vdomKey && vnodeData . key ) { key = vnodeData . key ; } if ( BUILD . slotRelocation && vnodeData . name ) { slotName = vnodeData . name ; } if ( BUILD . vdomClass ) { const classData = vnodeData . className || vnodeData . class ; if ( classData ) { vnodeData . class = typeof classData !== 'object' ? classData : Object . keys ( classData ) . filter ( ( k ) => classData [ k ] ) . join ( ' ' ) ; } } } if ( BUILD . isDev && vNodeChildren . some ( isHost ) ) { consoleDevError ( `The <Host> must be the single root component. Make sure:
- You are NOT using hostData() and <Host> in the same component.
- <Host> is used once, and it's the single root component of the render() function.` ) ; } if ( BUILD . vdomFunctional && typeof nodeName === 'function' ) { return ( nodeName as d . FunctionalComponent < any > ) ( vnodeData === null ? { } : vnodeData , vNodeChildren , vdomFnUtils ) as any ; } const vnode = newVNode ( nodeName , null ) ; vnode . $attrs$ = vnodeData ; if ( vNodeChildren . length > 0 ) { vnode . $children$ = vNodeChildren ; } if ( BUILD . vdomKey ) { vnode . $key$ = key ; } if ( BUILD . slotRelocation ) { vnode . $name$ = slotName ; } return vnode ; } ; export const newVNode = ( tag , text ) => { const vnode = { $flags$ : 0 , $tag$ : tag , $text$ : text , $elm$ : null , $children$ : null , } ; if ( BUILD . vdomAttribute ) { vnode . $attrs$ = null ; } if ( BUILD . vdomKey ) { vnode . $key$ = null ; } if ( BUILD . slotRelocation ) { vnode . $name$ = null ; } return vnode ; } ; export const Host = { } ; export const isHost = ( node ) : node is d . VNode => node && node . $tag$ === Host ; const vdomFnUtils = { forEach : ( children , cb ) => children . map ( convertToPublic ) . forEach ( cb ) , map : ( children , cb ) => children . map ( convertToPublic ) . map ( cb ) . map ( convertToPrivate ) , } ; const convertToPublic = ( node ) : d . ChildNode => ( { vattrs : node . $attrs$ , vchildren : node . $children$ , vkey : node . $key$ , vname : node . $name$ , vtag : node . $tag$ , vtext : node . $text$ , } ) ; const convertToPrivate = ( node ) : d . VNode => { if ( typeof node . vtag === 'function' ) { const vnodeData = { ... node . vattrs } ; if ( node . vkey ) { vnodeData . key = node . vkey ; } if ( node . vname ) { vnodeData . name = node . vname ; } return h ( node . vtag , vnodeData , ... ( node . vchildren || [ ] ) ) ; } const vnode = newVNode ( node . vtag as any , node . vtext ) ; vnode . $attrs$ = node . vattrs ; vnode . $children$ = node . vchildren ; vnode . $key$ = node . vkey ; vnode . $name$ = node . vname ; return vnode ; } ; param inputElm const validateInputProperties = ( inputElm ) : void => { const props = Object . keys ( inputElm ) ; const value = props . indexOf ( 'value' ) ; if ( value === - 1 ) { return ; } const typeIndex = props . indexOf ( 'type' ) ; const minIndex = props . indexOf ( 'min' ) ; const maxIndex = props . indexOf ( 'max' ) ; const stepIndex = props . indexOf ( 'step' ) ; if ( value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex ) { consoleDevWarn ( `The "value" prop of <input> should be set after "min", "max", "type" and "step"` ) ; } } ;