Handle conditions which contain braces
This commit is contained in:
parent
d3586a28f3
commit
c57d41e1a6
2 changed files with 24 additions and 5 deletions
|
@ -93,6 +93,13 @@ fn toggle_empty_attributes() {
|
|||
r#"<input>"#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggle_empty_attributes_braces() {
|
||||
let s = html!(input checked?[Maud { rocks: true }.rocks] /).into_string();
|
||||
let foo = 42;
|
||||
assert_eq!(s, r#"<input checked>"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colons_in_names() {
|
||||
let s = html!(pon-pon:controls-alpha a on:click="yay()" "Yay!").into_string();
|
||||
|
|
|
@ -408,16 +408,28 @@ impl Parser {
|
|||
self.commit(attempt);
|
||||
match self.peek() {
|
||||
// Toggle the attribute based on a boolean expression
|
||||
Some(TokenTree { kind: TokenNode::Group(Delimiter::Bracket, cond), span: delim_span }) => {
|
||||
Some(TokenTree {
|
||||
kind: TokenNode::Group(Delimiter::Bracket, cond),
|
||||
span: delim_span,
|
||||
}) => {
|
||||
self.advance();
|
||||
render.push(TokenTree {
|
||||
kind: TokenNode::Term(Term::intern("if")),
|
||||
span: question_span,
|
||||
});
|
||||
render.push(TokenTree {
|
||||
kind: TokenNode::Group(Delimiter::None, cond),
|
||||
span: delim_span,
|
||||
});
|
||||
// If the condition contains an opening brace `{`,
|
||||
// wrap it in parentheses to avoid parse errors
|
||||
if cond.clone().into_iter().any(|token| match token.kind {
|
||||
TokenNode::Group(Delimiter::Brace, _) => true,
|
||||
_ => false,
|
||||
}) {
|
||||
render.push(TokenTree {
|
||||
kind: TokenNode::Group(Delimiter::Parenthesis, cond),
|
||||
span: delim_span,
|
||||
});
|
||||
} else {
|
||||
render.push(cond);
|
||||
}
|
||||
let body = {
|
||||
let mut render = render.fork();
|
||||
render.attribute_empty(&name);
|
||||
|
|
Loading…
Add table
Reference in a new issue