@@ -218,7 +218,7 @@ pub const Writer = struct {
218218
219219 fn toJSON (self : * const Writer , w : anytype ) ! void {
220220 try w .beginObject ();
221- try writeCommon (self .node , false , w );
221+ try self . writeCommon (self .node , false , w );
222222
223223 {
224224 var registry = self .registry ;
@@ -232,7 +232,7 @@ pub const Writer = struct {
232232 const child = (try parser .nodeListItem (child_nodes , @intCast (i ))) orelse break ;
233233 const child_node = try registry .register (child );
234234 try w .beginObject ();
235- try writeCommon (child_node , true , w );
235+ try self . writeCommon (child_node , true , w );
236236 try w .endObject ();
237237 i += 1 ;
238238 }
@@ -245,7 +245,7 @@ pub const Writer = struct {
245245 try w .endObject ();
246246 }
247247
248- fn writeCommon (node : * const Node , include_child_count : bool , w : anytype ) ! void {
248+ fn writeCommon (self : * const Writer , node : * const Node , include_child_count : bool , w : anytype ) ! void {
249249 try w .objectField ("nodeId" );
250250 try w .write (node .id );
251251
@@ -254,9 +254,11 @@ pub const Writer = struct {
254254
255255 const n = node ._node ;
256256
257- // TODO:
258- // try w.objectField("parentId");
259- // try w.write(pid);
257+ if (try parser .nodeParentNode (n )) | p | {
258+ const parent_node = try self .registry .register (p );
259+ try w .objectField ("parentId" );
260+ try w .write (parent_node .id );
261+ }
260262
261263 try w .objectField ("nodeType" );
262264 try w .write (@intFromEnum (try parser .nodeType (n )));
@@ -461,6 +463,7 @@ test "cdp Node: Writer" {
461463 .xmlVersion = "" ,
462464 .compatibilityMode = "NoQuirksMode" ,
463465 .isScrollable = false ,
466+ .parentId = 1 ,
464467 }, .{
465468 .nodeId = 3 ,
466469 .backendNodeId = 3 ,
@@ -474,6 +477,7 @@ test "cdp Node: Writer" {
474477 .xmlVersion = "" ,
475478 .compatibilityMode = "NoQuirksMode" ,
476479 .isScrollable = false ,
480+ .parentId = 1 ,
477481 } },
478482 }, json );
479483 }
0 commit comments