Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the use of Rust keywords for element names (#1772)
* time for more hygiene * update corresponding tests * while I'm at it * now let's fix the actual issue * fix the publish examples CI while I'm at it * resolve clippy warnings
- Loading branch information
Showing
20 changed files
with
166 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
use yew::prelude::*; | ||
#![no_implicit_prelude] | ||
|
||
fn compile_pass() { | ||
html! { <>{ "Hi" }</> }; | ||
html! { <>{ format!("Hello") }</> }; | ||
html! { <>{ String::from("Hello") }</> }; | ||
fn main() { | ||
::yew::html! { <>{ "Hi" }</> }; | ||
::yew::html! { <>{ ::std::format!("Hello") }</> }; | ||
::yew::html! { <>{ ::std::string::ToString::to_string("Hello") }</> }; | ||
|
||
let msg = "Hello"; | ||
html! { <div>{ msg }</div> }; | ||
::yew::html! { <div>{ msg }</div> }; | ||
|
||
let subview = html! { "subview!" }; | ||
html! { <div>{ subview }</div> }; | ||
let subview = ::yew::html! { "subview!" }; | ||
::yew::html! { <div>{ subview }</div> }; | ||
|
||
let subview = || html! { "subview!" }; | ||
html! { <div>{ subview() }</div> }; | ||
let subview = || ::yew::html! { "subview!" }; | ||
::yew::html! { <div>{ subview() }</div> }; | ||
|
||
html! { | ||
::yew::html! { | ||
<ul> | ||
{ for (0..3).map(|num| { html! { <span>{num}</span> }}) } | ||
{ for ::std::iter::Iterator::map(0..3, |num| { ::yew::html! { <span>{ num }</span> }}) } | ||
</ul> | ||
}; | ||
|
||
let item = |num| html! { <li>{format!("item {}!", num)}</li> }; | ||
html! { | ||
let item = |num| ::yew::html! { <li>{ ::std::format!("item {}!", num) }</li> }; | ||
::yew::html! { | ||
<ul> | ||
{ for (0..3).map(item) } | ||
{ for ::std::iter::Iterator::map(0..3, item) } | ||
</ul> | ||
}; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/yew-macro/tests/html_macro/component-unimplemented-fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![recursion_limit = "128"] | ||
|
||
use yew::prelude::*; | ||
|
||
struct Unimplemented; | ||
|
10 changes: 5 additions & 5 deletions
10
packages/yew-macro/tests/html_macro/component-unimplemented-fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
error[E0599]: no function or associated item named `new` found for struct `yew::virtual_dom::vcomp::VChild<Unimplemented>` in the current scope | ||
--> $DIR/component-unimplemented-fail.rs:8:14 | ||
--> $DIR/component-unimplemented-fail.rs:6:14 | ||
| | ||
5 | struct Unimplemented; | ||
3 | struct Unimplemented; | ||
| --------------------- doesn't satisfy `Unimplemented: yew::html::component::Component` | ||
... | ||
8 | html! { <Unimplemented /> }; | ||
6 | html! { <Unimplemented /> }; | ||
| ^^^^^^^^^^^^^ function or associated item not found in `yew::virtual_dom::vcomp::VChild<Unimplemented>` | ||
| | ||
= note: the method `new` exists but the following trait bounds were not satisfied: | ||
`Unimplemented: yew::html::component::Component` | ||
|
||
error[E0277]: the trait bound `Unimplemented: yew::html::component::Component` is not satisfied | ||
--> $DIR/component-unimplemented-fail.rs:8:14 | ||
--> $DIR/component-unimplemented-fail.rs:6:14 | ||
| | ||
8 | html! { <Unimplemented /> }; | ||
6 | html! { <Unimplemented /> }; | ||
| ^^^^^^^^^^^^^ the trait `yew::html::component::Component` is not implemented for `Unimplemented` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![no_implicit_prelude] | ||
|
||
fn main() { | ||
let dyn_tag = || ::std::string::ToString::to_string("test"); | ||
let mut next_extra_tag = { | ||
let mut it = ::std::iter::IntoIterator::into_iter(::std::vec!["a", "b"]); | ||
move || ::std::option::Option::unwrap(::std::iter::Iterator::next(&mut it)) | ||
}; | ||
|
||
::yew::html! { | ||
<@{ dyn_tag() }> | ||
<@{ next_extra_tag() } class="extra-a"/> | ||
<@{ next_extra_tag() } class="extra-b"/> | ||
</@> | ||
}; | ||
|
||
::yew::html! { | ||
<@{ | ||
let tag = dyn_tag(); | ||
if tag == "test" { | ||
"div" | ||
} else { | ||
"a" | ||
} | ||
}/> | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,41 @@ | ||
#![recursion_limit = "768"] | ||
use yew::prelude::*; | ||
#![no_implicit_prelude] | ||
|
||
fn compile_pass() { | ||
let onclick = Callback::from(|_: MouseEvent| ()); | ||
let parent_ref = NodeRef::default(); | ||
fn main() { | ||
let onclick: ::yew::Callback<_> = ::std::convert::From::from(|_: ::yew::MouseEvent| ()); | ||
let parent_ref: ::yew::NodeRef = ::std::default::Default::default(); | ||
|
||
let dyn_tag = || String::from("test"); | ||
let mut extra_tags_iter = vec!["a", "b"].into_iter(); | ||
|
||
html! { | ||
::yew::html! { | ||
<div> | ||
<div data-key="abc"></div> | ||
<div ref=parent_ref class="parent"> | ||
<span class="child" value="anything"></span> | ||
<label for="first-name">{"First Name"}</label> | ||
<label for="first-name">{ "First Name" }</label> | ||
<input type="text" id="first-name" value="placeholder" /> | ||
<input type="checkbox" checked=true /> | ||
<textarea value="write a story" /> | ||
<select name="status"> | ||
<option selected=true disabled=false value="">{"Selected"}</option> | ||
<option selected=false disabled=true value="">{"Unselected"}</option> | ||
<option selected=true disabled=false value="">{ "Selected" }</option> | ||
<option selected=false disabled=true value="">{ "Unselected" }</option> | ||
</select> | ||
</div> | ||
<svg width="149" height="147" viewBox="0 0 149 147" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M60.5776 13.8268L51.8673 42.6431L77.7475 37.331L60.5776 13.8268Z" fill="#DEB819"/> | ||
<path d="M108.361 94.9937L138.708 90.686L115.342 69.8642" stroke="black" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/> | ||
<g filter="url(#filter0_d)"> | ||
<circle cx="75.3326" cy="73.4918" r="55" fill="#FDD630"/> | ||
<circle cx="75.3326" cy="73.4918" r="52.5" stroke="black" stroke-width="5"/> | ||
</g> | ||
<circle cx="71" cy="99" r="5" fill="white" fill-opacity="0.75" stroke="black" stroke-width="3"/> | ||
<defs> | ||
<filter id="filter0_d" x="16.3326" y="18.4918" width="118" height="118" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"> | ||
<feGaussianBlur stdDeviation="2"/> | ||
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/> | ||
</filter> | ||
</defs> | ||
</svg> | ||
<img class=classes!("avatar", "hidden") src="http://pic.com" /> | ||
<img class=::yew::classes!("avatar", "hidden") src="http://pic.com" /> | ||
<img class="avatar hidden" /> | ||
<button onclick=&onclick onclick=onclick /> | ||
<a href="http://google.com" /> | ||
<custom-tag-a> | ||
<custom-tag-b /> | ||
</custom-tag-a> | ||
<@{dyn_tag()}> | ||
<@{extra_tags_iter.next().unwrap()} class="extra-a"/> | ||
<@{extra_tags_iter.next().unwrap()} class="extra-b"/> | ||
</@> | ||
|
||
<@{ | ||
let tag = dyn_tag(); | ||
if tag == "test" { | ||
"div" | ||
} else { | ||
"a" | ||
} | ||
}/> | ||
|
||
<a href?=Some("http://google.com") media?=Option::<&str>::None /> | ||
<track kind?=Some("subtitles") src?=Option::<&str>::None /> | ||
<track kind?=Some(5) mixed="works" /> | ||
<input value?=Some("value") onblur?=Some(Callback::from(|_| ())) /> | ||
<a href?=::std::option::Option::Some("http://google.com") media?=::std::option::Option::<&str>::None /> | ||
<track kind?=::std::option::Option::Some("subtitles") src?=::std::option::Option::<&str>::None /> | ||
<track kind?=::std::option::Option::Some(5) mixed="works" /> | ||
<input value?=::std::option::Option::Some("value") onblur?=::std::option::Option::Some(<::yew::Callback<_> as ::std::convert::From<_>>::from(|_| ())) /> | ||
</div> | ||
}; | ||
|
||
let children = vec![ | ||
html! { <span>{ "Hello" }</span> }, | ||
html! { <span>{ "World" }</span> }, | ||
let children = ::std::vec![ | ||
::yew::html! { <span>{ "Hello" }</span> }, | ||
::yew::html! { <span>{ "World" }</span> }, | ||
]; | ||
html! { <div>{children}</div> }; | ||
::yew::html! { <div>{ children }</div> }; | ||
} | ||
|
||
fn main() {} |
2 changes: 0 additions & 2 deletions
2
packages/yew-macro/tests/html_macro/generic-component-fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![recursion_limit = "256"] | ||
|
||
use std::marker::PhantomData; | ||
use yew::prelude::*; | ||
|
||
|
Oops, something went wrong.