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

Duplicate attribute

Error message

Duplicate attribute

What it means

Tokenizer error from finish_attribute_token_name: an attribute name was completed that duplicates an attribute already present on the current start/end tag token, which HTML forbids (duplicate attribute names on one element).

Source

Thrown at crates/swc_html_parser/src/lexer/mod.rs:842

                }
                | Token::EndTag {
                    ref mut attributes, ..
                },
            ) = self.current_token
            {
                if let Some(last) = attributes.last_mut() {
                    let b = self.buf.clone();
                    let mut buf = b.borrow_mut();
                    let b = self.sub_buf.clone();
                    let mut sub_buf = b.borrow_mut();

                    let name: Atom = buf.clone().into();
                    let raw_name = Atom::new(sub_buf.clone());
                    let span = Span::new(attribute_start_position, self.cur_pos);

                    if self.attributes_validator.contains(&name) {
                        self.errors
                            .push(Error::new(span, ErrorKind::DuplicateAttribute));
                    }

                    self.attributes_validator.insert(name.clone());

                    last.name = name;
                    last.raw_name = Some(raw_name);

                    buf.clear();
                    sub_buf.clear();

                    last.span = span;
                }
            }
        }
    }

    fn append_to_attribute_token_value(&mut self, c: Option<char>, raw_c: Option<char>) {
        let b = self.buf.clone();

View on GitHub (pinned to 5176682b65)

Solutions

  1. Remove or rename the duplicated attribute so names are unique on the tag
  2. If duplicate attrs are acceptable for your pipeline, deduplicate downstream and downgrade this error
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_html_parser/src/lexer/mod.rs:842 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/6aada230836bfe75. Report an issue: GitHub.