Skip to content

Commit

Permalink
refactor: improve judgement order
Browse files Browse the repository at this point in the history
  • Loading branch information
lomirus committed Oct 22, 2023
1 parent 86cb8c5 commit eef8919
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ fn try_stack_to_dom(token_stack: Vec<Token>) -> Vec<Node> {
match token {
Token::Start(tag, attrs) => {
let is_void_tag = VOID_TAGS.contains(&tag.as_str());
if start_tags_stack.is_empty() {
if is_void_tag {
if is_void_tag {
if start_tags_stack.is_empty() {
nodes.push(
Element {
name: tag.clone(),
Expand All @@ -215,15 +215,15 @@ fn try_stack_to_dom(token_stack: Vec<Token>) -> Vec<Node> {
.into_node(),
);
} else {
start_tag_index = i;
start_tags_stack.push(Token::Start(tag.clone(), attrs.clone()));
// You do not need to push the void tag to the stack
// like above, because it must be inside the the
// element of the first start tag, and this element
// will then be pushed to the stack recursively.
}
} else if is_void_tag {
// You do not need to push the void tag to the stack
// like above, because it must be inside the the
// element of the first start tag, and this element
// will then be pushed to the stack recursively.
} else {
if start_tags_stack.is_empty() {
start_tag_index = i;
}
start_tags_stack.push(Token::Start(tag.clone(), attrs.clone()));
}
}
Expand Down

0 comments on commit eef8919

Please sign in to comment.