import { createCallExpression , ConstantTypes } from '../ast' ; import { isText } from '../../shared' ; import { PatchFlags , NodeTypes } from '../../shared/svu' ; import { getConstantType } from './hoistStatic' ; export const transformText = ( node , context ) => { if ( node . type === NodeTypes . ROOT || node . type === NodeTypes . ELEMENT || node . type === NodeTypes . IF_BRANCH ) { return ( ) => { const children = node . children ; let currentContainer = undefined ; let hasText = false ; for ( let i = 0 ; i < children . length ; i ++ ) { const child = children [ i ] ; if ( isText ( child ) ) { hasText = true ; for ( let j = i + 1 ; j < children . length ; j ++ ) { const next = children [ j ] ; if ( isText ( next ) ) { if ( ! currentContainer ) { currentContainer = children [ i ] = { type : NodeTypes . COMPOUND_EXPRESSION , loc : child . loc , children : [ child ] } ; } currentContainer . children . push ( ` + ` , next ) ; children . splice ( j , 1 ) ; j -- ; } else { currentContainer = undefined ; break ; } } } } if ( ! hasText || ( children . length === 1 && ( node . type === NodeTypes . ROOT || ( node . type === NodeTypes . ELEMENT ) ) ) ) { return ; } for ( let i = 0 ; i < children . length ; i ++ ) { const child = children [ i ] ; if ( isText ( child ) || child . type === NodeTypes . COMPOUND_EXPRESSION ) { const callArgs = [ ] ; if ( child . type !== NodeTypes . TEXT || child . content !== ' ' ) { callArgs . push ( child ) ; } children [ i ] = { type : NodeTypes . TEXT_CALL , content : child , loc : child . loc , codegenNode : createCallExpression ( context . helper ( 'CREATE_TEXT' ) , callArgs ) } ; } } } ; } } ;