1use react_compiler_diagnostics::JsString;2use serde::{Deserialize, Serialize};34use crate::common::BaseNode;56#[derive(Debug, Clone, Serialize, Deserialize)]7pub struct StringLiteral {8 #[serde(flatten)]9 pub base: BaseNode,10 /// JS string values may contain unpaired surrogates; see [`JsString`].11 pub value: JsString,12}1314#[derive(Debug, Clone, Serialize, Deserialize)]15pub struct NumericLiteral {16 #[serde(flatten)]17 pub base: BaseNode,18 pub value: f64,19 /// Babel's extra field containing the raw source text.20 /// Used to recover exact f64 values that serde_json may parse imprecisely.21 #[serde(default, skip_serializing_if = "Option::is_none")]22 pub extra: Option<NumericLiteralExtra>,23}2425impl NumericLiteral {26 /// Get the f64 value, preferring re-parsing from `extra.raw` when available27 /// to avoid serde_json float parsing precision issues.28 pub fn precise_value(&self) -> f64 {29 if let Some(extra) = &self.extra {30 if let Ok(v) = extra.raw.parse::<f64>() {31 return v;32 }33 }34 self.value35 }36}3738#[derive(Debug, Clone, Serialize, Deserialize)]39pub struct NumericLiteralExtra {40 pub raw: String,41 #[serde(default, rename = "rawValue")]42 pub raw_value: Option<f64>,43}4445#[derive(Debug, Clone, Serialize, Deserialize)]46pub struct BooleanLiteral {47 #[serde(flatten)]48 pub base: BaseNode,49 pub value: bool,50}5152#[derive(Debug, Clone, Serialize, Deserialize)]53pub struct NullLiteral {54 #[serde(flatten)]55 pub base: BaseNode,56}5758#[derive(Debug, Clone, Serialize, Deserialize)]59pub struct BigIntLiteral {60 #[serde(flatten)]61 pub base: BaseNode,62 pub value: String,63}6465#[derive(Debug, Clone, Serialize, Deserialize)]66pub struct RegExpLiteral {67 #[serde(flatten)]68 pub base: BaseNode,69 pub pattern: String,70 pub flags: String,71}7273#[derive(Debug, Clone, Serialize, Deserialize)]74pub struct TemplateElement {75 #[serde(flatten)]76 pub base: BaseNode,77 pub value: TemplateElementValue,78 pub tail: bool,79}8081#[derive(Debug, Clone, Serialize, Deserialize)]82pub struct TemplateElementValue {83 pub raw: String,84 #[serde(default, skip_serializing_if = "Option::is_none")]85 pub cooked: Option<String>,86}