Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for double braces in leptos_fluent! macro #244

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion leptos-fluent-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ serde_json = { version = "1", optional = true }
serde_yaml = { version = "0.9", optional = true }
json5 = { version = "0.4", optional = true }
tracing = { version = "0.1", optional = true }
proc-macro-warning = "1"

[dev-dependencies]
trybuild = "1"
Expand Down
26 changes: 1 addition & 25 deletions leptos-fluent-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(feature = "nightly", feature(track_path))]
#![cfg_attr(feature = "nightly", feature(absolute_path))]

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (csr-complete, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (csr-minimal, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (csr-minimal, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (csr-complete, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (system-gtk, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-axum, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-axum, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-actix, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-actix, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-actix, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-actix, nightly, ubuntu-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-axum, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (ssr-hydrate-axum, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

Check warning on line 4 in leptos-fluent-macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build example (system-gtk, nightly, macos-latest)

the feature `absolute_path` has been stable since 1.79.0 and no longer requires an attribute to enable

//! Macros for the leptos-fluent crate.
//!
Expand Down Expand Up @@ -31,7 +31,6 @@
pub(crate) use languages::ParsedLanguage;
use loader::{I18nLoader, Identifier, LitBoolExpr};
use quote::quote;
use std::str::FromStr;

#[cfg(feature = "debug")]
#[inline(always)]
Expand Down Expand Up @@ -94,28 +93,6 @@
pub fn leptos_fluent(
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
// optional double braces (must be removed in v0.2)
let input_as_str = input.to_string();
let loader_input;
let double_braced_warning;
if input_as_str.starts_with('{') && input_as_str.ends_with('}') {
loader_input = proc_macro::TokenStream::from(
proc_macro2::TokenStream::from_str(
&input_as_str[1..input_as_str.len() - 1],
)
.unwrap(),
);
let warning = proc_macro_warning::FormattedWarning::new_deprecated(
"leptos_fluent",
"The double braced syntax `leptos_fluent! {{ ... }}` is deprecated and will be removed in v0.2. Use `leptos_fluent! { ... }` instead.",
proc_macro2::Span::call_site(),
);
double_braced_warning = quote!(#warning);
} else {
loader_input = input;
double_braced_warning = quote!();
}

let I18nLoader {
fluent_file_paths,
translations,
Expand Down Expand Up @@ -170,7 +147,7 @@
initial_language_from_data_file,
#[cfg(feature = "system")]
data_file_key,
} = syn::parse_macro_input!(loader_input as I18nLoader);
} = syn::parse_macro_input!(input as I18nLoader);

let n_languages = languages.len();
let languages_quote = build_languages_quote(&languages);
Expand Down Expand Up @@ -2351,7 +2328,6 @@
tracing::trace!("{}", debug_quote);

let quote = quote! {
#double_braced_warning
{
#debug_quote
#other_quotes
Expand Down
15 changes: 13 additions & 2 deletions leptos-fluent-macros/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,20 @@ impl Parse for I18nLoader {
concat!(
"Expected an expression with",
" 'key: value', '#[...] key: value', 'key,' or `#[...] key,` format.",
" Found:\n{}"
" Found:{}"
),
input,
&match input.to_string().len() {
0 => concat!(
" (empty).\n",
"If you're using double curly braces syntax",
" (`leptos_fluent! {{ ... }}` make sure to",
" use single curly braces syntax",
" (`leptos_fluent! { ... }`)."
).to_string(),
_ => format!(
"\n{}", &input.to_string()
),
},
),
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use fluent_templates::static_loader;
use leptos::*;
use leptos_fluent_macros::leptos_fluent;

static_loader! {
pub static TRANSLATIONS = {
locales: "../../../../examples/csr-minimal/locales",
fallback_language: "en",
};
}

#[component]
pub fn App() -> impl IntoView {
leptos_fluent! {{
translations: [TRANSLATIONS],
locales: "../../../../examples/csr-minimal/locales",
url_param: ,
}};

view! { <p>Foo</p> }
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: Expected an expression with 'key: value', '#[...] key: value', 'key,' or `#[...] key,` format. Found: (empty).
If you're using double curly braces syntax (`leptos_fluent! {{ ... }}` make sure to use single curly braces syntax (`leptos_fluent! { ... }`).
--> tests/ui/leptos_fluent/fail/double_curly_braces.rs:14:5
|
14 | / leptos_fluent! {{
15 | | translations: [TRANSLATIONS],
16 | | locales: "../../../../examples/csr-minimal/locales",
17 | | url_param: ,
18 | | }};
| |______^
|
= note: this error originates in the macro `leptos_fluent` (in Nightly builds, run with -Z macro-backtrace for more info)
Loading