File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
- import snapshot , { serializeNodeWithId , transformAttribute } from './snapshot' ;
1
+ import snapshot , {
2
+ serializeNodeWithId ,
3
+ transformAttribute ,
4
+ visit ,
5
+ } from './snapshot' ;
2
6
import rebuild , { buildNodeWithSN , addHoverClass } from './rebuild' ;
3
7
export * from './types' ;
4
8
@@ -9,4 +13,5 @@ export {
9
13
buildNodeWithSN ,
10
14
addHoverClass ,
11
15
transformAttribute ,
16
+ visit ,
12
17
} ;
Original file line number Diff line number Diff line change @@ -425,4 +425,21 @@ function snapshot(
425
425
] ;
426
426
}
427
427
428
+ export function visit (
429
+ node : serializedNodeWithId ,
430
+ onVisit : ( node : serializedNodeWithId ) => unknown ,
431
+ ) {
432
+ function walk ( current : serializedNodeWithId ) {
433
+ onVisit ( current ) ;
434
+ if (
435
+ current . type === NodeType . Document ||
436
+ current . type === NodeType . Element
437
+ ) {
438
+ current . childNodes . forEach ( walk ) ;
439
+ }
440
+ }
441
+
442
+ walk ( node ) ;
443
+ }
444
+
428
445
export default snapshot ;
You can’t perform that action at this time.
0 commit comments