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>"#));
|
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]
|
#[test]
|
||||||
fn colons_in_names() {
|
fn colons_in_names() {
|
||||||
let s = html!(pon-pon:controls-alpha a on:click="yay()" "Yay!").into_string();
|
let s = html!(pon-pon:controls-alpha a on:click="yay()" "Yay!").into_string();
|
||||||
|
|
|
@ -408,16 +408,28 @@ impl Parser {
|
||||||
self.commit(attempt);
|
self.commit(attempt);
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
// Toggle the attribute based on a boolean expression
|
// 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();
|
self.advance();
|
||||||
render.push(TokenTree {
|
render.push(TokenTree {
|
||||||
kind: TokenNode::Term(Term::intern("if")),
|
kind: TokenNode::Term(Term::intern("if")),
|
||||||
span: question_span,
|
span: question_span,
|
||||||
});
|
});
|
||||||
render.push(TokenTree {
|
// If the condition contains an opening brace `{`,
|
||||||
kind: TokenNode::Group(Delimiter::None, cond),
|
// wrap it in parentheses to avoid parse errors
|
||||||
span: delim_span,
|
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 body = {
|
||||||
let mut render = render.fork();
|
let mut render = render.fork();
|
||||||
render.attribute_empty(&name);
|
render.attribute_empty(&name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue