swc-project/swc · error · Error

Unexpected '!' in declaration value

Error message

Unexpected '!' in declaration value

What it means

Fired while consuming a declaration value: a '!' delimiter was found where it cannot form a valid '!important' flag (not followed by whitespace plus the 'important' ident). Per the CSS grammar the '!' is a preserved token that makes the declaration value invalid, so the parser reports it instead of silently accepting the declaration.

Source

Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:672

        let mut important_ident = None;

        loop {
            if is!(self, EOF) {
                break;
            }

            let component_value = self.parse_as::<ComponentValue>()?;

            match &component_value {
                // Optimization for step 6
                ComponentValue::PreservedToken(token_and_span)
                    if matches!(token_and_span.token, Token::Delim { value: '!', .. })
                        && (is!(self, " ") || is_case_insensitive_ident!(self, "important")) =>
                {
                    if let Some(span) = &exclamation_point_span {
                        is_valid_to_canonicalize = false;

                        self.errors.push(Error::new(
                            *span,
                            ErrorKind::Unexpected("'!' in declaration value"),
                        ));

                        important_ident = None;
                        last_whitespaces = (last_whitespaces.2, 0, 0);
                    }

                    exclamation_point_span = Some(token_and_span.span);
                }
                ComponentValue::PreservedToken(token_and_span)
                    if matches!(token_and_span.token, Token::WhiteSpace { .. }) =>
                {
                    match (&exclamation_point_span, &important_ident) {
                        (Some(_), Some(_)) => {
                            last_whitespaces.2 += 1;
                        }
                        (Some(_), None) => {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Write the flag as '! important' or '!important' followed by the ident 'important'
  2. Remove the stray '!' if importance was not intended
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:672 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/071ed8388823e4e1. Report an issue: GitHub.