From 980f664f1e4ad89f11da31c606ec44643fb86556 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 25 Mar 2024 15:34:19 +0100 Subject: [PATCH 1/6] feat(napi): Expose `RuleNode#__{children,text}` debug view properties --- .../parser/runtime/src/napi_interface/cst.rs | 27 +++++++++++++++++++ .../src/generated/napi_interface/cst.rs | 27 +++++++++++++++++++ .../src/generated/napi_interface/cst.rs | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 8cc4c142a0..2bfd85ee60 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -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 { + 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")] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index e8dcae0dfc..82787c873d 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -74,6 +74,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 { + 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")] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index e8dcae0dfc..82787c873d 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -74,6 +74,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 { + 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")] From 9124880e59c1341fa6e3c26496297e54fc572eb9 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 25 Mar 2024 13:22:11 +0100 Subject: [PATCH 2/6] feat(napi): Add `{Rule,Token}Node::toJSON` --- .changeset/warm-maps-give.md | 5 +++++ Cargo.lock | 3 +++ crates/codegen/parser/runtime/Cargo.toml | 3 ++- .../parser/runtime/src/napi_interface/cst.rs | 16 ++++++++++++++++ .../src/generated/napi_interface/cst.rs | 16 ++++++++++++++++ .../cargo/slang_solidity_node_addon/Cargo.toml | 2 ++ .../outputs/npm/package/src/generated/index.d.ts | 12 ++++++++++++ .../src/generated/napi_interface/cst.rs | 16 ++++++++++++++++ .../cargo/slang_testlang_node_addon/Cargo.toml | 2 ++ .../outputs/npm/package/src/generated/index.d.ts | 12 ++++++++++++ 10 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 .changeset/warm-maps-give.md diff --git a/.changeset/warm-maps-give.md b/.changeset/warm-maps-give.md new file mode 100644 index 0000000000..808f1acf13 --- /dev/null +++ b/.changeset/warm-maps-give.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": minor +--- + +Add RuleNode/TokenNode::toJSON() in the TypeScript API diff --git a/Cargo.lock b/Cargo.lock index 0f6cf8b071..41c895de0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,6 +403,7 @@ dependencies = [ "napi-derive", "nom", "serde", + "serde_json", "strum", "strum_macros", ] @@ -1798,6 +1799,7 @@ dependencies = [ "nom", "semver", "serde", + "serde_json", "slang_solidity", "strum", "strum_macros", @@ -1832,6 +1834,7 @@ dependencies = [ "nom", "semver", "serde", + "serde_json", "slang_testlang", "strum", "strum_macros", diff --git a/crates/codegen/parser/runtime/Cargo.toml b/crates/codegen/parser/runtime/Cargo.toml index e7754f5aee..9fa7816a75 100644 --- a/crates/codegen/parser/runtime/Cargo.toml +++ b/crates/codegen/parser/runtime/Cargo.toml @@ -13,6 +13,7 @@ napi = { workspace = true, optional = true } napi-derive = { workspace = true, optional = true } nom = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } @@ -20,7 +21,7 @@ strum_macros = { workspace = true } # i.e `slang_solidity_node_addon`. [features] default = ["slang_napi_interfaces"] -slang_napi_interfaces = ["dep:napi", "dep:napi-derive"] +slang_napi_interfaces = ["dep:napi", "dep:napi-derive", "dep:serde_json"] [lints] workspace = true diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 2bfd85ee60..9e9e4cd1e4 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -68,6 +68,14 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() @@ -134,6 +142,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index 82787c873d..a0cb24cc0c 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -70,6 +70,14 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() @@ -136,6 +144,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml b/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml index 0d71cef363..bd39d17ecc 100644 --- a/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml +++ b/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml @@ -29,6 +29,7 @@ crate-type = ["cdylib"] default = ["slang_napi_interfaces"] slang_napi_interfaces = [ # This enables '#[napi]' attributes on the Rust types imported via [lib.path] above. + "dep:serde_json", ] [build-dependencies] @@ -43,6 +44,7 @@ napi-derive = { workspace = true } nom = { workspace = true } semver = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index 9d31b9bc2e..a77527cec4 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -746,6 +746,12 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; unparse(): string; } export class TokenNode { @@ -753,6 +759,12 @@ export namespace cst { get kind(): kinds.TokenKind; get textLength(): text_index.TextIndex; get text(): string; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index 82787c873d..a0cb24cc0c 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -70,6 +70,14 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() @@ -136,6 +144,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml b/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml index e325b846ba..9a7652aa0b 100644 --- a/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml +++ b/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml @@ -29,6 +29,7 @@ crate-type = ["cdylib"] default = ["slang_napi_interfaces"] slang_napi_interfaces = [ # This enables '#[napi]' attributes on the Rust types imported via [lib.path] above. + "dep:serde_json", ] [build-dependencies] @@ -43,6 +44,7 @@ napi-derive = { workspace = true } nom = { workspace = true } semver = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } diff --git a/crates/testlang/outputs/npm/package/src/generated/index.d.ts b/crates/testlang/outputs/npm/package/src/generated/index.d.ts index 4fa4bda6db..8cfa3126b5 100644 --- a/crates/testlang/outputs/npm/package/src/generated/index.d.ts +++ b/crates/testlang/outputs/npm/package/src/generated/index.d.ts @@ -87,6 +87,12 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; unparse(): string; } export class TokenNode { @@ -94,6 +100,12 @@ export namespace cst { get kind(): kinds.TokenKind; get textLength(): text_index.TextIndex; get text(): string; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; } } From f0552aacb0879f5e56c1f75d1490b9fe567ca52d Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 10 Apr 2024 10:50:39 +0100 Subject: [PATCH 3/6] Clean up some wording in the comment --- crates/codegen/parser/runtime/src/napi_interface/cst.rs | 4 +--- .../cargo/slang_solidity/src/generated/napi_interface/cst.rs | 4 +--- .../cargo/slang_testlang/src/generated/napi_interface/cst.rs | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 9e9e4cd1e4..9d6731e239 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -70,8 +70,6 @@ impl RuleNode { #[napi(catch_unwind, js_name = "toJSON")] /// Serialize the token node to JSON. - /// - /// This method is intended for debugging purposes and may not be stable. pub fn to_json(&self) -> String { serde_json::to_string(&self.0).unwrap() } @@ -82,7 +80,7 @@ impl RuleNode { } // Expose the children as a hidden (non-enumerable, don't generate type definition) - // property that's eagerly evaluated (getter) in the debugger context. + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. #[napi( enumerable = false, configurable = false, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index a0cb24cc0c..588ed064d2 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -72,8 +72,6 @@ impl RuleNode { #[napi(catch_unwind, js_name = "toJSON")] /// Serialize the token node to JSON. - /// - /// This method is intended for debugging purposes and may not be stable. pub fn to_json(&self) -> String { serde_json::to_string(&self.0).unwrap() } @@ -84,7 +82,7 @@ impl RuleNode { } // Expose the children as a hidden (non-enumerable, don't generate type definition) - // property that's eagerly evaluated (getter) in the debugger context. + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. #[napi( enumerable = false, configurable = false, diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index a0cb24cc0c..588ed064d2 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -72,8 +72,6 @@ impl RuleNode { #[napi(catch_unwind, js_name = "toJSON")] /// Serialize the token node to JSON. - /// - /// This method is intended for debugging purposes and may not be stable. pub fn to_json(&self) -> String { serde_json::to_string(&self.0).unwrap() } @@ -84,7 +82,7 @@ impl RuleNode { } // Expose the children as a hidden (non-enumerable, don't generate type definition) - // property that's eagerly evaluated (getter) in the debugger context. + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. #[napi( enumerable = false, configurable = false, From 0f211f71457324480aaf28d59615cc1c37149cf7 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 10 Apr 2024 10:57:53 +0100 Subject: [PATCH 4/6] fix: Adapt to the recent changes upstream --- crates/codegen/parser/runtime/src/napi_interface/cst.rs | 4 ++-- .../slang_solidity/src/generated/napi_interface/cst.rs | 4 ++-- .../solidity/outputs/npm/package/src/generated/index.d.ts | 6 +----- .../slang_testlang/src/generated/napi_interface/cst.rs | 4 ++-- .../testlang/outputs/npm/package/src/generated/index.d.ts | 6 +----- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 330be006de..4f4663867a 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -104,8 +104,8 @@ impl RuleNode { js_name = "__children", // Needed; otherwise, the property name would shadow `children`. skip_typescript )] - pub fn __children(&self, env: Env) -> Vec { - Self::children(self, env) + pub fn __children(&self) -> Vec> { + Self::children(self) } // Similarly, expose the eagerly evaluated unparsed text in the debugger context. diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index 62133a050a..77c3ddffb8 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -106,8 +106,8 @@ impl RuleNode { js_name = "__children", // Needed; otherwise, the property name would shadow `children`. skip_typescript )] - pub fn __children(&self, env: Env) -> Vec { - Self::children(self, env) + pub fn __children(&self) -> Vec> { + Self::children(self) } // Similarly, expose the eagerly evaluated unparsed text in the debugger context. diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index a77527cec4..b2a8a8806c 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -746,11 +746,7 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; - /** - * Serialize the token node to JSON. - * - * This method is intended for debugging purposes and may not be stable. - */ + /** Serialize the token node to JSON. */ toJSON(): string; unparse(): string; } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index 62133a050a..77c3ddffb8 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -106,8 +106,8 @@ impl RuleNode { js_name = "__children", // Needed; otherwise, the property name would shadow `children`. skip_typescript )] - pub fn __children(&self, env: Env) -> Vec { - Self::children(self, env) + pub fn __children(&self) -> Vec> { + Self::children(self) } // Similarly, expose the eagerly evaluated unparsed text in the debugger context. diff --git a/crates/testlang/outputs/npm/package/src/generated/index.d.ts b/crates/testlang/outputs/npm/package/src/generated/index.d.ts index 8cfa3126b5..68d5cfc94e 100644 --- a/crates/testlang/outputs/npm/package/src/generated/index.d.ts +++ b/crates/testlang/outputs/npm/package/src/generated/index.d.ts @@ -87,11 +87,7 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; - /** - * Serialize the token node to JSON. - * - * This method is intended for debugging purposes and may not be stable. - */ + /** Serialize the token node to JSON. */ toJSON(): string; unparse(): string; } From 0edb69f2dece765c556cb36e8eef39426747fd8e Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2024 10:06:28 +0100 Subject: [PATCH 5/6] fix: Add #[napi(catch_unwind)] attr to the debug properties It seems these are not properly propagated if the inner called function already uses the catch_unwind attribute, so we want to be extra careful here. --- crates/codegen/parser/runtime/src/napi_interface/cst.rs | 6 ++++-- .../slang_solidity/src/generated/napi_interface/cst.rs | 6 ++++-- .../slang_testlang/src/generated/napi_interface/cst.rs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 4f4663867a..1dc18b8993 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -102,7 +102,8 @@ impl RuleNode { writable = false, getter, js_name = "__children", // Needed; otherwise, the property name would shadow `children`. - skip_typescript + skip_typescript, + catch_unwind )] pub fn __children(&self) -> Vec> { Self::children(self) @@ -115,7 +116,8 @@ impl RuleNode { writable = false, getter, js_name = "__text", - skip_typescript + skip_typescript, + catch_unwind )] pub fn __text(&self) -> String { self.unparse() diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index 77c3ddffb8..3fed1dc268 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -104,7 +104,8 @@ impl RuleNode { writable = false, getter, js_name = "__children", // Needed; otherwise, the property name would shadow `children`. - skip_typescript + skip_typescript, + catch_unwind )] pub fn __children(&self) -> Vec> { Self::children(self) @@ -117,7 +118,8 @@ impl RuleNode { writable = false, getter, js_name = "__text", - skip_typescript + skip_typescript, + catch_unwind )] pub fn __text(&self) -> String { self.unparse() diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index 77c3ddffb8..3fed1dc268 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -104,7 +104,8 @@ impl RuleNode { writable = false, getter, js_name = "__children", // Needed; otherwise, the property name would shadow `children`. - skip_typescript + skip_typescript, + catch_unwind )] pub fn __children(&self) -> Vec> { Self::children(self) @@ -117,7 +118,8 @@ impl RuleNode { writable = false, getter, js_name = "__text", - skip_typescript + skip_typescript, + catch_unwind )] pub fn __text(&self) -> String { self.unparse() From eb63cda656926efc38cb0382884f3a24a992750e Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2024 10:16:48 +0100 Subject: [PATCH 6/6] Change TS cst.NodeType to be a string value of the enum variant --- .changeset/pink-bats-lie.md | 5 +++++ crates/codegen/parser/runtime/src/napi_interface/cst.rs | 2 +- .../cargo/slang_solidity/src/generated/napi_interface/cst.rs | 2 +- crates/solidity/outputs/npm/package/src/generated/index.d.ts | 4 ++-- .../cargo/slang_testlang/src/generated/napi_interface/cst.rs | 2 +- crates/testlang/outputs/npm/package/src/generated/index.d.ts | 4 ++-- 6 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/pink-bats-lie.md diff --git a/.changeset/pink-bats-lie.md b/.changeset/pink-bats-lie.md new file mode 100644 index 0000000000..50c4ac2a88 --- /dev/null +++ b/.changeset/pink-bats-lie.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": minor +--- + +Changed the cst.NodeType in TS to use more descriptive string values rather than 0/1 integers diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 1dc18b8993..b46da02abf 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -9,7 +9,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index 3fed1dc268..94b69f82d0 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -11,7 +11,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index b2a8a8806c..d432cdf573 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -737,8 +737,8 @@ export namespace ast_internal { } export namespace cst { export enum NodeType { - Rule = 0, - Token = 1, + Rule = "Rule", + Token = "Token", } export class RuleNode { get type(): NodeType.Rule; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index 3fed1dc268..94b69f82d0 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -11,7 +11,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, diff --git a/crates/testlang/outputs/npm/package/src/generated/index.d.ts b/crates/testlang/outputs/npm/package/src/generated/index.d.ts index 68d5cfc94e..954405ba8c 100644 --- a/crates/testlang/outputs/npm/package/src/generated/index.d.ts +++ b/crates/testlang/outputs/npm/package/src/generated/index.d.ts @@ -78,8 +78,8 @@ export namespace ast_internal { } export namespace cst { export enum NodeType { - Rule = 0, - Token = 1, + Rule = "Rule", + Token = "Token", } export class RuleNode { get type(): NodeType.Rule;