swc-project/swc · error · Error

EofWithUnclosedElements

EofWithUnclosedElements

Error message

End of file seen and there were open elements

What it means

HTML parse error emitted when an EOF token is processed while the stack of open elements is not empty, i.e. the document ended with unclosed elements. The tree builder still pops/generates implied end tags so parsing recovers and yields a complete document tree.

Source

Thrown at crates/swc_html_parser/src/parser/mod.rs:2003

                                parser.errors.push(Error::new(
                                    token_and_info.span,
                                    ErrorKind::NonSpaceCharacterInNoscriptInHead,
                                ));
                            }
                            Token::StartTag { tag_name, .. } => {
                                parser.errors.push(Error::new(
                                    token_and_info.span,
                                    ErrorKind::BadStartTagInNoscriptInHead(tag_name.clone()),
                                ));
                            }
                            Token::EndTag { tag_name, .. } => {
                                parser.errors.push(Error::new(
                                    token_and_info.span,
                                    ErrorKind::StrayEndTag(tag_name.clone()),
                                ));
                            }
                            Token::Eof => {
                                parser.errors.push(Error::new(
                                    token_and_info.span,
                                    ErrorKind::EofWithUnclosedElements,
                                ));
                            }
                            _ => {
                                unreachable!()
                            }
                        }

                        parser.open_elements_stack.pop();
                        parser.insertion_mode = InsertionMode::InHead;
                        parser.process_token(token_and_info, None)?;

                        Ok(())
                    };

                // When the user agent is to apply the rules for the "in head noscript"
                // insertion mode, the user agent must handle the token as follows:

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close all open elements before end of file (balance every start tag)
  2. Verify no truncation of the input document
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:2003 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/7a69a9dddbde6ef6. Report an issue: GitHub.