@@ -520,11 +520,25 @@ const defaultMethods = {
520520 } ,
521521 '!' : ( value , _1 , _2 , engine ) => Array . isArray ( value ) ? ! engine . truthy ( value [ 0 ] ) : ! engine . truthy ( value ) ,
522522 '!!' : ( value , _1 , _2 , engine ) => Boolean ( Array . isArray ( value ) ? engine . truthy ( value [ 0 ] ) : engine . truthy ( value ) ) ,
523- cat : ( arr ) => {
524- if ( typeof arr === 'string' ) return arr
525- let res = ''
526- for ( let i = 0 ; i < arr . length ; i ++ ) res += arr [ i ]
527- return res
523+ cat : {
524+ method : ( arr ) => {
525+ if ( typeof arr === 'string' ) return arr
526+ if ( ! Array . isArray ( arr ) ) return arr . toString ( )
527+ let res = ''
528+ for ( let i = 0 ; i < arr . length ; i ++ ) res += arr [ i ] . toString ( )
529+ return res
530+ } ,
531+ deterministic : true ,
532+ traverse : true ,
533+ optimizeUnary : true ,
534+ compile : ( data , buildState ) => {
535+ if ( typeof data === 'string' ) return JSON . stringify ( data )
536+ if ( typeof data === 'number' ) return '"' + JSON . stringify ( data ) + '"'
537+ if ( ! Array . isArray ( data ) ) return false
538+ let res = buildState . compile `''`
539+ for ( let i = 0 ; i < data . length ; i ++ ) res = buildState . compile `${ res } + ${ data [ i ] } `
540+ return buildState . compile `(${ res } )`
541+ }
528542 } ,
529543 keys : ( [ obj ] ) => typeof obj === 'object' ? Object . keys ( obj ) : [ ] ,
530544 pipe : {
@@ -843,14 +857,6 @@ defaultMethods['*'].compile = function (data, buildState) {
843857 return `(${ buildString ( data , buildState ) } ).reduce((a,b) => (+a)*(+b))`
844858 }
845859}
846- // @ts -ignore Allow custom attribute
847- defaultMethods . cat . compile = function ( data , buildState ) {
848- if ( typeof data === 'string' ) return JSON . stringify ( data )
849- if ( ! Array . isArray ( data ) ) return false
850- let res = buildState . compile `''`
851- for ( let i = 0 ; i < data . length ; i ++ ) res = buildState . compile `${ res } + ${ data [ i ] } `
852- return buildState . compile `(${ res } )`
853- }
854860
855861// @ts -ignore Allow custom attribute
856862defaultMethods [ '!' ] . compile = function (
0 commit comments