exclude element function if a component includes only svg-elements

pull/6556/head
tomoam 5 years ago
parent 7f0c0b703f
commit 26b56b6da8

@ -388,9 +388,11 @@ export default class ElementWrapper extends Wrapper {
? this.node.name
: this.node.name.toUpperCase();
const svg = this.node.namespace === namespaces.svg ? '@svg_element' : null;
return x`@claim_element(${nodes}, "${name}", { ${attributes} }, ${svg})`;
if (this.node.namespace === namespaces.svg) {
return x`@claim_svg_element(${nodes}, "${name}", { ${attributes} })`;
} else {
return x`@claim_element(${nodes}, "${name}", { ${attributes} })`;
}
}
add_directives_in_order (block: Block) {

@ -433,7 +433,7 @@ function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (no
return resultNode;
}
export function claim_element(nodes: ChildNodeArray, name: string, attributes: { [key: string]: boolean }, create_element: (name: string) => Element | SVGElement = element) {
export function claim_element_base(nodes: ChildNodeArray, name: string, attributes: { [key: string]: boolean }, create_element: (name: string) => Element | SVGElement) {
return claim_node<Element | SVGElement>(
nodes,
(node: ChildNode): node is Element | SVGElement => node.nodeName === name,
@ -452,6 +452,14 @@ export function claim_element(nodes: ChildNodeArray, name: string, attributes: {
);
}
export function claim_element(nodes: ChildNodeArray, name: string, attributes: { [key: string]: boolean }) {
return claim_element_base(nodes, name, attributes, element);
}
export function claim_svg_element(nodes: ChildNodeArray, name: string, attributes: { [key: string]: boolean }) {
return claim_element_base(nodes, name, attributes, svg_element);
}
export function claim_text(nodes: ChildNodeArray, data) {
return claim_node<Text>(
nodes,

@ -3,7 +3,7 @@ import {
SvelteComponent,
append_hydration,
children,
claim_element,
claim_svg_element,
claim_text,
detach,
init,
@ -26,9 +26,9 @@ function create_fragment(ctx) {
t = text("a title");
},
l(nodes) {
svg = claim_element(nodes, "svg", {}, svg_element);
svg = claim_svg_element(nodes, "svg", {});
var svg_nodes = children(svg);
title = claim_element(svg_nodes, "title", {}, svg_element);
title = claim_svg_element(svg_nodes, "title", {});
var title_nodes = children(title);
t = claim_text(title_nodes, "a title");
title_nodes.forEach(detach);
@ -55,4 +55,4 @@ class Component extends SvelteComponent {
}
}
export default Component;
export default Component;

Loading…
Cancel
Save