diff --git a/compiler/crates/react_compiler_ast/src/scope.rs b/compiler/crates/react_compiler_ast/src/scope.rs index ac4e901d554..8d11211ee8c 100644 --- a/compiler/crates/react_compiler_ast/src/scope.rs +++ b/compiler/crates/react_compiler_ast/src/scope.rs @@ -115,7 +115,7 @@ pub struct ScopeInfo { /// Parallel to node_to_scope — same keys, but stores the end position /// of the scope-creating AST node. Used to determine if a source position /// falls within a particular scope's AST range. - #[serde(default)] + #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub node_to_scope_end: HashMap, /// Maps an Identifier AST node's start offset to the binding it resolves to. @@ -126,11 +126,19 @@ pub struct ScopeInfo { /// Maps an identifier reference's node-ID to the binding it resolves to. /// Only present for identifiers that resolve to a binding (not globals). /// Uses IndexMap to preserve insertion order. - #[serde(default, rename = "refNodeIdToBinding")] + #[serde( + default, + rename = "refNodeIdToBinding", + skip_serializing_if = "IndexMap::is_empty" + )] pub ref_node_id_to_binding: IndexMap, /// Maps a scope-creating AST node's node-ID to the scope it creates. - #[serde(default, rename = "nodeIdToScope")] + #[serde( + default, + rename = "nodeIdToScope", + skip_serializing_if = "HashMap::is_empty" + )] pub node_id_to_scope: HashMap, /// The program-level (module) scope. Always scopes[0].