Skip to content

Commit 6e67bcf

Browse files
committed
tweak
1 parent 4066f0c commit 6e67bcf

5 files changed

Lines changed: 19 additions & 23 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import {
3030
EACH_IS_CONTROLLED,
3131
EACH_IS_IMMUTABLE,
3232
EACH_ITEM_REACTIVE,
33-
EACH_KEYED,
34-
namespace_svg
33+
EACH_KEYED
3534
} from '../../../../../constants.js';
3635
import { regex_is_valid_identifier } from '../../../patterns.js';
3736
import { javascript_visitors_runes } from './javascript-runes.js';
@@ -2076,8 +2075,6 @@ export const template_visitors = {
20762075
/** @type {import('estree').ExpressionStatement[]} */
20772076
const lets = [];
20782077

2079-
const namespace = determine_namespace_for_children(node, context.state.metadata.namespace);
2080-
20812078
// Create a temporary context which picks up the init/update statements.
20822079
// They'll then be added to the function parameter of $.element
20832080
const element_id = b.id(context.state.scope.generate('$$element'));
@@ -2126,7 +2123,7 @@ export const template_visitors = {
21262123

21272124
const get_tag = b.thunk(/** @type {import('estree').Expression} */ (context.visit(node.tag)));
21282125

2129-
if (context.state.options.dev && namespace !== 'foreign') {
2126+
if (context.state.options.dev && context.state.metadata.namespace !== 'foreign') {
21302127
if (node.fragment.nodes.length > 0) {
21312128
context.state.init.push(b.stmt(b.call('$.validate_void_dynamic_element', get_tag)));
21322129
}
@@ -2153,7 +2150,7 @@ export const template_visitors = {
21532150
...context.state,
21542151
metadata: {
21552152
...context.state.metadata,
2156-
namespace
2153+
namespace: determine_namespace_for_children(node, context.state.metadata.namespace)
21572154
}
21582155
}
21592156
})
@@ -2164,7 +2161,11 @@ export const template_visitors = {
21642161
'$.element',
21652162
context.state.node,
21662163
get_tag,
2167-
namespace === 'svg' ? b.id('$.namespace_svg') : b.literal(null),
2164+
node.metadata.svg === true
2165+
? b.true
2166+
: node.metadata.svg === false
2167+
? b.false
2168+
: b.literal(null),
21682169
inner.length === 0
21692170
? /** @type {any} */ (undefined)
21702171
: b.arrow([element_id, b.id('$$anchor')], b.block(inner))

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ export interface SvelteElement extends BaseElement {
310310
tag: Expression;
311311
metadata: {
312312
/**
313-
* `true` if this is definitely an svg element.
314-
* `false` could still mean that it is one, but we can't know statically.
313+
* `true`/`false` if this is definitely (not) an svg element.
314+
* `null` means we can't know statically.
315315
*/
316-
svg: boolean;
316+
svg: boolean | null;
317317
};
318318
}
319319

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,11 +1601,11 @@ function swap_block_dom(block, from, to) {
16011601
/**
16021602
* @param {Comment} anchor_node
16031603
* @param {() => string} tag_fn
1604-
* @param {null | string} namespace
1604+
* @param {boolean | null} is_svg `null` == not statically known
16051605
* @param {undefined | ((element: Element, anchor: Node) => void)} render_fn
16061606
* @returns {void}
16071607
*/
1608-
export function element(anchor_node, tag_fn, namespace, render_fn) {
1608+
export function element(anchor_node, tag_fn, is_svg, render_fn) {
16091609
const block = create_dynamic_element_block();
16101610
hydrate_block_anchor(anchor_node);
16111611
let has_mounted = false;
@@ -1633,12 +1633,11 @@ export function element(anchor_node, tag_fn, namespace, render_fn) {
16331633
// but on the first render on the client (without hydration) the parent will be undefined,
16341634
// since the anchor is not attached to its parent / the dom yet.
16351635
const ns =
1636-
namespace ??
1637-
(tag === 'svg'
1636+
is_svg || tag === 'svg'
16381637
? namespace_svg
1639-
: anchor_node.parentElement?.tagName === 'foreignObject'
1638+
: is_svg === false || anchor_node.parentElement?.tagName === 'foreignObject'
16401639
? null
1641-
: anchor_node.parentElement?.namespaceURI ?? null);
1640+
: anchor_node.parentElement?.namespaceURI ?? null;
16421641
const next_element = tag
16431642
? current_hydration_fragment !== null
16441643
? /** @type {Element} */ (current_hydration_fragment[0])

packages/svelte/src/internal/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ export {
4040
unwrap,
4141
freeze
4242
} from './client/runtime.js';
43-
4443
export * from './client/each.js';
4544
export * from './client/render.js';
4645
export * from './client/validate.js';
4746
export { raf } from './client/timing.js';
48-
export { namespace_svg } from '../constants.js';
4947
export { proxy, readonly, unstate } from './client/proxy.js';
50-
5148
export { create_custom_element } from './client/custom-element.js';
52-
5349
export {
5450
child,
5551
child_frag,

packages/svelte/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,10 @@ declare module 'svelte/compiler' {
13441344
tag: Expression;
13451345
metadata: {
13461346
/**
1347-
* `true` if this is definitely an svg element.
1348-
* `false` could still mean that it is one, but we can't know statically.
1347+
* `true`/`false` if this is definitely (not) an svg element.
1348+
* `null` means we can't know statically.
13491349
*/
1350-
svg: boolean;
1350+
svg: boolean | null;
13511351
};
13521352
}
13531353

0 commit comments

Comments
 (0)