{"record":{"id":"03e752ed4e124442","repo":"swc-project/swc","slug":"assignment-to-constant-variable","errorCode":null,"errorMessage":"Assignment to constant variable.","messagePattern":"Assignment to constant variable\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bindings/binding_nodejs_support_wasm/src/nodejs.rs","lineNumber":1148,"sourceCode":"        binding.namespace,\n        export_property_access(&binding.export_name)\n    )\n}\n\nfn export_property_access(export_name: &str) -> String {\n    if is_identifier_name(export_name) {\n        format!(\".{export_name}\")\n    } else {\n        format!(\"[{}]\", json_string(export_name))\n    }\n}\n\nfn import_meta_error_expression() -> String {\n    \"(() => { throw new SyntaxError(\\\"Cannot use import.meta outside a module\\\"); })()\".to_string()\n}\n\nfn import_assignment_error_expression() -> String {\n    \"(() => { throw new TypeError(\\\"Assignment to constant variable.\\\"); })()\".to_string()\n}\n\nfn is_identifier_name(value: &str) -> bool {\n    let mut chars = value.chars();\n    let Some(first) = chars.next() else {\n        return false;\n    };\n\n    if !(first == '_' || first == '$' || first.is_ascii_alphabetic()) {\n        return false;\n    }\n\n    chars.all(|ch| ch == '_' || ch == '$' || ch.is_ascii_alphanumeric())\n}\n\nenum ParseOutcome {\n    Valid,\n    Invalid(Vec<ParseError>),","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/bindings/binding_nodejs_support_wasm/src/nodejs.rs#L1130-L1166","documentation":"While handling an end tag in the Main phase, the parser compares the end tag's name with the tag name of the currently open element (top of open_elements_stack). If they differ, this mismatch error is recorded with the end tag's span. Parsing still recovers: the parser searches the open element stack for any element matching the end tag name and pops up to it if found, so the document remains usable.","triggerScenarios":"Any end tag that does not match the innermost open element: `<a><b></a></b>`-style crossings, `<Div></div>` case mismatches, namespace prefixes spelled differently in open/close tags, or an end tag for an element that was never opened. The comparison is on the raw token tag_name string, so prefix casing matters.","commonSituations":"Case mismatches from templating (e.g. React-style `<Div>` closed as `</div>`); refactoring that renames a tag in one place only; namespace-prefixed tags where the prefix differs between open and close; self-closing HTML habits (`<br>`) fed into an XML parser combined with mismatched closing tags.","solutions":["Jump to the error span to see which end tag mismatches, then fix either that end tag or the corresponding unclosed inner element.","Balance tags strictly: every start tag needs a matching end tag with the identical, case-sensitive name (including namespace prefix).","If the document intentionally omits inner close tags, rewrite them as self-closing empty tags (`<child/>`) instead of relying on implied closes.","Note the recovery rule: the parser pops up to the nearest matching name on the stack, so also check for cascading mismatch errors that all stem from one original typo."],"exampleFix":"<!-- before: crossed/case-mismatched tags -->\n<Config>\n  <Item>value</item>\n</config>\n\n<!-- after -->\n<Config>\n  <Item>value</Item>\n</Config>","handlingStrategy":"validation","validationCode":"use swc_xml_parser::error::ErrorKind;\n\nlet mut errors = Vec::new();\nlet doc = swc_xml_parser::parse_file_as_document(&fm, config, &mut errors)?;\nlet mismatched = errors\n    .iter()\n    .any(|e| matches!(e.kind(), ErrorKind::OpeningAndEndingTagMismatch));\nif mismatched {\n    // document was recovered, but spans/end-tag spans may be inconsistent\n    return Err(\"unbalanced tags\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat tag names as case-sensitive identifiers; lint templates where casing is inconsistent (e.g. <Div> vs </div>).","Use an editor/IDE XML language mode that highlights mismatched end tags as you type.","Serialize rather than hand-edit when possible - serializers cannot emit crossed tags."],"tags":["xml","parser","tag-mismatch","well-formedness","swc","recoverable"],"backgroundTag":"tag-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}