Skip to content

Commit 1e6d85b

Browse files
committed
fixes
1 parent 17f1b6a commit 1e6d85b

File tree

1 file changed

+23
-2
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/transform-template

1 file changed

+23
-2
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-functions.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import fix_attribute_casing from './fix-attribute-casing.js';
88
* @param {Node[]} items
99
*/
1010
export 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

Comments
 (0)