1313
1414const CACHE = { } ;
1515
16+ const stringify = JSON . stringify ;
17+
1618export default function html ( statics ) {
17- const key = statics . length + statics ;
19+ let key = '.' ;
20+ for ( let i = 0 ; i < statics . length ; i ++ ) key += statics [ i ] . length + ',' + statics [ i ] ;
1821 const tpl = CACHE [ key ] || ( CACHE [ key ] = build ( statics ) ) ;
1922
2023 // eslint-disable-next-line prefer-rest-params
@@ -55,12 +58,12 @@ const build = (statics) => {
5558 if ( ! inTag ) {
5659 if ( field || ( buffer = buffer . replace ( / ^ \s * \n \s * | \s * \n \s * $ / g, '' ) ) ) {
5760 if ( hasChildren ++ ) out += ',' ;
58- out += field || JSON . stringify ( buffer ) ;
61+ out += field || stringify ( buffer ) ;
5962 }
6063 }
6164 else if ( mode === MODE_TAGNAME ) {
6265 if ( hasChildren ++ ) out += ',' ;
63- out += 'h(' + ( field || JSON . stringify ( buffer ) ) ;
66+ out += 'h(' + ( field || stringify ( buffer ) ) ;
6467 mode = MODE_WHITESPACE ;
6568 }
6669 else if ( mode === MODE_ATTRIBUTE || ( mode === MODE_WHITESPACE && buffer === '...' ) ) {
@@ -77,8 +80,8 @@ const build = (statics) => {
7780 if ( ! props ) props += '{' ;
7881 else props += ',' + ( propsClose ? '' : '{' ) ;
7982 propsClose = '}' ;
80- props += JSON . stringify ( propName ) + ':' ;
81- props += field || ( ( propHasValue || buffer ) && JSON . stringify ( buffer ) ) || 'true' ;
83+ props += stringify ( propName ) + ':' ;
84+ props += field || ( ( propHasValue || buffer ) && stringify ( buffer ) ) || 'true' ;
8285 propName = '' ;
8386 }
8487 propHasValue = false ;
0 commit comments