{"record":{"id":"a342a4ee905069ab","repo":"swc-project/swc","slug":"invalid-name-reference-name-id","errorCode":null,"errorMessage":"invalid name reference: {name_id}","messagePattern":"invalid name reference: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_config/src/source_map.rs","lineNumber":93,"sourceCode":"                            if nums.len() != 4 && nums.len() != 5 {\n                                bail!(\n                                    \"invalid vlq segment size; expected 4 or 5, got {}\",\n                                    nums.len()\n                                );\n                            }\n                            src_id = (i64::from(src_id) + nums[1]) as u32;\n                            if src_id >= sources.len() as u32 {\n                                bail!(\"invalid source reference: {src_id}\");\n                            }\n\n                            src = src_id;\n                            src_line = (i64::from(src_line) + nums[2]) as u32;\n                            src_col = (i64::from(src_col) + nums[3]) as u32;\n\n                            if nums.len() > 4 {\n                                name_id = (i64::from(name_id) + nums[4]) as u32;\n                                if name_id >= names.len() as u32 {\n                                    bail!(\"invalid name reference: {name_id}\");\n                                }\n                                name = name_id;\n                            }\n                        }\n\n                        tokens.push(RawToken {\n                            dst_line: dst_line as u32,\n                            dst_col,\n                            src_line,\n                            src_col,\n                            src_id: src,\n                            name_id: name,\n                            is_range: false,\n                        });\n                    }\n                }\n\n                let mut map = SourceMap::new(","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_config/src/source_map.rs#L75-L111","documentation":"Same decoder loop as the source-index check, but for the optional 5th VLQ field: name_id accumulates deltas across segments and must remain within the `names` array bounds. When the accumulated name index >= names.len(), the mappings reference an original identifier name that does not exist in the `names` array, and decoding fails. The `names` array and `mappings` are out of sync.","triggerScenarios":"Supplying a parsed input source map whose `names` array was stripped (e.g. minified down to save bytes) while mappings still contain 5-field segments with name deltas; or splicing mappings from another file.","commonSituations":"Source map post-processors that drop or truncate the `names` array for size; merging/concatenating source maps without remapping name indices; producer tools emitting inconsistent maps after renaming passes; cached stale maps after a build change.","solutions":["Regenerate the source map from the original tool so `names` and `mappings` stay consistent","If name mappings are not needed, strip the 5th field from segments as well when stripping `names` (or set names to match indices)","Validate with a standard source-map library first to pinpoint the inconsistent segment","Pass the map as a JSON string or omit it if not required by your pipeline"],"exampleFix":"// before: names array dropped but mappings still reference it\nmap.names = vec![];\n\n// after: keep names, or regenerate the map wholesale\n// (preferred) let fresh = producer.generate_source_map();","handlingStrategy":"validation","validationCode":"// Cheap consistency gate: if you strip `names`, ensure no 5-field segments remain\nfunction hasNameRefs(mappings) { /* decode VLQ; true if any segment has 5 fields */ }\nif (map.names.length === 0 && hasNameRefs(map.mappings)) throw new Error('mappings reference missing names');","typeGuard":null,"tryCatchPattern":"try { await transform(src, { inputSourceMap: map }) } catch (e) { if (/invalid name reference/.test(e.message)) { return transform(src, {}); } throw e; }","preventionTips":["Never truncate the `names` array without also stripping the 5th field from segments","Regenerate maps wholesale instead of surgically editing fields","Gate third-party source maps through a standard consumer in CI"],"tags":["sourcemap","name-index","input-sourcemap","delta-encoding","malformed-input"],"backgroundTag":"sourcemap-index-out-of-range","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"}