Skip to content

Commit cf44cc1

Browse files
committed
Fix issue of casting a Node[] to a Node in rewrite_props in Component
1 parent d42ca04 commit cf44cc1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/compiler/compile/Component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ export default class Component {
10151015
let scope = instance_scope;
10161016

10171017
walk(this.ast.instance.content, {
1018-
enter(node: Node) {
1018+
enter(node: Node, parent: Node, key, index) {
10191019
if (regex_contains_term_function.test(node.type)) {
10201020
return this.skip();
10211021
}
@@ -1138,11 +1138,16 @@ export default class Component {
11381138
}
11391139
}
11401140

1141-
this.replace(b`
1142-
${node.declarations.length ? node : null}
1143-
${ props.length > 0 && b`let { ${props} } = $$props;`}
1144-
${inserts}
1145-
` as any);
1141+
if (inserts.length > 0) {
1142+
parent[key].splice(index + 1, 0, ...inserts);
1143+
}
1144+
if (props.length > 0) {
1145+
parent[key].splice(index + 1, 0, b`let { ${props} } = $$props;`);
1146+
}
1147+
if (node.declarations.length == 0) {
1148+
parent[key].splice(index, 1);
1149+
}
1150+
11461151
return this.skip();
11471152
}
11481153
}

0 commit comments

Comments
 (0)