Skip to content

Commit

Permalink
add RuleNode.unparse() to the TypeScript API (#731)
Browse files Browse the repository at this point in the history
used in #732
  • Loading branch information
OmarTawfik committed Jan 10, 2024
1 parent 0727cf8 commit 3deaea2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-buttons-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

add `RuleNode.unparse()` to the TypeScript API
5 changes: 5 additions & 0 deletions crates/codegen/parser/runtime/src/napi/napi_cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl RuleNode {
.cursor_with_offset((&text_offset).into())
.into()
}

#[napi(catch_unwind)]
pub fn unparse(&self) -> String {
self.0.clone().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.

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

10 changes: 10 additions & 0 deletions crates/solidity/outputs/npm/tests/src/tests/cst-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ test("calculate unicode characters text length", () => {
utf8: 24,
});
});

test("can unparse rule nodes", () => {
const source = `contract Foo {}`;
const language = new Language("0.8.1");

const parseTree = language.parse(RuleKind.SourceUnit, source).tree();
expectRule(parseTree, RuleKind.SourceUnit);

expect(parseTree.unparse()).toEqual(source);
});

0 comments on commit 3deaea2

Please sign in to comment.