swc-project/swc · error · swc_html_parser::error::Error

Non void html element start tag with trailing solidus

Error message

Non void html element start tag with trailing solidus

What it means

HTML parse error raised in the parser loop after tree construction: a StartTag token carried the self-closing flag (trailing '/') but the element is not a void element, so per spec the flag is not acknowledged and the solidus is reported as an error. Parsing continues with normal start-tag handling.

Source

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

            // Re-emit errors from tokenizer
            for error in self.input.take_errors() {
                let (span, kind) = *error.into_inner();

                self.errors.push(Error::new(span, kind));
            }

            self.tree_construction_dispatcher(&mut token_and_info)?;

            // When a start tag token is emitted with its self-closing flag set,
            // if the flag is not acknowledged when it is processed by the tree
            // construction stage, that is a parse error.
            if let Token::StartTag {
                is_self_closing, ..
            } = &token_and_info.token
            {
                if *is_self_closing && !token_and_info.acknowledged {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::NonVoidHtmlElementStartTagWithTrailingSolidus,
                    ));
                }
            }
        }

        Ok(())
    }

    fn tree_construction_dispatcher(&mut self, token_and_info: &mut TokenAndInfo) -> PResult<()> {
        // As each token is emitted from the tokenizer, the user agent must follow the
        // appropriate steps from the following list, known as the tree construction
        // dispatcher:
        //
        // If the stack of open elements is empty
        //
        // If the adjusted current node is an element in the HTML namespace

View on GitHub (pinned to 5176682b65)

Solutions

  1. Remove the trailing '/' from non-void element start tags (e.g. <div/> -> <div>)
  2. Use proper <element>...</element> form for non-void elements
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:572 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/1f65ea8302ac2977. Report an issue: GitHub.