-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix handling of boolean attributes #840
Changes from 2 commits
6f1fbd3
d770710
f78a128
e4b11a4
d6e4963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,10 @@ pub struct TagAttributes { | |
pub attributes: Vec<TagAttribute>, | ||
pub listeners: Vec<TagAttribute>, | ||
pub classes: Option<ClassesForm>, | ||
pub booleans: Vec<TagAttribute>, | ||
pub value: Option<Expr>, | ||
pub kind: Option<Expr>, | ||
pub checked: Option<Expr>, | ||
pub disabled: Option<Expr>, | ||
pub selected: Option<Expr>, | ||
pub node_ref: Option<Expr>, | ||
pub href: Option<Expr>, | ||
|
@@ -24,6 +24,53 @@ pub enum ClassesForm { | |
Single(Expr), | ||
} | ||
|
||
lazy_static! { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment saying what the source of this list is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this list is not totally correct, see this comment: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7#gistcomment-2717606 |
||
static ref BOOLEAN_SET: HashSet<&'static str> = { | ||
HashSet::from_iter( | ||
vec![ | ||
"async", | ||
"autocomplete", | ||
"autofocus", | ||
"autoplay", | ||
"border", | ||
"challenge", | ||
"checked", | ||
"compact", | ||
"contenteditable", | ||
"controls", | ||
"default", | ||
"defer", | ||
"disabled", | ||
"formNoValidate", | ||
"frameborder", | ||
"hidden", | ||
"indeterminate", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nohref", | ||
"noresize", | ||
"noshade", | ||
"novalidate", | ||
"nowrap", | ||
"open", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"scoped", | ||
"scrolling", | ||
"seamless", | ||
"selected", | ||
"sortable", | ||
"spellcheck", | ||
"translate", | ||
] | ||
.into_iter(), | ||
) | ||
}; | ||
} | ||
|
||
lazy_static! { | ||
static ref LISTENER_SET: HashSet<&'static str> = { | ||
HashSet::from_iter( | ||
|
@@ -92,6 +139,20 @@ impl TagAttributes { | |
drained | ||
} | ||
|
||
fn drain_boolean(attrs: &mut Vec<TagAttribute>) -> Vec<TagAttribute> { | ||
let mut i = 0; | ||
let mut drained = Vec::new(); | ||
while i < attrs.len() { | ||
let name_str = attrs[i].label.to_string(); | ||
if BOOLEAN_SET.contains(&name_str.as_str()) { | ||
drained.push(attrs.remove(i)); | ||
} else { | ||
i += 1; | ||
} | ||
} | ||
drained | ||
} | ||
|
||
fn remove_attr(attrs: &mut Vec<TagAttribute>, name: &str) -> Option<Expr> { | ||
let mut i = 0; | ||
while i < attrs.len() { | ||
|
@@ -142,13 +203,13 @@ impl Parse for TagAttributes { | |
} | ||
i += 1; | ||
} | ||
let booleans = TagAttributes::drain_boolean(&mut attributes); | ||
|
||
let classes = | ||
TagAttributes::remove_attr(&mut attributes, "class").map(TagAttributes::map_classes); | ||
let value = TagAttributes::remove_attr(&mut attributes, "value"); | ||
let kind = TagAttributes::remove_attr(&mut attributes, "type"); | ||
let checked = TagAttributes::remove_attr(&mut attributes, "checked"); | ||
let disabled = TagAttributes::remove_attr(&mut attributes, "disabled"); | ||
let selected = TagAttributes::remove_attr(&mut attributes, "selected"); | ||
let node_ref = TagAttributes::remove_attr(&mut attributes, "ref"); | ||
let href = TagAttributes::remove_attr(&mut attributes, "href"); | ||
|
@@ -157,10 +218,10 @@ impl Parse for TagAttributes { | |
attributes, | ||
classes, | ||
listeners, | ||
booleans, | ||
value, | ||
kind, | ||
checked, | ||
disabled, | ||
selected, | ||
node_ref, | ||
href, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need special handling for
selected
with your change. Can you please remove the special handling and ensure thatselected
works properly as a boolean attribute?