Skip to content

Commit c36665f

Browse files
emily8rownmeta-codesync[bot]
authored andcommitted
Fix hash generation for declare const types in API snapshot #54818 (#54822)
Summary: Pull Request resolved: #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
1 parent 753c1e1 commit c36665f

3 files changed

Lines changed: 120 additions & 81 deletions

File tree

packages/react-native/ReactNativeApi.d.ts

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<23a3208168c8d68b6cfefa829d849408>>
7+
* @generated SignedSource<<bffba0612c645ddb6166e1f5bb1187f2>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -5954,59 +5954,59 @@ declare type WrapperComponentProvider = (
59545954
) => React.ComponentType<any>
59555955
export {
59565956
AccessibilityActionEvent, // f6181a2c
5957-
AccessibilityInfo, // 70604904
5957+
AccessibilityInfo, // ce4850e1
59585958
AccessibilityProps, // 5a2836fc
59595959
AccessibilityRole, // f2f2e066
59605960
AccessibilityState, // b0c2b3f7
59615961
AccessibilityValue, // cf8bcb74
5962-
ActionSheetIOS, // 88e6bfb0
5962+
ActionSheetIOS, // b558559e
59635963
ActionSheetIOSOptions, // 1756eb5a
5964-
ActivityIndicator, // 8d041a45
5964+
ActivityIndicator, // 0fbc1b53
59655965
ActivityIndicatorProps, // 64ab03e1
59665966
Alert, // 5bf12165
59675967
AlertButton, // bf1a3b60
59685968
AlertButtonStyle, // ec9fb242
59695969
AlertOptions, // a0cdac0f
59705970
AlertType, // 5ab91217
59715971
AndroidKeyboardEvent, // e03becc8
5972-
Animated, // 9c6edf39
5972+
Animated, // 47139b9b
59735973
AppConfig, // ebddad4b
59745974
AppRegistry, // 6cdee1d6
5975-
AppState, // f7097b1b
5975+
AppState, // 12012be5
59765976
AppStateEvent, // 80f034c3
59775977
AppStateStatus, // 447e5ef2
59785978
Appearance, // 00cbaa0a
59795979
AutoCapitalize, // c0e857a0
5980-
BackHandler, // a9f9bad9
5980+
BackHandler, // 0b13c289
59815981
BackPressEventName, // 4620fb76
59825982
BlurEvent, // 870b9bb5
59835983
BoxShadowValue, // b679703f
5984-
Button, // dd130b61
5984+
Button, // ef82aed4
59855985
ButtonProps, // 3c081e75
5986-
Clipboard, // 9b8c878e
5986+
Clipboard, // 41addb89
59875987
CodegenTypes, // 030a94b8
59885988
ColorSchemeName, // 31a4350e
59895989
ColorValue, // 98989a8f
59905990
ComponentProvider, // b5c60ddd
59915991
ComponentProviderInstrumentationHook, // 9f640048
59925992
CursorValue, // 26522595
5993-
DevMenu, // 99e9fcd6
5994-
DevSettings, // 1a2f3a5f
5995-
DeviceEventEmitter, // 31dc96e7
5996-
DeviceInfo, // cc37eaec
5993+
DevMenu, // 21b8b7a9
5994+
DevSettings, // e55b91dc
5995+
DeviceEventEmitter, // 650e6394
5996+
DeviceInfo, // 521bfb71
59975997
DeviceInfoConstants, // 279e7858
59985998
DimensionValue, // b163a381
59995999
Dimensions, // 980ef68c
60006000
DimensionsPayload, // 653bc26c
60016001
DisplayMetrics, // 1dc35cef
60026002
DisplayMetricsAndroid, // 872e62eb
6003-
DrawerLayoutAndroid, // 14121b61
6003+
DrawerLayoutAndroid, // 5659aca9
60046004
DrawerLayoutAndroidProps, // 66371296
60056005
DrawerSlideEvent, // cc43db83
60066006
DropShadowValue, // e9df2606
6007-
DynamicColorIOS, // 1f9b3410
6007+
DynamicColorIOS, // d96c228c
60086008
DynamicColorIOSTuple, // 023ce58e
6009-
Easing, // b624f91d
6009+
Easing, // 673080ba
60106010
EasingFunction, // 14aee4c0
60116011
EdgeInsetsValue, // bd44afe6
60126012
EmitterSubscription, // de50c359
@@ -6015,19 +6015,19 @@ export {
60156015
EventSubscription, // b8d084aa
60166016
ExtendedExceptionData, // 5a6ccf5a
60176017
FilterFunction, // bf24c0e3
6018-
FlatList, // 940a1186
6019-
FlatListProps, // 6fc8f490
6018+
FlatList, // a6600e49
6019+
FlatListProps, // de2108a1
60206020
FocusEvent, // 529b43eb
60216021
FontVariant, // 7c7558bb
60226022
GestureResponderEvent, // b466f6d6
60236023
GestureResponderHandlers, // 8356843d
60246024
Handle, // 2d65285d
60256025
HostComponent, // 5e13ff5a
60266026
HostInstance, // 489cbe7f
6027-
I18nManager, // f2fa58ce
6027+
I18nManager, // f9870e00
60286028
IOSKeyboardEvent, // e67bfe3a
60296029
IgnorePattern, // ec6f6ece
6030-
Image, // 04474205
6030+
Image, // 957b3726
60316031
ImageBackground, // 06d5af5c
60326032
ImageBackgroundProps, // 473a9eb4
60336033
ImageErrorEvent, // b7b2ae63
@@ -6044,23 +6044,23 @@ export {
60446044
ImageSourcePropType, // bfb5e5c6
60456045
ImageStyle, // 8b22ac76
60466046
ImageURISource, // 016eb083
6047-
InputAccessoryView, // 591855d8
6047+
InputAccessoryView, // ddb7f881
60486048
InputAccessoryViewProps, // 4b6f5450
60496049
InputModeOptions, // 4e8581b9
60506050
Insets, // e7fe432a
6051-
InteractionManager, // 301bfa63
6051+
InteractionManager, // c324d6e3
60526052
KeyDownEvent, // 5309360e
60536053
KeyEvent, // 20fa4267
60546054
KeyUpEvent, // 7c3054e1
6055-
Keyboard, // 87311c77
6056-
KeyboardAvoidingView, // 4a933094
6055+
Keyboard, // 49414c97
6056+
KeyboardAvoidingView, // 23d0b271
60576057
KeyboardAvoidingViewProps, // 81cba23f
60586058
KeyboardEvent, // c3f895d4
60596059
KeyboardEventEasing, // af4091c8
60606060
KeyboardEventName, // 59299ad6
60616061
KeyboardMetrics, // 7997b799
60626062
KeyboardTypeOptions, // ae44efe7
6063-
LayoutAnimation, // 795a5df3
6063+
LayoutAnimation, // 54110cf7
60646064
LayoutAnimationAnim, // 074da826
60656065
LayoutAnimationConfig, // 5e200571
60666066
LayoutAnimationProperties, // 84e6e197
@@ -6070,65 +6070,65 @@ export {
60706070
LayoutChangeEvent, // c674f902
60716071
LayoutConformanceProps, // 055f03b8
60726072
LayoutRectangle, // 6601b294
6073-
Linking, // 292de0a0
6073+
Linking, // b5645d2b
60746074
ListRenderItem, // b5353fd8
60756075
ListRenderItemInfo, // e8595b03
60766076
ListViewToken, // 833d3481
6077-
LogBox, // b58880c6
6077+
LogBox, // 04665d29
60786078
LogData, // 89af6d4c
60796079
MeasureInWindowOnSuccessCallback, // a285f598
60806080
MeasureLayoutOnSuccessCallback, // 3592502a
60816081
MeasureOnSuccessCallback, // 82824e59
6082-
Modal, // 78e8a79d
6082+
Modal, // 9f28d6fe
60836083
ModalBaseProps, // 0c81c9b1
60846084
ModalProps, // a69426b0
60856085
ModalPropsAndroid, // 515fb173
60866086
ModalPropsIOS, // 4fbcedf6
6087-
ModeChangeEvent, // af2c4926
6087+
ModeChangeEvent, // 16790307
60886088
MouseEvent, // 53ede3db
6089-
NativeAppEventEmitter, // b4d20c1d
6089+
NativeAppEventEmitter, // e1340a0a
60906090
NativeColorValue, // d2094c29
60916091
NativeComponentRegistry, // 7fd99ba6
6092-
NativeDialogManagerAndroid, // 6254873e
6092+
NativeDialogManagerAndroid, // 5be8497e
60936093
NativeEventEmitter, // d72906cc
60946094
NativeEventSubscription, // de3942e7
60956095
NativeMethods, // 03dc51c5
60966096
NativeMethodsMixin, // 4b061b7e
6097-
NativeModules, // 1cf72876
6097+
NativeModules, // 4597cd36
60986098
NativeMouseEvent, // ff25cf35
60996099
NativePointerEvent, // 89c1f3ad
61006100
NativeScrollEvent, // caad7f53
61016101
NativeSyntheticEvent, // d2a1fe6a
61026102
NativeTouchEvent, // 59b676df
61036103
NativeUIEvent, // 44ac26ac
6104-
Networking, // b674447b
6104+
Networking, // bbc5be42
61056105
OpaqueColorValue, // 25f3fa5b
6106-
PanResponder, // 98a9b6fc
6106+
PanResponder, // d803bfcf
61076107
PanResponderCallbacks, // d325aa56
61086108
PanResponderGestureState, // 54baf558
6109-
PanResponderInstance, // c8b0d00c
6109+
PanResponderInstance, // 84d7fd52
61106110
Permission, // 06473f4f
61116111
PermissionStatus, // 4b7de97b
6112-
PermissionsAndroid, // 0c1619e7
6112+
PermissionsAndroid, // db2a401e
61136113
PixelRatio, // 10d9e32d
6114-
Platform, // dc0f5740
6114+
Platform, // b73caa89
61156115
PlatformColor, // 8297ec62
61166116
PlatformOSType, // 0a17561e
61176117
PlatformSelectSpec, // 09ed7758
61186118
PointValue, // 69db075f
61196119
PointerEvent, // ff3129ff
61206120
PressabilityConfig, // 9bb563c2
61216121
PressabilityEventHandlers, // ade29c37
6122-
Pressable, // 3c6e4eb9
6122+
Pressable, // a4242e8c
61236123
PressableAndroidRippleConfig, // 42bc9727
61246124
PressableProps, // 42ae2cc7
61256125
PressableStateCallbackType, // 9af36561
61266126
ProcessedColorValue, // 33f74304
6127-
ProgressBarAndroid, // 03e66cf5
6127+
ProgressBarAndroid, // f6740378
61286128
ProgressBarAndroidProps, // 021ef6d2
61296129
PromiseTask, // 5102c862
61306130
PublicRootInstance, // 8040afd7
6131-
PublicTextInstance, // 7d73f802
6131+
PublicTextInstance, // e775d6b1
61326132
PushNotificationEventName, // 84e7e150
61336133
PushNotificationIOS, // b4d1fe78
61346134
PushNotificationPermissions, // c2e7ae4f
@@ -6143,29 +6143,29 @@ export {
61436143
ReturnKeyTypeOptions, // afd47ba3
61446144
Role, // af7b889d
61456145
RootTag, // 3cd10504
6146-
RootTagContext, // 15b60335
6146+
RootTagContext, // 38bfc8f6
61476147
RootViewStyleProvider, // cc8d50e9
61486148
Runnable, // 2cb32c54
61496149
Runnables, // d3749ae1
6150-
SafeAreaView, // 4364c7bb
6150+
SafeAreaView, // 1b0e10d1
61516151
ScaledSize, // 07e417c7
61526152
ScrollEvent, // 84e5b805
6153-
ScrollResponderType, // d39056e7
6153+
ScrollResponderType, // 8eff013e
61546154
ScrollToLocationParamsType, // d7ecdad1
6155-
ScrollView, // 7fb7c469
6156-
ScrollViewImperativeMethods, // eb20aa46
6157-
ScrollViewProps, // d25b90bd
6155+
ScrollView, // dcb23e16
6156+
ScrollViewImperativeMethods, // 92677f19
6157+
ScrollViewProps, // 68051136
61586158
ScrollViewPropsAndroid, // 84e2134b
61596159
ScrollViewPropsIOS, // d83c9733
61606160
ScrollViewScrollToOptions, // 3313411e
61616161
SectionBase, // b376bddc
6162-
SectionList, // 19c9aaa2
6162+
SectionList, // ab067389
61636163
SectionListData, // 119baf83
6164-
SectionListProps, // 52787c42
6164+
SectionListProps, // e0865379
61656165
SectionListRenderItem, // 1fad0435
61666166
SectionListRenderItemInfo, // 745e1992
61676167
Separators, // 6a45f7e3
6168-
Settings, // 4282b0da
6168+
Settings, // 2be0c61e
61696169
Share, // e4591b32
61706170
ShareAction, // ead1004a
61716171
ShareActionSheetError, // 55e4f451
@@ -6178,18 +6178,18 @@ export {
61786178
StatusBarProps, // 06c98add
61796179
StatusBarStyle, // 986b2051
61806180
StyleProp, // fa0e9b4a
6181-
StyleSheet, // 366689d4
6181+
StyleSheet, // 17b08ddb
61826182
SubmitBehavior, // c4ddf490
6183-
Switch, // aebc9941
6183+
Switch, // cd54192c
61846184
SwitchChangeEvent, // 2e5bd2de
61856185
SwitchProps, // 5b2f78be
61866186
Systrace, // b5aa21fc
61876187
TVViewPropsIOS, // 330ce7b5
61886188
TargetedEvent, // 16e98910
61896189
TaskProvider, // 266dedf2
6190-
Text, // bd525aa9
6190+
Text, // e55ac2e2
61916191
TextContentType, // 239b3ecc
6192-
TextInput, // 282b394e
6192+
TextInput, // cf7a3331
61936193
TextInputAndroidProps, // 3f09ce49
61946194
TextInputChangeEvent, // 380cbe93
61956195
TextInputContentSizeChangeEvent, // 5fba3f54
@@ -6203,39 +6203,39 @@ export {
62036203
TextLayoutEvent, // 45b0a8d7
62046204
TextProps, // 95d8874d
62056205
TextStyle, // f3404e2b
6206-
ToastAndroid, // b4875e35
6207-
Touchable, // 93eb6c63
6208-
TouchableHighlight, // b4304a98
6209-
TouchableHighlightProps, // c871f353
6206+
ToastAndroid, // 88a8969a
6207+
Touchable, // b89b4800
6208+
TouchableHighlight, // 254e7a9d
6209+
TouchableHighlightProps, // 4af01d74
62106210
TouchableNativeFeedback, // 60a3e196
62116211
TouchableNativeFeedbackProps, // 372d3213
6212-
TouchableOpacity, // 7e33acfd
6213-
TouchableOpacityProps, // 73c84562
6212+
TouchableOpacity, // bd92a35c
6213+
TouchableOpacityProps, // 822164b4
62146214
TouchableWithoutFeedback, // 7363a906
62156215
TouchableWithoutFeedbackProps, // 68e3d87f
62166216
TransformsStyle, // 65e70f18
62176217
TurboModule, // dfe29706
62186218
TurboModuleRegistry, // 4ace6db2
6219-
UIManager, // 8d2c8281
6220-
UTFSequence, // baacd11b
6221-
Vibration, // 315e131d
6222-
View, // 39dd4de4
6219+
UIManager, // a1a7cc01
6220+
UTFSequence, // ad625158
6221+
Vibration, // 31e4bbf8
6222+
View, // 76fc9522
62236223
ViewProps, // 1945fbb5
62246224
ViewPropsAndroid, // 21385d96
62256225
ViewPropsIOS, // 58ee19bf
62266226
ViewStyle, // c2db0e6e
6227-
VirtualViewMode, // 85a69ef6
6228-
VirtualizedList, // 4d513939
6229-
VirtualizedListProps, // d3376e70
6230-
VirtualizedSectionList, // 446ba0df
6231-
VirtualizedSectionListProps, // 4f35f007
6227+
VirtualViewMode, // 6be59722
6228+
VirtualizedList, // 68c7345e
6229+
VirtualizedListProps, // de80b6d7
6230+
VirtualizedSectionList, // 9fd9cd61
6231+
VirtualizedSectionListProps, // bdbfdf88
62326232
WrapperComponentProvider, // 9cf3844c
6233-
codegenNativeCommands, // e16d62f7
6234-
codegenNativeComponent, // ed4c8103
6235-
findNodeHandle, // c6b08494
6236-
processColor, // 00453092
6237-
registerCallableModule, // 86b65226
6238-
requireNativeComponent, // e659aa32
6233+
codegenNativeCommands, // 628a7c0a
6234+
codegenNativeComponent, // a733b8b6
6235+
findNodeHandle, // 65981202
6236+
processColor, // 6e877698
6237+
registerCallableModule, // 839c8cfe
6238+
requireNativeComponent, // 72c09c3d
62396239
useAnimatedValue, // b18adb63
62406240
useColorScheme, // c216d6f7
62416241
usePressability, // fe1f27d8

scripts/js-api/build-types/transforms/typescript/__tests__/versionExportedApis-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,27 @@ describe('versionExportedApis', () => {
726726
"
727727
`);
728728
});
729+
730+
test('should handle typeof with declare const and track dependencies', async () => {
731+
const code = `
732+
type AccessibilityInfo_default = {
733+
isScreenReaderEnabled: () => Promise<boolean>;
734+
};
735+
declare const AccessibilityInfo: typeof AccessibilityInfo_default;
736+
declare type AccessibilityInfo = typeof AccessibilityInfo;
737+
export { AccessibilityInfo };
738+
`;
739+
const result = await translate(code);
740+
expect(result).toMatchInlineSnapshot(`
741+
"type AccessibilityInfo_default = {
742+
isScreenReaderEnabled: () => Promise<boolean>;
743+
};
744+
declare const AccessibilityInfo: typeof AccessibilityInfo_default;
745+
declare type AccessibilityInfo = typeof AccessibilityInfo;
746+
export {
747+
AccessibilityInfo, // 2b0c85e6, Deps: [AccessibilityInfo_default], Total: 1, Tree: AccessibilityInfo→[AccessibilityInfo_default]
748+
};
749+
"
750+
`);
751+
});
729752
});

0 commit comments

Comments
 (0)