SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

Fix hash generation for declare const types in API snapshot #54818 (#54822)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54822

Updates hash generation in `versionExportedApis.js` to track changes to `declare const` type declarations like `AccessibilityInfo_default`.

Previously, changes to APIs (e.g., `AccessibilityInfo`) would not always update their hashes in `ReactNativeApi.d.ts`, causing the breaking change detection to miss actual API changes.

Three issues prevented proper hash tracking:

1. **`VariableDeclaration` types weren't tracked** - `declare const X: {...}` was not in the list of tracked declaration types
2. **Duplicate declarations caused overwrites** - `declare type X = typeof X` would overwrite `declare const X: typeof X_default` in the declarations map, losing the dependency on `X_default`
3. **`typeof X` queries weren't extracting dependencies** - references via `typeof` weren't being added to the dependency graph

## Fix

- Add `t.isVariableDeclaration(node)` to tracked types with proper name extraction
- Prevent overwriting existing declarations (first declaration wins)
- Handle `TSTypeQuery` nodes to extract `typeof X` dependencies

### Note on Hash Changes

This PR causes many hashes to change, even for types that haven't been modified. This is expected because the hash computation now includes `declare const` dependencies that were previously ignored.

**Before:** `AccessibilityInfo` hash only included `declare type AccessibilityInfo = typeof AccessibilityInfo` (self-reference)
**After:** Hash now includes `declare const AccessibilityInfo: typeof AccessibilityInfo_default` + the full `AccessibilityInfo_default` type

## Changelog:
[GENERAL] [FIXED] - hash generation includes `declare const` types in API snapshot

Reviewed By: huntie

Differential Revision: D88653322

fbshipit-source-id: abdf9c5e11bf8ff9e6e2f17a743a2d5aa213ae1c
E
Emily Brown committed
c36665f7c658c641cf1b6cca890415bdb149a623
Parent: 753c1e1
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 12/10/2025, 11:10:32 AM