Skip to content

Commit

Permalink
Merge pull request #1075 from neon-bindings/kv/export-self-types
Browse files Browse the repository at this point in the history
feat(neon-macros): Add `Channel` context for async functions and `this` support
  • Loading branch information
kjvalencik authored Oct 7, 2024
2 parents 205ed38 + 4c77978 commit 2c8cd15
Show file tree
Hide file tree
Showing 27 changed files with 961 additions and 87 deletions.
24 changes: 18 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Rust
target
rls*.log

# Created by `trybuild` ui tests
wip
**/*~

# Node
**/node_modules
**/.DS_Store
npm-debug.log

# JS build
**/build
**/dist
cli/lib
test/cli/lib

# Neon build
**/index.node
**/artifacts.json
cli/lib
**/dist
pkgs/create-neon/create-neon-test-project
pkgs/create-neon/create-neon-manual-test-project
test/cli/lib
npm-debug.log
rls*.log

# System
**/.DS_Store
114 changes: 114 additions & 0 deletions Cargo.lock

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

27 changes: 14 additions & 13 deletions crates/neon-macros/src/export/function/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) struct Meta {
pub(super) name: Option<syn::LitStr>,
pub(super) json: bool,
pub(super) context: bool,
pub(super) this: bool,
}

#[derive(Default)]
Expand All @@ -28,33 +29,29 @@ impl Meta {
Ok(())
}

fn force_context(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
match self.kind {
Kind::Normal | Kind::AsyncFn => {}
Kind::Async => return Err(meta.error(super::ASYNC_CX_ERROR)),
Kind::Task => return Err(meta.error(super::TASK_CX_ERROR)),
}

fn force_context(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
self.context = true;

Ok(())
}

fn force_this(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
self.this = true;

Ok(())
}

fn make_async(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
if matches!(self.kind, Kind::AsyncFn) {
return Err(meta.error(super::ASYNC_FN_ERROR));
return Err(meta.error("`async` attribute should not be used with an `async fn`"));
}

self.kind = Kind::Async;

Ok(())
}

fn make_task(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
if self.context {
return Err(meta.error(super::TASK_CX_ERROR));
}

fn make_task(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
self.kind = Kind::Task;

Ok(())
Expand Down Expand Up @@ -93,6 +90,10 @@ impl syn::parse::Parser for Parser {
return attr.force_context(meta);
}

if meta.path.is_ident("this") {
return attr.force_this(meta);
}

if meta.path.is_ident("async") {
return attr.make_async(meta);
}
Expand Down
Loading

0 comments on commit 2c8cd15

Please sign in to comment.