Skip to content

Commit

Permalink
feat: allow slice! macro to index tuples (#2598)
Browse files Browse the repository at this point in the history
* Allow slice! macro to index tuples

* Undo changes to component tests

---------

Co-authored-by: Greg Johnston <greg.johnston@gmail.com>
  • Loading branch information
SleeplessOne1917 and gbj committed May 29, 2024
1 parent 2f4fd87 commit 21a6551
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions leptos_macro/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use syn::{

struct SliceMacroInput {
root: syn::Ident,
path: Punctuated<syn::Ident, Token![.]>,
path: Punctuated<syn::Member, Token![.]>,
}

impl Parse for SliceMacroInput {
fn parse(input: ParseStream) -> syn::Result<Self> {
let root: syn::Ident = input.parse()?;
input.parse::<Token![.]>()?;
// do not accept trailing punctuation
let path: Punctuated<syn::Ident, Token![.]> =
let path: Punctuated<syn::Member, Token![.]> =
Punctuated::parse_separated_nonempty(input)?;

if path.is_empty() {
Expand Down
7 changes: 5 additions & 2 deletions leptos_macro/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ pub struct OuterState {
#[derive(Clone, PartialEq, Default)]
pub struct InnerState {
inner_count: i32,
inner_name: String,
inner_tuple: InnerTuple,
}

#[derive(Clone, PartialEq, Default)]
pub struct InnerTuple(String);

#[test]
fn green() {
let _ = create_runtime();
Expand All @@ -22,7 +25,7 @@ fn green() {
let (_, _) = slice!(outer_signal.count);

let (_, _) = slice!(outer_signal.inner.inner_count);
let (_, _) = slice!(outer_signal.inner.inner_name);
let (_, _) = slice!(outer_signal.inner.inner_tuple.0);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions leptos_macro/tests/slice/red.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ error: expected `.`
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:25:18
|
25 | let (_, _) = slice!(outer_signal.);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:27:18
|
27 | let (_, _) = slice!(outer_signal.inner.);
Expand Down

0 comments on commit 21a6551

Please sign in to comment.