swc-project/swc · error · Error
Unexpected token
Error message
Unexpected token
What it means
While parsing a style block's rule list, a QualifiedRule failed to parse; recovery pushes this error into self.errors and skips tokens to continue. 'Unexpected token' marks input at that position that the rule grammar cannot accept.
Source
Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:441
let state = self.input.state();
let qualified_rule = self
.with_ctx(Ctx {
block_contents_grammar: BlockContentsGrammar::StyleBlock,
mixed_with_declarations: true,
..self.ctx
})
.parse_as::<Box<QualifiedRule>>();
match qualified_rule {
Ok(i) => rules.push(StyleBlock::QualifiedRule(i)),
Err(err) => {
self.errors.push(err);
self.input.reset(&state);
let span = self.input.cur_span();
self.errors
.push(Error::new(span, ErrorKind::Unexpected("token")));
// For recovery mode
let mut list_of_component_values = ListOfComponentValues {
span: Default::default(),
children: Vec::new(),
};
while !is_one_of!(self, ";", EOF) {
let component_value = self.parse_as::<ComponentValue>()?;
list_of_component_values.children.push(component_value);
}
list_of_component_values.span = span!(self, span.lo);
declarations.push(StyleBlock::ListOfComponentValues(Box::new(
list_of_component_values,
)));View on GitHub (pinned to 5176682b65)
Solutions
- Inspect the collected errors to locate the offending token
- Fix the selector/rule syntax in the style block
- Use the recovery results to skip and keep parsing the rest of the sheet
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:441 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/949d4ff414678b4d.
Report an issue: GitHub.