swc-project/swc · error · Error

Expected percentage, function (math functions) or ident (wit

Error message

Expected percentage, function (math functions) or ident (with 'none' value) token

What it means

Fired while parsing a color function component (e.g. an alpha or channel slot): the value must be a percentage, a math function, or the ident 'none', but the current token is something else. An ident other than 'none' is specifically rejected here.

Source

Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1506

                            }
                            tok!("ident") => {
                                let ident: Box<Ident> = parser.parse()?;

                                if ident.value.eq_ignore_ascii_case("none") {
                                    Ok(Some(ComponentValue::Ident(ident)))
                                } else {
                                    Err(Error::new(
                                        ident.span,
                                        ErrorKind::Expected("'none' value of an ident token"),
                                    ))
                                }
                            }
                            Token::Function { value, .. } if is_math_function(value) => {
                                Ok(Some(ComponentValue::Function(parser.parse()?)))
                            }
                            _ => {
                                if !has_variable_before {
                                    Err(Error::new(
                                        parser.input.cur_span(),
                                        ErrorKind::Expected(
                                            "percentage, function (math functions) or ident (with \
                                             'none' value) token",
                                        ),
                                    ))
                                } else {
                                    Ok(None)
                                }
                            }
                        },
                        &mut has_variable,
                    )?;

                    if let Some(number_or_percentage_or_none) = number_or_percentage_or_none {
                        values.push(number_or_percentage_or_none);
                    }

View on GitHub (pinned to 5176682b65)

Solutions

  1. Use a percentage (e.g. '50%'), a math function (e.g. 'calc(...)'), or the keyword 'none'
  2. Remove unsupported idents in the channel/alpha position
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1506 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/c5e2e00e86c7389b. Report an issue: GitHub.