Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into napi-glibc
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Apr 3, 2024
2 parents addb72e + a001a46 commit 235af0c
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 90 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ariadne = { version = "0.2.0" }
cargo-emit = { version = "0.2.1" }
cargo-xwin = { version = "0.14.2" }
cargo-zigbuild = { version = "0.18.3" }
clap = { version = "4.5.3", features = ["derive", "wrap_help"] }
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
clap_complete = { version = "4.5.1" }
console = { version = "0.15.8" }
derive-new = { version = "0.6.0" }
Expand All @@ -90,9 +90,9 @@ indicatif = { version = "0.17.8", features = ["in_memory"] }
Inflector = { version = "0.11.4" }
itertools = { version = "0.10.5" }
markdown = { version = "0.3.0" }
napi = { version = "2.16.0", features = ["compat-mode", "napi8", "serde-json"] }
napi = { version = "2.16.1", features = ["compat-mode", "napi8", "serde-json"] }
napi-build = { version = "2.1.2" }
napi-derive = { version = "2.16.0" }
napi-derive = { version = "2.16.1" }
nom = { version = "7.1.3" }
num-format = { version = "0.4.4" }
once_cell = { version = "1.19.0" }
Expand All @@ -103,12 +103,12 @@ regex = { version = "1.10.4" }
reqwest = { version = "0.11.27", features = ["blocking"] }
semver = { version = "1.0.22", features = ["serde"] }
serde = { version = "1.0.197", features = ["derive", "rc"] }
serde_json = { version = "1.0.114", features = ["preserve_order"] }
serde_json = { version = "1.0.115", features = ["preserve_order"] }
similar-asserts = { version = "1.5.0" }
stack-graphs = { version = "0.12.0" }
strum = { version = "0.25.0" }
strum_macros = { version = "0.25.3" }
syn = { version = "2.0.55", features = [
syn = { version = "2.0.57", features = [
"fold",
"full",
"extra-traits",
Expand All @@ -118,8 +118,8 @@ syn = { version = "2.0.55", features = [
tera = { version = "1.19.1" }
tempfile = { version = "3.10.1" }
thiserror = { version = "1.0.58" }
trybuild = { version = "1.0.90" }
toml = { version = "0.8.2" }
trybuild = { version = "1.0.91" }
toml = { version = "0.8.12" }
url = { version = "2.3.1" }

[workspace.lints.rust]
Expand Down
31 changes: 16 additions & 15 deletions crates/codegen/parser/runtime/src/napi_interface/cst.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::rc::Rc;

use napi::bindgen_prelude::{Env, ToNapiValue};
use napi::{JsObject, NapiValue};
use napi::bindgen_prelude::Env;
use napi::JsObject;
use napi_derive::napi;

use crate::napi_interface::cursor::Cursor;
Expand Down Expand Up @@ -54,7 +54,7 @@ impl RuleNode {
self.0
.children
.iter()
.map(|child| child.to_js(&env))
.map(|child| child.to_js(env))
.collect()
}

Expand Down Expand Up @@ -118,29 +118,30 @@ impl TokenNode {
}
}

pub trait ToJS {
fn to_js(&self, env: &Env) -> JsObject;
pub(crate) trait ToJS {
fn to_js(&self, env: Env) -> JsObject;
}

impl ToJS for Rc<RustRuleNode> {
fn to_js(&self, env: &Env) -> JsObject {
let obj =
unsafe { <RuleNode as ToNapiValue>::to_napi_value(env.raw(), RuleNode(self.clone())) };
unsafe { JsObject::from_raw_unchecked(env.raw(), obj.unwrap()) }
fn to_js(&self, env: Env) -> JsObject {
RuleNode(self.clone())
.into_instance(env)
.expect("Class constructor to be defined by #[napi]")
.as_object(env)
}
}

impl ToJS for Rc<RustTokenNode> {
fn to_js(&self, env: &Env) -> JsObject {
let obj = unsafe {
<TokenNode as ToNapiValue>::to_napi_value(env.raw(), TokenNode(self.clone()))
};
unsafe { JsObject::from_raw_unchecked(env.raw(), obj.unwrap()) }
fn to_js(&self, env: Env) -> JsObject {
TokenNode(self.clone())
.into_instance(env)
.expect("Class constructor to be defined by #[napi]")
.as_object(env)
}
}

impl ToJS for RustNode {
fn to_js(&self, env: &Env) -> JsObject {
fn to_js(&self, env: Env) -> JsObject {
match self {
RustNode::Rule(rust_rule_node) => rust_rule_node.to_js(env),
RustNode::Token(rust_token_node) => rust_token_node.to_js(env),
Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/parser/runtime/src/napi_interface/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Cursor {

#[napi(ts_return_type = "cst.Node", catch_unwind)]
pub fn node(&self, env: Env) -> JsObject {
self.0.node().to_js(&env)
self.0.node().to_js(env)
}

#[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)]
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Cursor {
pub fn ancestors(&self, env: Env) -> Vec<JsObject> {
self.0
.ancestors()
.map(|rust_rule_node| rust_rule_node.to_js(&env))
.map(|rust_rule_node| rust_rule_node.to_js(env))
.collect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl From<RustParseOutput> for ParseOutput {
impl ParseOutput {
#[napi(ts_return_type = "cst.Node", catch_unwind)]
pub fn tree(&self, env: Env) -> napi::JsObject {
self.0.tree().to_js(&env)
self.0.tree().to_js(env)
}

#[napi(ts_return_type = "Array<parse_error.ParseError>", catch_unwind)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Selector {
}
node if filter(node) => {
self.index += 1;
return Ok(Some(node.to_js(&self.env)));
return Ok(Some(node.to_js(self.env)));
}
_ => {
break;
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.

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

Loading

0 comments on commit 235af0c

Please sign in to comment.