@@ -8,6 +8,11 @@ import fix_attribute_casing from './fix-attribute-casing.js';
88 * @param {Node[] } items
99 */
1010export function template_to_functions ( items ) {
11+ // if the first item is a comment we need to add another comment for effect.start
12+ if ( items [ 0 ] . type === 'anchor' ) {
13+ items . unshift ( { type : 'anchor' , data : undefined } ) ;
14+ }
15+
1116 return b . array ( items . map ( build ) ) ;
1217}
1318
@@ -25,15 +30,31 @@ function build(item) {
2530 b . id ( 'p' ) ,
2631 b . object (
2732 entries . map ( ( [ key , value ] ) => {
28- return b . prop ( 'init' , b . key ( key ) , value === undefined ? b . void0 : b . literal ( value ) ) ;
33+ return b . prop (
34+ 'init' ,
35+ b . key ( fix_attribute_casing ( key ) ) ,
36+ value === undefined ? b . void0 : b . literal ( value )
37+ ) ;
2938 } )
3039 )
3140 )
3241 ) ;
3342 }
3443
3544 if ( item . children . length > 0 ) {
36- element . properties . push ( b . prop ( 'init' , b . id ( 'c' ) , b . array ( item . children . map ( build ) ) ) ) ;
45+ const children = item . children . map ( build ) ;
46+ element . properties . push ( b . prop ( 'init' , b . id ( 'c' ) , b . array ( children ) ) ) ;
47+
48+ // special case — strip leading newline from `<pre>` and `<textarea>`
49+ if ( item . name === 'pre' || item . name === 'textarea' ) {
50+ const first = children [ 0 ] ;
51+ if ( first ?. type === 'Literal' ) {
52+ first . value = /** @type {string } */ ( first . value ) . replace (
53+ regex_starts_with_newline ,
54+ ''
55+ ) ;
56+ }
57+ }
3758 }
3859
3960 return element ;
0 commit comments