Skip to content

Commit

Permalink
fix: fix Svelte 5 snippet block (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkylerLipthay authored Nov 5, 2024
1 parent 609b755 commit d25b42b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions markup_fmt/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,13 +2174,32 @@ impl<'s> Parser<'s> {
.and_then(|_| self.chars.next_if(|(_, c)| c.is_ascii_whitespace()))
.is_none()
{
return Err(self.emit_error(SyntaxErrorKind::ExpectSvelteIfBlock));
return Err(self.emit_error(SyntaxErrorKind::ExpectSvelteSnippetBlock));
};

let expr = self.parse_svelte_or_astro_expr()?;
let children = self.parse_svelte_block_children()?;

Ok(SvelteSnippetBlock { expr, children })
if self
.chars
.next_if(|(_, c)| *c == '{')
.map(|_| self.skip_ws())
.and_then(|_| self.chars.next_if(|(_, c)| *c == '/'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 's'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'n'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'i'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'e'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 't'))
.map(|_| self.skip_ws())
.and_then(|_| self.chars.next_if(|(_, c)| *c == '}'))
.is_some()
{
Ok(SvelteSnippetBlock { expr, children })
} else {
Err(self.emit_error(SyntaxErrorKind::ExpectSvelteBlockEnd))
}
}

fn parse_tag_name(&mut self) -> PResult<&'s str> {
Expand Down
1 change: 1 addition & 0 deletions markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ impl<'s> DocGen<'s> for SvelteSnippetBlock<'s> {
ctx,
state,
))
.append(Doc::text("{/snippet}"))
}
}

Expand Down

0 comments on commit d25b42b

Please sign in to comment.