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
: this.node.name.toUpperCase(); : this.node.name.toUpperCase();
const svg = this.node.namespace === namespaces.svg ? '@svg_element' : null; if (this.node.namespace === namespaces.svg) {
return x`@claim_svg_element(${nodes}, "${name}", { ${attributes} })`;
return x`@claim_element(${nodes}, "${name}", { ${attributes} }, ${svg})`; } else {
return x`@claim_element(${nodes}, "${name}", { ${attributes} })`;
}
} }
add_directives_in_order (block: Block) { add_directives_in_order (block: Block) {

@ -433,7 +433,7 @@ function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (no
return resultNode; 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>( return claim_node<Element | SVGElement>(
nodes, nodes,
(node: ChildNode): node is Element | SVGElement => node.nodeName === name, (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) { export function claim_text(nodes: ChildNodeArray, data) {
return claim_node<Text>( return claim_node<Text>(
nodes, nodes,

@ -3,7 +3,7 @@ import {
SvelteComponent, SvelteComponent,
append_hydration, append_hydration,
children, children,
claim_element, claim_svg_element,
claim_text, claim_text,
detach, detach,
init, init,
@ -26,9 +26,9 @@ function create_fragment(ctx) {
t = text("a title"); t = text("a title");
}, },
l(nodes) { l(nodes) {
svg = claim_element(nodes, "svg", {}, svg_element); svg = claim_svg_element(nodes, "svg", {});
var svg_nodes = children(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); var title_nodes = children(title);
t = claim_text(title_nodes, "a title"); t = claim_text(title_nodes, "a title");
title_nodes.forEach(detach); title_nodes.forEach(detach);

Loading…
Cancel
Save