1
1
import { hydrate_anchor , hydrate_nodes , hydrating } from './hydration.js' ;
2
- import { get_descriptor } from '../utils.js' ;
3
2
import { DEV } from 'esm-env' ;
4
3
import { init_array_prototype_warnings } from '../dev/equality.js' ;
5
4
@@ -15,24 +14,6 @@ var element_prototype;
15
14
/** @type {Text } */
16
15
var text_prototype ;
17
16
18
- /** @type {typeof Node.prototype.appendChild } */
19
- var append_child_method ;
20
-
21
- /** @type {typeof Node.prototype.cloneNode } */
22
- var clone_node_method ;
23
-
24
- /** @type {(this: Node) => ChildNode | null } */
25
- var first_child_get ;
26
-
27
- /** @type {(this: Node) => ChildNode | null } */
28
- var next_sibling_get ;
29
-
30
- /** @type {(this: Node, text: string ) => void } */
31
- var text_content_set ;
32
-
33
- /** @type {(this: Element, class_name: string) => void } */
34
- var class_name_set ;
35
-
36
17
// export these for reference in the compiled code, making global name deduplication unnecessary
37
18
/**
38
19
* @type {Window }
@@ -56,9 +37,6 @@ export function init_operations() {
56
37
element_prototype = Element . prototype ;
57
38
text_prototype = Text . prototype ;
58
39
59
- append_child_method = node_prototype . appendChild ;
60
- clone_node_method = node_prototype . cloneNode ;
61
-
62
40
$window = window ;
63
41
$document = document ;
64
42
@@ -80,47 +58,6 @@ export function init_operations() {
80
58
81
59
init_array_prototype_warnings ( ) ;
82
60
}
83
-
84
- first_child_get = /** @type {(this: Node) => ChildNode | null } */ (
85
- // @ts -ignore
86
- get_descriptor ( node_prototype , 'firstChild' ) . get
87
- ) ;
88
-
89
- next_sibling_get = /** @type {(this: Node) => ChildNode | null } */ (
90
- // @ts -ignore
91
- get_descriptor ( node_prototype , 'nextSibling' ) . get
92
- ) ;
93
-
94
- text_content_set = /** @type {(this: Node, text: string ) => void } */ (
95
- // @ts -ignore
96
- get_descriptor ( node_prototype , 'textContent' ) . set
97
- ) ;
98
-
99
- class_name_set = /** @type {(this: Element, class_name: string) => void } */ (
100
- // @ts -ignore
101
- get_descriptor ( element_prototype , 'className' ) . set
102
- ) ;
103
- }
104
-
105
- /**
106
- * @template {Element} E
107
- * @template {Node} T
108
- * @param {E } element
109
- * @param {T } child
110
- */
111
- export function append_child ( element , child ) {
112
- append_child_method . call ( element , child ) ;
113
- }
114
-
115
- /**
116
- * @template {Node} N
117
- * @param {N } node
118
- * @param {boolean } deep
119
- * @returns {N }
120
- */
121
- /*#__NO_SIDE_EFFECTS__*/
122
- export function clone_node ( node , deep ) {
123
- return /** @type {N } */ ( clone_node_method . call ( node , deep ) ) ;
124
61
}
125
62
126
63
/** @returns {Text } */
@@ -135,7 +72,7 @@ export function empty() {
135
72
*/
136
73
/*#__NO_SIDE_EFFECTS__*/
137
74
export function child ( node ) {
138
- const child = first_child_get . call ( node ) ;
75
+ const child = node . firstChild ;
139
76
if ( ! hydrating ) return child ;
140
77
141
78
// Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
@@ -155,7 +92,7 @@ export function child(node) {
155
92
export function first_child ( fragment , is_text ) {
156
93
if ( ! hydrating ) {
157
94
// when not hydrating, `fragment` is a `DocumentFragment` (the result of calling `open_frag`)
158
- return first_child_get . call ( /** @type {DocumentFragment } */ ( fragment ) ) ;
95
+ return /** @type {DocumentFragment } */ ( fragment ) . firstChild ;
159
96
}
160
97
161
98
// when we _are_ hydrating, `fragment` is an array of nodes
@@ -181,7 +118,7 @@ export function first_child(fragment, is_text) {
181
118
*/
182
119
/*#__NO_SIDE_EFFECTS__*/
183
120
export function sibling ( node , is_text = false ) {
184
- const next_sibling = next_sibling_get . call ( node ) ;
121
+ const next_sibling = node . nextSibling ;
185
122
186
123
if ( ! hydrating ) {
187
124
return next_sibling ;
@@ -205,23 +142,13 @@ export function sibling(node, is_text = false) {
205
142
return hydrate_anchor ( /** @type {Node } */ ( next_sibling ) ) ;
206
143
}
207
144
208
- /**
209
- * @template {Element} N
210
- * @param {N } node
211
- * @param {string } class_name
212
- * @returns {void }
213
- */
214
- export function set_class_name ( node , class_name ) {
215
- class_name_set . call ( node , class_name ) ;
216
- }
217
-
218
145
/**
219
146
* @template {Node} N
220
147
* @param {N } node
221
148
* @returns {void }
222
149
*/
223
150
export function clear_text_content ( node ) {
224
- text_content_set . call ( node , '' ) ;
151
+ node . textContent = '' ;
225
152
}
226
153
227
154
/** @param {string } name */
0 commit comments