swc-project/swc · error · Error
Invalid An+B microsyntax
Error message
Invalid An+B microsyntax
What it means
Fired while parsing the An+B microsyntax (e.g. in :nth-child()): a dimension token representing the `n` part was read, but its unit did not start with the character 'n'/'N', so it is not an <n-dimension>. This is a validation guard on the dimension's unit; input at fault is something like `:nth-child(3x)` instead of `:nth-child(3n)`.
Source
Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1308
unreachable!();
}
};
let n_char = dimension.2.chars().next();
if n_char != Some('n') && n_char != Some('N') {
return Err(Error::new(
span,
ErrorKind::Expected("'n' character in Ident"),
));
}
a = Some(dimension.0 as i32);
a_raw = Some(dimension.1);
n_value = (*dimension.2).to_string();
}
_ => {
return Err(Error::new(span, ErrorKind::InvalidAnPlusBMicrosyntax));
}
};
self.input.skip_ws();
let mut b = None;
let mut b_raw = None;
let dash_after_n = n_value.chars().nth(1);
match cur!(self) {
// '+'? n <signed-integer>
// -n <signed-integer>
// <n-dimension> <signed-integer>
tok!("number") if dash_after_n.is_none() => {
let number = match bump!(self) {
Token::Number { value, raw, .. } => (value, raw),
_ => {View on GitHub (pinned to 5176682b65)
Solutions
- Follow `n` with `+`/`-` and a signless integer, or nothing at all
- Report the collected error
- Fix the selector
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1308 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/3ccf893636349235.
Report an issue: GitHub.