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

Unterminated block comment

Error message

Unterminated block comment

What it means

The CSS lexer reached EOF while scanning a /* ... */ block comment, so the comment never closes. read_comments records the comment text gathered so far and pushes this recoverable error into the parser's error list rather than aborting the parse.

Source

Thrown at crates/swc_css_parser/src/lexer/mod.rs:553

                                    // Safety: last_pos is a valid position
                                    self.input.slice(cmt_start, last_pos)
                                };

                                self.pending_leading_comments.push(Comment {
                                    kind: CommentKind::Block,
                                    span: (self.start_pos, last_pos).into(),
                                    text: self.atoms.atom(text),
                                });
                            }

                            break;
                        }
                        None => {
                            let span = Span::new(self.start_pos, self.input.last_pos());

                            self.errors
                                .borrow_mut()
                                .push(Error::new(span, ErrorKind::UnterminatedBlockComment));

                            return;
                        }
                        _ => {}
                    }
                }
            }
        } else if self.config.allow_wrong_line_comments
            && self.next() == Some(b'/')
            && self.next_next() == Some(b'/')
        {
            while self.next() == Some(b'/') && self.next_next() == Some(b'/') {
                self.consume(1); // '/'
                self.consume(1); // '/'

                let start_of_content = self.input.last_pos();

                loop {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close the block comment with */ in the CSS source
  2. Inspect the parser's collected errors after parsing to report this to users
  3. Demote to a warning if lenient parsing is acceptable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/lexer/mod.rs:553 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/b04ae2b55dfaa511. Report an issue: GitHub.