Skip to content

Commit ee7c59e

Browse files
fix
1 parent ca4877d commit ee7c59e

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

crates/djls-template-ast/src/parser.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -330,35 +330,22 @@ impl Parser {
330330
}
331331

332332
fn synchronize(&mut self) -> Result<(), ParserError> {
333-
let mut depth = 0;
334-
let mut found_django_token = false;
335-
333+
let sync_types = [
334+
TokenType::DjangoBlock(String::new()),
335+
TokenType::DjangoVariable(String::new()),
336+
TokenType::Comment(String::new(), String::from("{#"), Some(String::from("#}"))),
337+
TokenType::Eof,
338+
];
336339
while !self.is_at_end() {
337-
if let TokenType::DjangoBlock(content) = &self.tokens[self.current].token_type() {
338-
let tag = content.split_whitespace().next().unwrap_or("");
339-
if let Some(spec) = TagSpec::load_builtin_specs().unwrap_or_default().get(tag) {
340-
if spec.closing.as_deref() == Some(tag) {
341-
depth -= 1;
342-
if depth <= 0 {
343-
found_django_token = true;
344-
break;
345-
}
346-
} else {
347-
depth += 1;
348-
}
340+
let current = self.peek()?;
341+
for sync_type in &sync_types {
342+
if current.token_type() == sync_type {
343+
return Ok(());
349344
}
350345
}
351-
self.current += 1;
346+
self.consume()?;
352347
}
353-
354-
if !found_django_token {
355-
return Err(ParserError::Ast(
356-
AstError::StreamError("AtEnd".into()),
357-
None,
358-
));
359-
}
360-
361-
Ok(())
348+
Err(ParserError::Ast(AstError::StreamError("AtEnd".into()), None))
362349
}
363350
}
364351

0 commit comments

Comments
 (0)