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

yew-macro: silence non-normalised element name warnings for SVG elements #3769

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/yew-macro/src/derive_props/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub struct PropFieldCheck<'a> {
check_arg: GenericParam,
}

impl<'a> PropFieldCheck<'a> {
impl PropFieldCheck<'_> {
pub fn to_fake_prop_decl(&self) -> proc_macro2::TokenStream {
let Self { this, .. } = self;
if !this.is_required() {
Expand Down
43 changes: 41 additions & 2 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@ use crate::props::{ElementProps, Prop, PropDirective};
use crate::stringify::{Stringify, Value};
use crate::{is_ide_completion, non_capitalized_ascii, Peek, PeekValue};

fn is_normalised_element_name(name: &str) -> bool {
match name {
"animateMotion"
| "animateTransform"
| "clipPath"
| "feBlend"
| "feColorMatrix"
| "feComponentTransfer"
| "feComposite"
| "feConvolveMatrix"
| "feDiffuseLighting"
| "feDisplacementMap"
| "feDistantLight"
| "feDropShadow"
| "feFlood"
| "feFuncA"
| "feFuncB"
| "feFuncG"
| "feFuncR"
| "feGaussianBlur"
| "feImage"
| "feMerge"
| "feMergeNode"
| "feMorphology"
| "feOffset"
| "fePointLight"
| "feSpecularLighting"
| "feSpotLight"
| "feTile"
| "feTurbulence"
| "foreignObject"
| "glyphRef"
| "linearGradient"
| "radialGradient"
| "textPath" => true,
_ => !name.chars().any(|c| c.is_ascii_uppercase()),
}
}

pub struct HtmlElement {
pub name: TagName,
pub props: ElementProps,
Expand Down Expand Up @@ -310,9 +349,9 @@ impl ToTokens for HtmlElement {
TagName::Lit(dashedname) => {
let name_span = dashedname.span();
let name = dashedname.to_ascii_lowercase_string();
if name != dashedname.to_string() {
if !is_normalised_element_name(&dashedname.to_string()) {
emit_warning!(
dashedname.span(),
name_span.clone(),
format!(
"The tag '{dashedname}' is not matching its normalized form '{name}'. If you want \
to keep this form, change this to a dynamic tag `@{{\"{dashedname}\"}}`."
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/tests/html_macro_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dynamic_tags_catch_non_ascii() {
#[test]
fn html_nested_macro_on_html_element() {
let _node = html_nested! {
<div/>
<feBlend/>
};
let _node = html_nested! {
<input/>
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/blist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct NodeWriter<'s> {
slot: DomSlot,
}

impl<'s> NodeWriter<'s> {
impl NodeWriter<'_> {
/// Write a new node that has no ancestor
fn add(self, node: VNode) -> (Self, BNode) {
test_log!("adding: {:?}", node);
Expand Down
1 change: 0 additions & 1 deletion packages/yew/src/dom_bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) struct Bundle(BNode);

impl Bundle {
/// Creates a new bundle.

pub const fn new() -> Self {
Self(BNode::List(BList::new()))
}
Expand Down
Loading