{"record":{"id":"d0c51ab8504622bc","repo":"swc-project/swc","slug":"failed-to-parse-the-value-of-decimalliteral","errorCode":null,"errorMessage":"failed to parse the value of DecimalLiteral","messagePattern":"failed to parse the value of DecimalLiteral","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/swcify/lit.rs","lineNumber":161,"sourceCode":"                .parse()\n                .map(Box::new)\n                .expect(\"failed to parse the value of BigIntLiteral\"),\n            // TODO improve me\n            raw: None,\n        }\n    }\n}\n\nimpl Swcify for DecimalLiteral {\n    type Output = Number;\n\n    fn swcify(self, ctx: &Context) -> Self::Output {\n        Number {\n            span: ctx.span(&self.base),\n            value: self\n                .value\n                .parse()\n                .expect(\"failed to parse the value of DecimalLiteral\"),\n            // TODO improve me\n            raw: None,\n        }\n    }\n}\n","sourceCodeStart":143,"sourceCodeEnd":167,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/swcify/lit.rs#L143-L167","documentation":"Thrown while converting an ESTree DecimalLiteral into swc's Number node (swc_estree_compat `swcify`). The `value` string is parsed with Rust's `f64::from_str`, which accepts only standard float syntax (digits, optional '.', exponent, optional sign, inf/NaN); the `.expect(...)` panics on any other content. ESTree decimal-proposal literals keep the 'm' suffix in their textual value (e.g. \"1.1m\"), which f64 parsing rejects, as do 'n' BigInt suffixes, whitespace, and empty strings.","triggerScenarios":"Calling `.swcify(ctx)` on a tree containing a DecimalLiteral whose `value` is not parseable as f64: value=\"1.1m\", value=\"0.3m\", value=\"10n\", value=\"\", or value with whitespace/thousand separators.","commonSituations":"Converting ASTs from parsers that support the (withdrawn) JS decimal proposal and leave the 'm' suffix in value; mixing BigInt values into decimal nodes; hand-crafted fixtures; lossy JSON round-trips that empty the value field.","solutions":["Normalize the value before converting: strip a trailing 'm' (and any 'n' or separators) so the string is a plain decimal number","If you generate the ESTree AST yourself, emit value as a plain numeric string like \"1.1\"","Filter/validate DecimalLiteral nodes before running swcify and surface a proper error instead of a panic","Patch the crate to use a fallible parse and report the value in a diagnostic"],"exampleFix":"// before\n// node = { type: 'DecimalLiteral', value: '1.1m' }\nswcify(node); // panics: failed to parse the value of DecimalLiteral\n\n// after\nnode.value = node.value.replace(/[mn]$/, ''); // '1.1'\nswcify(node);","handlingStrategy":"validation","validationCode":"function decimalValueOk(node) {\n  if (node.type !== 'DecimalLiteral') return true;\n  const v = String(node.value).replace(/[mn]$/, '');\n  return v !== '' && !Number.isNaN(Number(v));\n}\nconst bad = nodes.filter(n => !decimalValueOk(n));\nif (bad.length) throw new Error(`unparseable DecimalLiteral value: ${bad[0].value}`);","typeGuard":"function isParseableDecimalLiteral(node: unknown): boolean {\n  if (typeof node !== 'object' || node === null) return false;\n  const n = node as { type?: string; value?: unknown };\n  if (n.type !== 'DecimalLiteral') return false;\n  if (typeof n.value !== 'string') return false;\n  const v = n.value.replace(/[mn]$/, '');\n  return v !== '' && !Number.isNaN(Number(v));\n}","tryCatchPattern":"// Rust: convert the panic into an error at the boundary\nlet out = std::panic::catch_unwind(|| ast.swcify(&ctx))\n    .map_err(|_| anyhow::anyhow!(\"DecimalLiteral value failed to parse; check for 'm' suffix\"));","preventionTips":["Strip the decimal 'm' (and bigint 'n') suffixes from literal values at ingestion, before any AST conversion","Reject empty string values when reading ASTs from JSON sources","Add fixture tests covering decimal/bigint literals to your conversion pipeline"],"tags":["decimal","estree-compat","parse","panic","swcify","rust"],"backgroundTag":"invalid-numeric-literal-string","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}