From 790662a6d70597dc3db270ef70f5f25218f53ea7 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Tue, 9 Apr 2024 10:48:27 +0100 Subject: [PATCH] refactor: Rename into_js_either_node helper function --- .../codegen/parser/runtime/src/napi_interface/cst.rs | 12 +++++++++--- .../parser/runtime/src/napi_interface/cursor.rs | 2 +- .../runtime/src/napi_interface/parse_output.rs | 2 +- .../napi_interface/templates/ast_selectors.rs.jinja2 | 2 +- .../src/generated/napi_interface/ast_selectors.rs | 2 +- .../src/generated/napi_interface/cst.rs | 12 +++++++++--- .../src/generated/napi_interface/cursor.rs | 2 +- .../src/generated/napi_interface/parse_output.rs | 2 +- .../src/generated/napi_interface/ast_selectors.rs | 2 +- .../src/generated/napi_interface/cst.rs | 12 +++++++++--- .../src/generated/napi_interface/cursor.rs | 2 +- .../src/generated/napi_interface/parse_output.rs | 2 +- 12 files changed, 36 insertions(+), 18 deletions(-) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index ca662ed502..18e309851d 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -16,8 +16,8 @@ pub enum NodeType { } impl RustNode { - /// Converts a Rust node into a choice of NAPI-exposed wrapper structs. - pub fn into_either(self) -> Either { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { match self { RustNode::Rule(rule) => Either::A(RuleNode(rule)), RustNode::Token(token) => Either::B(TokenNode(token)), @@ -25,6 +25,12 @@ impl RustNode { } } +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -63,7 +69,7 @@ impl RuleNode { self.0 .children .iter() - .map(|child| child.node.clone().into_either()) + .map(|child| child.node.clone().into()) .collect() } diff --git a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs index e24537696f..f3c91feaa4 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs @@ -53,7 +53,7 @@ impl Cursor { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn node(&self) -> Either { - self.0.node().into_either() + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] diff --git a/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs b/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs index 5c88841047..aa2cb6c7a6 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs @@ -17,7 +17,7 @@ impl From for ParseOutput { impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn tree(&self) -> Either { - self.0.tree().into_either() + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)] diff --git a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 index d65b456203..679afca8b0 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 @@ -284,7 +284,7 @@ impl Selector { } labeled if filter(labeled) => { self.index += 1; - return Ok(Some(labeled.node.clone().into_either())); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs index a9fd00cf13..efa50fbd10 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs @@ -3177,7 +3177,7 @@ impl Selector { } labeled if filter(labeled) => { self.index += 1; - return Ok(Some(labeled.node.clone().into_either())); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; 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 89fb62e1e5..20f0a13157 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 @@ -18,8 +18,8 @@ pub enum NodeType { } impl RustNode { - /// Converts a Rust node into a choice of NAPI-exposed wrapper structs. - pub fn into_either(self) -> Either { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { match self { RustNode::Rule(rule) => Either::A(RuleNode(rule)), RustNode::Token(token) => Either::B(TokenNode(token)), @@ -27,6 +27,12 @@ impl RustNode { } } +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -65,7 +71,7 @@ impl RuleNode { self.0 .children .iter() - .map(|child| child.node.clone().into_either()) + .map(|child| child.node.clone().into()) .collect() } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs index 01b8ed2e62..623cdfb7c6 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs @@ -55,7 +55,7 @@ impl Cursor { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn node(&self) -> Either { - self.0.node().into_either() + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs index 76b7b8896b..994cf7de26 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs @@ -19,7 +19,7 @@ impl From for ParseOutput { impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn tree(&self) -> Either { - self.0.tree().into_either() + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs index 7296083e70..508abba30d 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs @@ -310,7 +310,7 @@ impl Selector { } labeled if filter(labeled) => { self.index += 1; - return Ok(Some(labeled.node.clone().into_either())); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; 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 89fb62e1e5..20f0a13157 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 @@ -18,8 +18,8 @@ pub enum NodeType { } impl RustNode { - /// Converts a Rust node into a choice of NAPI-exposed wrapper structs. - pub fn into_either(self) -> Either { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { match self { RustNode::Rule(rule) => Either::A(RuleNode(rule)), RustNode::Token(token) => Either::B(TokenNode(token)), @@ -27,6 +27,12 @@ impl RustNode { } } +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -65,7 +71,7 @@ impl RuleNode { self.0 .children .iter() - .map(|child| child.node.clone().into_either()) + .map(|child| child.node.clone().into()) .collect() } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs index 01b8ed2e62..623cdfb7c6 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs @@ -55,7 +55,7 @@ impl Cursor { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn node(&self) -> Either { - self.0.node().into_either() + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs index 76b7b8896b..994cf7de26 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs @@ -19,7 +19,7 @@ impl From for ParseOutput { impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] pub fn tree(&self) -> Either { - self.0.tree().into_either() + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)]