{"record":{"id":"aeac738c483f0d6f","repo":"swc-project/swc","slug":"expected","errorCode":null,"errorMessage":"Expected {}","messagePattern":"Expected (.+?)","errorType":"validation","errorClass":"swc_css_parser::error::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/macros.rs","lineNumber":161,"sourceCode":"    };\n}\n\nmacro_rules! eat {\n    ($parser:expr, $tt:tt) => {\n        if is!($parser, $tt) {\n            bump!($parser);\n            true\n        } else {\n            false\n        }\n    };\n}\n\nmacro_rules! expect {\n    ($parser:expr, $tt:tt) => {\n        if !eat!($parser, $tt) {\n            let span = $parser.input.cur_span();\n            return Err(crate::error::Error::new(\n                span,\n                crate::error::ErrorKind::ExpectedButGot(stringify!($tt)),\n            ));\n        }\n    };\n}\n","sourceCodeStart":143,"sourceCodeEnd":168,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/macros.rs#L143-L168","documentation":"The expect!() macro is the parser's generic token assertion: it tries to eat a specific token (')', '}', ident, string, ...) and, when the current token is not it, returns ExpectedButGot with the expected token name. The '{}' in the message is filled with the token that was expected at that call site, so this one error kind covers every 'expected X here' site in the CSS parser — the expected-token text and span tell you which grammar position failed.","triggerScenarios":"Missing ')' closing a media feature: '@media (width: 10px {', missing '}' closing a block, missing '(' after an at-rule keyword, or a missing ident/string where a value is required — any site using expect!(self, ...) whose token does not match.","commonSituations":"Hand-edited stylesheets with a dropped delimiter; minified CSS where a brace was stripped; templating that conditionally emits an opening construct but not its closer. Because the message names the expected token, developers often misread it as a library bug when it is input syntax.","solutions":["Read the expected-token text in the message and the error span, then insert that token at the span location","Balance delimiters around the reported position (the missing token is usually a ')' or '}' belonging to an earlier line)","Run the input through a formatter/linter (prettier, stylelint) to localize the imbalance","If generating CSS, emit open/close pairs from one code path"],"exampleFix":"/* before */\n@media (min-width: 100px { .a { color: red; } }\n/* after */\n@media (min-width: 100px) { .a { color: red; } }","handlingStrategy":"try-catch","validationCode":"// Cheap delimiter-balance check catches the common missing ')'/'}' cases\nif (!isBalanced(css)) throw new SyntaxError('unbalanced braces or parens');","typeGuard":null,"tryCatchPattern":"// JS: extract the expected token from the message for actionable diagnostics\ntry { parse(css, opts); } catch (e) {\n  const m = e.message.match(/Expected (\\S+), but got/);\n  if (m) report(`insert '${m[1]}' near offset ${e.span?.start}`); else throw e;\n}","preventionTips":["Emit opening and closing tokens from the same code path in generators","Format/lint generated CSS (prettier/stylelint) before feeding it to swc","Remember the message names the MISSING token — search upward from the span for the unclosed construct"],"tags":["css","parser","syntax","expected-token"],"backgroundTag":"css-expected-token-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}