@@ -12,15 +12,8 @@ export function add_locations(fn, filename, locations) {
12
12
return ( /** @type {any[] } */ ...args ) => {
13
13
const dom = fn ( ...args ) ;
14
14
15
- const nodes = hydrating
16
- ? is_array ( dom )
17
- ? dom
18
- : [ dom ]
19
- : dom . nodeType === 11
20
- ? Array . from ( dom . childNodes )
21
- : [ dom ] ;
22
-
23
- assign_locations ( nodes , filename , locations ) ;
15
+ var node = hydrating && is_array ( dom ) ? dom [ 0 ] : dom . nodeType === 11 ? dom . firstChild : dom ;
16
+ assign_locations ( node , filename , locations ) ;
24
17
25
18
return dom ;
26
19
} ;
@@ -38,34 +31,30 @@ function assign_location(element, filename, location) {
38
31
} ;
39
32
40
33
if ( location [ 2 ] ) {
41
- assign_locations (
42
- /** @type {import('#client').TemplateNode[] } */ ( Array . from ( element . childNodes ) ) ,
43
- filename ,
44
- location [ 2 ]
45
- ) ;
34
+ assign_locations ( element . firstChild , filename , location [ 2 ] ) ;
46
35
}
47
36
}
48
37
49
38
/**
50
- * @param {import('#client').TemplateNode[] } nodes
39
+ * @param {Node | null } node
51
40
* @param {string } filename
52
41
* @param {import('../../../compiler/phases/3-transform/client/types.js').SourceLocation[] } locations
53
42
*/
54
- function assign_locations ( nodes , filename , locations ) {
55
- var j = 0 ;
43
+ function assign_locations ( node , filename , locations ) {
44
+ var i = 0 ;
56
45
var depth = 0 ;
57
46
58
- for ( var i = 0 ; i < nodes . length ; i += 1 ) {
59
- var node = nodes [ i ] ;
60
-
47
+ while ( node && i < locations . length ) {
61
48
if ( hydrating && node . nodeType === 8 ) {
62
49
var comment = /** @type {Comment } */ ( node ) ;
63
50
if ( comment . data === HYDRATION_START ) depth += 1 ;
64
- if ( comment . data . startsWith ( HYDRATION_END ) ) depth -= 1 ;
51
+ else if ( comment . data [ 0 ] === HYDRATION_END ) depth -= 1 ;
65
52
}
66
53
67
54
if ( depth === 0 && node . nodeType === 1 ) {
68
- assign_location ( /** @type {Element } */ ( node ) , filename , locations [ j ++ ] ) ;
55
+ assign_location ( /** @type {Element } */ ( node ) , filename , locations [ i ++ ] ) ;
69
56
}
57
+
58
+ node = node . nextSibling ;
70
59
}
71
60
}
0 commit comments