{"record":{"id":"2d4a1a9c469045e4","repo":"dianping/cat","slug":"namespace-not-allowed-here","errorCode":null,"errorMessage":"@namespace not allowed here.","messagePattern":"@namespace not allowed here\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-css.js","lineNumber":2069,"sourceCode":"                                break;\n                            case Tokens.S:\n                                this._readWhitespace();\n                                break;\n                            default:\n                                if(!this._ruleset()){\n                                    switch(tt){\n                                        case Tokens.CHARSET_SYM:\n                                            token = tokenStream.LT(1);\n                                            this._charset(false);\n                                            throw new SyntaxError(\"@charset not allowed here.\", token.startLine, token.startCol);\n                                        case Tokens.IMPORT_SYM:\n                                            token = tokenStream.LT(1);\n                                            this._import(false);\n                                            throw new SyntaxError(\"@import not allowed here.\", token.startLine, token.startCol);\n                                        case Tokens.NAMESPACE_SYM:\n                                            token = tokenStream.LT(1);\n                                            this._namespace(false);\n                                            throw new SyntaxError(\"@namespace not allowed here.\", token.startLine, token.startCol);\n                                        default:\n                                            tokenStream.get();  //get the last token\n                                            this._unexpectedToken(tokenStream.token());\n                                    }\n\n                                }\n                        }\n                    } catch(ex) {\n                        if (ex instanceof SyntaxError && !this.options.strict){\n                            this.fire({\n                                type:       \"error\",\n                                error:      ex,\n                                message:    ex.message,\n                                line:       ex.line,\n                                col:        ex.col\n                            });\n                        } else {\n                            throw ex;","sourceCodeStart":2051,"sourceCodeEnd":2087,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-css.js#L2051-L2087","documentation":"Thrown when `@namespace` appears after rules that must follow it: `@namespace` declarations must come after `@charset`/`@import` but before any style rules (and before any element-type selectors that would rely on the namespace). The parser consumes the `@namespace` via `_namespace(false)` and throws `SyntaxError('@namespace not allowed here.')` at its token position; in non-strict mode it degrades to an 'error' event.","triggerScenarios":"`@namespace svg url(...);` placed after a ruleset, `@media`, or `@font-face`; XML-targeted stylesheets where a rule was added above the namespace; generated SVG CSS that appends namespaces at the end.","commonSituations":"Editing SVG-styled CSS and appending the namespace late; merge conflicts resolved by putting the namespace block below rules; tooling that injects a prefix block before a hand-written namespace.","solutions":["Move `@namespace` statements directly after `@charset`/`@import` and before all style rules.","If you do not actually need XML namespaces (plain HTML CSS), delete the `@namespace` line.","If required, restructure so namespaced selectors live in their own file parsed/imported in correct order.","Lint for at-rule ordering (@charset → @import → @namespace → rules) in CI."],"exampleFix":"/* before */\nsvg|rect { fill: red; }\n@namespace svg url(http://www.w3.org/2000/svg); /* not allowed here */\n\n/* after */\n@namespace svg url(http://www.w3.org/2000/svg);\nsvg|rect { fill: red; }","handlingStrategy":"validation","validationCode":"function namespaceBeforeRules(css) {\n  var m = css.match(/@namespace[^;]+;/);\n  if (!m) return true;\n  var rulesBefore = css.slice(0, m.index).replace(/@charset[^;]*;|@import[^;]+;/g, '').trim();\n  return rulesBefore === '';\n}","typeGuard":null,"tryCatchPattern":"try {\n  parser.parse(css);\n} catch (ex) {\n  if (/@namespace not allowed/.test(ex.message)) { moveToTop('@namespace'); return; }\n  throw ex;\n}","preventionTips":["Keep the header order @charset → @import → @namespace → rules in every file and in concatenated output.","Delete @namespace from HTML-only stylesheets where it serves no purpose.","Add an at-rule-order lint rule so merges cannot silently break ordering."],"tags":["css","parser","at-rule","namespace","syntax-error"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}