{"record":{"id":"f1c4673b4f0f19b4","repo":"swc-project/swc","slug":"class-name-cannot-be-referenced-in-computed-p","errorCode":null,"errorMessage":"Class \"${name}\" cannot be referenced in computed property keys.","messagePattern":"Class \"(.+?)\" cannot be referenced in computed property keys\\.","errorType":"exception","errorClass":"ReferenceError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_class_name_tdz_error.rs","lineNumber":11,"sourceCode":"// This file is generated by `cargo codegen helpers`. DO NOT MODIFY.\n\nuse super::{HelperDef, HelperName};\n\npub const DEF: HelperDef = HelperDef {\n    name: HelperName::class_name_tdz_error,\n    local: \"_class_name_tdz_error\",\n    import_path: \"@swc/helpers/_/_class_name_tdz_error\",\n    #[cfg(feature = \"inline-helpers\")]\n    source: r#\"function _class_name_tdz_error(name) {\n    throw new ReferenceError(\"Class \\\"\" + name + \"\\\" cannot be referenced in computed property keys.\");\n}\n\"#,\n    #[cfg(feature = \"inline-helpers\")]\n    deps: super::HelperBitmap::from_bits(0x00000000000000000000000000800000),\n};\n\n#[cfg(feature = \"inline-helpers\")]\npub fn stmts() -> &'static [swc_ecma_ast::Stmt] {\n    static STMTS: once_cell::sync::Lazy<Vec<swc_ecma_ast::Stmt>> =\n        once_cell::sync::Lazy::new(|| super::super::parse(DEF.source, DEF.import_path));\n    &STMTS\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_class_name_tdz_error.rs#L1-L24","documentation":"In the Main phase (inside the root element) every token kind has a handler except the doctype token, which lands in the `_` catch-all and yields ErrorKind::UnexpectedTokenInMainPhase. XML allows exactly one doctype, and only in the prolog before the root element, so a `<!DOCTYPE ...>` seen after content has started is reported here. It is a recoverable error: the doctype token is dropped and parsing continues.","triggerScenarios":"A `<!DOCTYPE ...>` declaration that appears inside the root element or after it has been opened, e.g. `<root><!DOCTYPE item></root>`, or doctype text embedded in generated fragments that were concatenated after the root started.","commonSituations":"XML fragments generated per-item each containing their own doctype and then concatenated inside a wrapper element; templating that injects a doctype partial in the wrong slot; SVG/HTML-style documents (which commonly carry doctypes) fed to the XML parser with the doctype nested in the body.","solutions":["Move the `<!DOCTYPE ...>` declaration to the very top of the document, before the root element and after nothing but the optional XML declaration.","If generating fragments, emit the doctype once for the outer document and strip it from inner fragments.","Check the error span to find which doctype is misplaced when several exist.","Validate with xmllint --noout to get a second opinion on the document structure."],"exampleFix":"<!-- before: doctype inside the root element -->\n<items>\n  <!DOCTYPE item>\n  <item/>\n</items>\n\n<!-- after -->\n<!DOCTYPE items>\n<items>\n  <item/>\n</items>","handlingStrategy":"validation","validationCode":"use swc_xml_parser::error::ErrorKind;\n\nlet mut errors = Vec::new();\nswc_xml_parser::parse_file_as_document(&fm, config, &mut errors)?;\nif errors\n    .iter()\n    .any(|e| matches!(e.kind(), ErrorKind::UnexpectedTokenInMainPhase))\n{\n    return Err(\"misplaced doctype (must precede the root element)\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Emit the doctype exactly once, as the first markup in the document.","When merging per-item XML fragments, strip their doctype declarations first.","Prefer node-level merging over text concatenation."],"tags":["xml","parser","doctype","misplaced-declaration","swc","recoverable"],"backgroundTag":"misplaced-doctype","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"}