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' ;
26import rebuild , { buildNodeWithSN , addHoverClass } from './rebuild' ;
37export * from './types' ;
48
@@ -9,4 +13,5 @@ export {
913 buildNodeWithSN ,
1014 addHoverClass ,
1115 transformAttribute ,
16+ visit ,
1217} ;
Original file line number Diff line number Diff line change @@ -425,4 +425,21 @@ function snapshot(
425425 ] ;
426426}
427427
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+
428445export default snapshot ;
You can’t perform that action at this time.
0 commit comments