Skip to content

Commit

Permalink
feat(napi): Expose RuleNode#__{children,text} debug view properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Mar 27, 2024
1 parent b9b946e commit 980f664
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/codegen/parser/runtime/src/napi_interface/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ impl RuleNode {
pub fn unparse(&self) -> String {
self.0.clone().unparse()
}

// Expose the children as a hidden (non-enumerable, don't generate type definition)
// property that's eagerly evaluated (getter) in the debugger context.
#[napi(
enumerable = false,
configurable = false,
writable = false,
getter,
js_name = "__children", // Needed; otherwise, the property name would shadow `children`.
skip_typescript
)]
pub fn __children(&self, env: Env) -> Vec<JsObject> {
Self::children(self, env)
}

// Similarly, expose the eagerly evaluated unparsed text in the debugger context.
#[napi(
enumerable = false,
configurable = false,
writable = false,
getter,
js_name = "__text",
skip_typescript
)]
pub fn __text(&self) -> String {
self.unparse()
}
}

#[napi(namespace = "cst")]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 980f664

Please sign in to comment.