Skip to content

Commit 310f82d

Browse files
committed
move stuff off state.metadata.context and onto state.template
1 parent 9106533 commit 310f82d

File tree

6 files changed

+21
-43
lines changed

6 files changed

+21
-43
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ export function client_component(analysis, options) {
154154
legacy_reactive_imports: [],
155155
legacy_reactive_statements: new Map(),
156156
metadata: {
157-
context: {
158-
template_needs_import_node: false,
159-
template_contains_script_tag: false
160-
},
161157
namespace: options.namespace,
162158
bound_contenteditable: false
163159
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { template_to_string } from './to-string.js';
1414
* @returns
1515
*/
1616
function get_template_function(namespace, state) {
17-
const contains_script_tag = state.metadata.context.template_contains_script_tag;
17+
const contains_script_tag = state.template.contains_script_tag;
1818
return (
1919
namespace === 'svg'
2020
? contains_script_tag

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
/** @import { Node, Element } from './types'; */
33

44
export class Template {
5+
/**
6+
* `true` if HTML template contains a `<script>` tag. In this case we need to invoke a special
7+
* template instantiation function (see `create_fragment_with_script_from_html` for more info)
8+
*/
9+
contains_script_tag = false;
10+
11+
/** `true` if the HTML template needs to be instantiated with `importNode` */
12+
needs_import_node = false;
13+
514
/** @type {Node[]} */
615
nodes = [];
716

packages/svelte/src/compiler/phases/3-transform/client/types.d.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,6 @@ export interface ComponentClientTransformState extends ClientTransformState {
5959
readonly metadata: {
6060
namespace: Namespace;
6161
bound_contenteditable: boolean;
62-
/**
63-
* Stuff that is set within the children of one `Fragment` visitor that is relevant
64-
* to said fragment. Shouldn't be destructured or otherwise spread unless inside the
65-
* `Fragment` visitor to keep the object reference intact (it's also nested
66-
* within `metadata` for this reason).
67-
*/
68-
context: {
69-
/** `true` if the HTML template needs to be instantiated with `importNode` */
70-
template_needs_import_node: boolean;
71-
/**
72-
* `true` if HTML template contains a `<script>` tag. In this case we need to invoke a special
73-
* template instantiation function (see `create_fragment_with_script_from_html` for more info)
74-
*/
75-
template_contains_script_tag: boolean;
76-
};
7762
};
7863
readonly preserve_whitespace: boolean;
7964

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ export function Fragment(node, context) {
7070
locations: [],
7171
transform: { ...context.state.transform },
7272
metadata: {
73-
context: {
74-
template_needs_import_node: false,
75-
template_contains_script_tag: false
76-
},
7773
namespace,
7874
bound_contenteditable: context.state.metadata.bound_contenteditable
7975
}
@@ -98,11 +94,7 @@ export function Fragment(node, context) {
9894
node: id
9995
});
10096

101-
let flags = undefined;
102-
103-
if (state.metadata.context.template_needs_import_node) {
104-
flags = TEMPLATE_USE_IMPORT_NODE;
105-
}
97+
let flags = state.template.needs_import_node ? TEMPLATE_USE_IMPORT_NODE : undefined;
10698

10799
transform_template(state, context, namespace, template_name, flags);
108100

@@ -144,7 +136,7 @@ export function Fragment(node, context) {
144136

145137
let flags = TEMPLATE_FRAGMENT;
146138

147-
if (state.metadata.context.template_needs_import_node) {
139+
if (state.template.needs_import_node) {
148140
flags |= TEMPLATE_USE_IMPORT_NODE;
149141
}
150142

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,15 @@ export function RegularElement(node, context) {
5858

5959
const is_custom_element = is_custom_element_node(node);
6060

61-
if (node.name === 'video' || is_custom_element) {
62-
// cloneNode is faster, but it does not instantiate the underlying class of the
63-
// custom element until the template is connected to the dom, which would
64-
// cause problems when setting properties on the custom element.
65-
// Therefore we need to use importNode instead, which doesn't have this caveat.
66-
// Additionally, Webkit browsers need importNode for video elements for autoplay
67-
// to work correctly.
68-
context.state.metadata.context.template_needs_import_node = true;
69-
}
70-
71-
if (node.name === 'script') {
72-
context.state.metadata.context.template_contains_script_tag = true;
73-
}
61+
// cloneNode is faster, but it does not instantiate the underlying class of the
62+
// custom element until the template is connected to the dom, which would
63+
// cause problems when setting properties on the custom element.
64+
// Therefore we need to use importNode instead, which doesn't have this caveat.
65+
// Additionally, Webkit browsers need importNode for video elements for autoplay
66+
// to work correctly.
67+
context.state.template.needs_import_node ||= node.name === 'video' || is_custom_element;
68+
69+
context.state.template.contains_script_tag ||= node.name === 'script';
7470

7571
context.state.template.create_element(node.name);
7672

0 commit comments

Comments
 (0)