Skip to content

Commit

Permalink
fix: fix Angular control after @for (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
electricentity authored Nov 13, 2024
1 parent 8d38b5d commit feca4a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
38 changes: 18 additions & 20 deletions markup_fmt/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,29 @@ impl<'s> Parser<'s> {
let children = self.parse_angular_control_flow_children()?;

let mut empty = None;
'empty: {
let mut chars = self.chars.clone();
'peek: loop {
match chars.next() {
Some((_, c)) if c.is_ascii_whitespace() => continue 'peek,
Some((_, '@')) => {
let mut chars = self.chars.clone();
'peek: loop {
match chars.next() {
Some((_, c)) if c.is_ascii_whitespace() => continue 'peek,
Some((_, '@')) => {
if chars
.next_if(|(_, c)| *c == 'e')
.and_then(|_| chars.next_if(|(_, c)| *c == 'm'))
.and_then(|_| chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| chars.next_if(|(_, c)| *c == 't'))
.and_then(|_| chars.next_if(|(_, c)| *c == 'y'))
.is_some()
{
self.chars = chars;
self.skip_ws();
empty = Some(self.parse_angular_control_flow_children()?);
break 'peek;
} else {
break 'peek;
}
_ => break 'empty,
}
_ => break 'peek,
}
if self
.chars
.next_if(|(_, c)| *c == 'e')
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'm'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 't'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'y'))
.is_none()
{
return Err(self.emit_error(SyntaxErrorKind::ExpectKeyword("empty")));
}
self.skip_ws();
empty = Some(self.parse_angular_control_flow_children()?);
}

Ok(AngularFor {
Expand Down
9 changes: 9 additions & 0 deletions markup_fmt/tests/fmt/angular/control-flow/for.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@
@for ( item of items; track item){
}
</div>

<div>
@for ( item of items; track item){
<li><strong>{{ item.name }}</strong></li>
}
@for ( item of items; track item){
<li><strong>{{item.name}}</strong></li>
}
</div>
9 changes: 9 additions & 0 deletions markup_fmt/tests/fmt/angular/control-flow/for.component.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ source: markup_fmt/tests/fmt.rs
<div>
@for (item of items; track item) { }
</div>

<div>
@for (item of items; track item) {
<li><strong>{{ item.name }}</strong></li>
}
@for (item of items; track item) {
<li><strong>{{ item.name }}</strong></li>
}
</div>

0 comments on commit feca4a0

Please sign in to comment.