Skip to content

Commit

Permalink
reduce the number of compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile committed Jan 24, 2022
1 parent 362aee9 commit 3a0b4d5
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/yew-macro/src/html_tree/html_dashed_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Parse for HtmlDashedName {
let name = input.call(Ident::parse_any)?;
let mut extended = Vec::new();
while input.peek(Token![-]) {
extended.push((input.parse::<Token![-]>()?, input.parse::<Ident>()?));
extended.push((input.parse::<Token![-]>()?, Ident::parse_any(input)?));
}

Ok(HtmlDashedName { name, extended })
Expand Down
5 changes: 4 additions & 1 deletion packages/yew-macro/src/html_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ impl HtmlTree {
} else if input.peek(Token![::]) {
Some(HtmlType::Component)
} else if input.peek(Ident::peek_any) {
if input.peek(Token![=]) || (input.peek(Token![?]) && input.peek2(Token![=])) {
let ident = Ident::parse_any(&input).ok()?;
let ident_str = ident.to_string();

if input.peek(Token![=]) || (input.peek(Token![?]) && input.peek2(Token![=])) || ident_str == "key" {
Some(HtmlType::List)
} else {
Some(HtmlType::Component)
Expand Down
6 changes: 3 additions & 3 deletions packages/yew-macro/src/typed_vdom/generate_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ impl ToTokens for GenerateElement {
}

impl #props_ident {
fn into_data(self) -> ElementData {
fn into_data(self) -> ::yew::virtual_dom::typings::ElementData {

ElementData {
::yew::virtual_dom::typings::ElementData {
node_ref: ::std::option::Option::unwrap_or_default(self.node_ref),
attributes: {
let mut attrs = ::std::collections::HashMap::new();
Expand All @@ -99,7 +99,7 @@ impl ToTokens for GenerateElement {
}

fn view(&self, ctx: &::yew::html::Context<Self>) -> ::yew::html::Html {
let element: ElementData = ctx.props().clone().into_data();
let element = ctx.props().clone().into_data();
// todo use __new_{other, textarea, input} depending upon the element
::yew::virtual_dom::VTag::__new_other(
::std::stringify!(#element_name).into(),
Expand Down
2 changes: 0 additions & 2 deletions packages/yew/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ pub mod prelude {
pub use crate::suspense::Suspense;

pub use crate::functional::*;

pub use crate::virtual_dom::typings::*;
}

pub use self::prelude::*;
Expand Down
6 changes: 3 additions & 3 deletions packages/yew/src/server_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ where

/// Renders Yew Application.
pub async fn render(self) -> String {
let mut s = String::new();
let mut buf = String::new();

self.render_to_string(&mut s).await;
self.render_to_string(&mut buf).await;

s
buf
}

/// Renders Yew Application to a String.
Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/virtual_dom/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ mod test {
#[test]
fn all_key_conversions() {
html! {
<key="string literal">
<div key="string literal">
<img key={"String".to_owned()} />
<p key={Rc::<str>::from("rc")}></p>
<key='a'>
<div key='a'>
<p key=11_usize></p>
<p key=12_u8></p>
<p key=13_u16></p>
Expand All @@ -96,8 +96,8 @@ mod test {
<p key=23_i16></p>
<p key=24_i32></p>
<p key=25_i128></p>
</>
</>
</div>
</div>
};
}
}
12 changes: 6 additions & 6 deletions packages/yew/src/virtual_dom/typings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,11 @@ generate_element! {
/// A [Component](crate::html::Component) is generated using this data for every element.
#[derive(Debug)]
pub struct ElementData {
node_ref: NodeRef,
attributes: HashMap<&'static str, AttrValue>,
listeners: Vec<Option<Rc<dyn Listener>>>,
key: Option<Key>,
children: Vec<VNode>,
pub node_ref: NodeRef,
pub attributes: HashMap<&'static str, AttrValue>,
pub listeners: Vec<Option<Rc<dyn Listener>>>,
pub key: Option<Key>,
pub children: Vec<VNode>,
}

#[cfg(all(test, feature = "wasm_test"))]
Expand Down Expand Up @@ -1098,7 +1098,7 @@ mod tests {
#[function_component]
fn Comp(props: &Props) -> Html {
html! {
<Btn class="ccc" name="yes" on_click={props.on_click.clone()}>{ TEXT }</Btn>
<Btn class="ccc" name="yes" onclick={props.on_click.clone()}>{ TEXT }</Btn>
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/yew/src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ mod layout_tests_keys {
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);

// the tests use an <e> element
// this call can serve as a very simple custom element declaration
yew_macro::generate_element! {
e;
props: {}
}

struct Comp {}

#[derive(Properties, Clone, PartialEq)]
Expand Down
30 changes: 15 additions & 15 deletions packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,15 +753,15 @@ mod tests {
#[test]
fn it_compares_attributes_static() {
let a = html! {
<div a="test"></div>
<div class="test"></div>
};

let b = html! {
<div a="test"></div>
<div class="test"></div>
};

let c = html! {
<div a="fail"></div>
<div class="fail"></div>
};

assert_eq!(a, b);
Expand All @@ -771,15 +771,15 @@ mod tests {
#[test]
fn it_compares_attributes_dynamic() {
let a = html! {
<div a={"test".to_owned()}></div>
<div class={"test".to_owned()}></div>
};

let b = html! {
<div a={"test".to_owned()}></div>
<div class={"test".to_owned()}></div>
};

let c = html! {
<div a={"fail".to_owned()}></div>
<div class={"fail".to_owned()}></div>
};

assert_eq!(a, b);
Expand Down Expand Up @@ -887,8 +887,8 @@ mod tests {
let namespace = Some(namespace);
let svg_el = document.create_element_ns(namespace, "svg").unwrap();

let mut g_node = html! { <g class="segment"></g> };
let path_node = html! { <path></path> };
let mut g_node = html! { <@{"g"} class="segment"></@> };
let path_node = html! { <@{"path"}></@> };
let mut svg_node = html! { <svg>{path_node}</svg> };

let svg_tag = assert_vtag_mut(&mut svg_node);
Expand Down Expand Up @@ -945,22 +945,22 @@ mod tests {
#[test]
fn it_compares_checked() {
let a = html! {
<input type="checkbox" checked=false />
<input type="checkbox" />
};

let b = html! {
<input type="checkbox" checked=false />
<input type="checkbox" />
};

let c = html! {
<input type="checkbox" checked=true />
<input type="checkbox" checked="true" />
};

assert_eq!(a, b);
assert_ne!(a, c);
}

#[test]
/*#[test] aria/data attributes will be part of props composition/"rest" prop
fn it_allows_aria_attributes() {
let a = html! {
<p aria-controls="it-works">
Expand Down Expand Up @@ -994,7 +994,7 @@ mod tests {
} else {
panic!("vtag expected");
}
}
}*/

#[test]
fn it_does_not_set_missing_class_name() {
Expand Down Expand Up @@ -1230,13 +1230,13 @@ mod tests {
let test_ref = NodeRef::default();
let mut before = html! {
<>
<div ref={&test_ref} id="before" />
<div ref={test_ref.clone()} id="before" />
</>
};
let mut after = html! {
<>
<h6 />
<div ref={&test_ref} id="after" />
<div ref={test_ref.clone()} id="after" />
</>
};
// The point of this diff is to first render the "after" div and then detach the "before" div,
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/tests/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async fn suspense_not_suspended_at_start() {

Ok(html! {
<div class="content-area">
<textarea value={value.to_string()} oninput={on_text_input}></textarea>
<textarea oninput={on_text_input}>{value.to_string()}</textarea>
<div class="action-area">
<button class="take-a-break" onclick={on_take_a_break}>{"Take a break!"}</button>
</div>
Expand Down

1 comment on commit 3a0b4d5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: 3a0b4d5 Previous: 31afa9d Ratio
yew-struct-keyed 01_run1k 230.7495 269.2845 0.86
yew-struct-keyed 02_replace1k 236.24 255.614 0.92
yew-struct-keyed 03_update10th1k_x16 350.0865 444.468 0.79
yew-struct-keyed 04_select1k 77.288 86.78399999999999 0.89
yew-struct-keyed 05_swap1k 92.489 101.038 0.92
yew-struct-keyed 06_remove-one-1k 29.0335 34.5415 0.84
yew-struct-keyed 07_create10k 2550.3050000000003 2831.4849999999997 0.90
yew-struct-keyed 08_create1k-after1k_x2 510.6595 586.5625 0.87
yew-struct-keyed 09_clear1k_x8 245.741 260.2425 0.94
yew-struct-keyed 21_ready-memory 0.9634513854980468 0.9634513854980468 1
yew-struct-keyed 22_run-memory 1.4998092651367188 1.5034751892089844 1.00
yew-struct-keyed 23_update5-memory 1.503814697265625 1.5043830871582031 1.00
yew-struct-keyed 24_run5-memory 1.510845184326172 1.5091552734375 1.00
yew-struct-keyed 25_run-clear-memory 1.1287879943847656 1.1287879943847656 1
yew-struct-keyed 31_startup-ci 1732.652 1733.726 1.00
yew-struct-keyed 32_startup-bt 32.377999999999986 39.80199999999999 0.81
yew-struct-keyed 34_startup-totalbytes 365.9482421875 365.9482421875 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.