Skip to content

Commit 0aa1abc

Browse files
committed
WIP
1 parent 28f4314 commit 0aa1abc

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

packages/svelte/src/compiler/phases/1-parse/read/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { namespace_svg } from '../../../../constants.js';
12
import { error } from '../../../errors.js';
23

34
const regex_valid_tag_name = /^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/;
@@ -156,7 +157,7 @@ export default function read_options(node) {
156157
error(attribute, 'invalid-svelte-option-namespace');
157158
}
158159

159-
if (value === 'http://www.w3.org/2000/svg') {
160+
if (value === namespace_svg) {
160161
component_options.namespace = 'svg';
161162
} else if (value === 'html' || value === 'svg' || value === 'foreign') {
162163
component_options.namespace = value;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,7 @@ export const template_visitors = {
21022102
context.state.node,
21032103
get_tag,
21042104
b.arrow([element_id, b.id('$$anchor')], b.block(inner)),
2105-
namespace === 'http://www.w3.org/2000/svg'
2106-
? b.literal(true)
2107-
: /** @type {any} */ (undefined)
2105+
namespace ? b.literal(namespace) : /** @type {any} */ (undefined)
21082106
)
21092107
)
21102108
);

packages/svelte/src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ export const DOMBooleanAttributes = [
7777
'seamless',
7878
'selected'
7979
];
80+
81+
export const namespace_svg = 'http://www.w3.org/2000/svg';
82+
export const namespace_html = 'http://www.w3.org/1999/xhtml';

packages/svelte/src/internal/client/render.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import {
2828
EACH_ITEM_REACTIVE,
2929
PassiveDelegatedEvents,
3030
DelegatedEvents,
31-
AttributeAliases
31+
AttributeAliases,
32+
namespace_svg,
33+
namespace_html
3234
} from '../../constants.js';
3335
import {
3436
create_fragment_from_html,
@@ -1543,10 +1545,10 @@ function swap_block_dom(block, from, to) {
15431545
* @param {Comment} anchor_node
15441546
* @param {() => string} tag_fn
15451547
* @param {null | ((element: Element, anchor: Node) => void)} render_fn
1546-
* @param {any} is_svg
1548+
* @param {string} namespace
15471549
* @returns {void}
15481550
*/
1549-
export function element(anchor_node, tag_fn, render_fn, is_svg = false) {
1551+
export function element(anchor_node, tag_fn, render_fn, namespace) {
15501552
const block = create_dynamic_element_block();
15511553
hydrate_block_anchor(anchor_node);
15521554
let has_mounted = false;
@@ -1570,11 +1572,13 @@ export function element(anchor_node, tag_fn, render_fn, is_svg = false) {
15701572
// Managed effect
15711573
const render_effect_signal = render_effect(
15721574
() => {
1575+
const ns = namespace ?? tag === 'svg' ? namespace_svg : null;
1576+
console.log(anchor_node);
15731577
const next_element = tag
15741578
? current_hydration_fragment !== null
15751579
? /** @type {HTMLElement | SVGElement} */ (current_hydration_fragment[0])
1576-
: is_svg
1577-
? document.createElementNS('http://www.w3.org/2000/svg', tag)
1580+
: ns
1581+
? document.createElementNS(ns, tag)
15781582
: document.createElement(tag)
15791583
: null;
15801584
const prev_element = element;
@@ -2327,7 +2331,7 @@ export function cssProps(anchor, is_html, props, component) {
23272331
tag = document.createElement('div');
23282332
tag.style.display = 'contents';
23292333
} else {
2330-
tag = document.createElementNS('http://www.w3.org/2000/svg', 'g');
2334+
tag = document.createElementNS(namespace_svg, 'g');
23312335
}
23322336
insert(tag, null, anchor);
23332337
component_anchor = empty();
@@ -2821,7 +2825,7 @@ export function spread_dynamic_element_attributes(node, prev, attrs, css_hash) {
28212825
/** @type {Element & ElementCSSInlineStyle} */ (node),
28222826
prev,
28232827
attrs,
2824-
node.namespaceURI !== 'http://www.w3.org/2000/svg',
2828+
node.namespaceURI !== namespace_svg,
28252829
css_hash
28262830
);
28272831
}

0 commit comments

Comments
 (0)