Skip to content

Commit 0e590c0

Browse files
jbromafacebook-github-bot
authored andcommitted
refactor: use ESM exports in ReactNativeViewConfigRegistry (#27508) (#40787)
Summary: ## Summary When transpiling `react-native` with `swc` this file caused some trouble as it mixes ESM and CJS import/export syntax. This PR addresses this by converting CJS exports to ESM exports. As `ReactNativeViewConfigRegistry` is synced from `react` to `react-native` repository, it's required to make the change here. I've also aligned the mock of `ReactNativeViewConfigRegistry` to reflect current implementation. Pull Request resolved: #40787 Test Plan: Sandcastle tests Reviewed By: noahlemen Differential Revision: D50229257 Pulled By: javache fbshipit-source-id: 2e848a1ac434c45e219876c1042aacb42c77cb6f
1 parent 3a26e55 commit 0e590c0

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515

1616
import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttributes';
1717
import UIManager from '../ReactNative/UIManager';
18-
import ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
18+
import * as ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
1919
import verifyComponentAttributeEquivalence from '../Utilities/verifyComponentAttributeEquivalence';
2020
import * as StaticViewConfigValidator from './StaticViewConfigValidator';
2121
import {createViewConfig} from './ViewConfig';

packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import typeof {
2727
diff as diffAttributePayloads,
2828
} from '../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload';
2929
import typeof UIManager from '../ReactNative/UIManager';
30-
import typeof ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
30+
import typeof * as ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
3131
import typeof flattenStyle from '../StyleSheet/flattenStyle';
3232
import type {DangerouslyImpreciseStyleProp} from '../StyleSheet/StyleSheet';
3333
import typeof deepFreezeAndThrowOnMutationInDev from '../Utilities/deepFreezeAndThrowOnMutationInDev';

packages/react-native/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noformat
88
* @flow strict-local
99
* @nolint
10-
* @generated SignedSource<<1b39316520f5af25f0a141d7d78b0809>>
10+
* @generated SignedSource<<3cf9b746913da1666cb5bce0ae12d978>>
1111
*/
1212

1313
'use strict';
@@ -16,7 +16,7 @@ import {type ViewConfig} from './ReactNativeTypes';
1616
import invariant from 'invariant';
1717

1818
// Event configs
19-
const customBubblingEventTypes: {
19+
export const customBubblingEventTypes: {
2020
[eventName: string]: $ReadOnly<{
2121
phasedRegistrationNames: $ReadOnly<{
2222
captured: string,
@@ -26,16 +26,13 @@ const customBubblingEventTypes: {
2626
}>,
2727
...
2828
} = {};
29-
const customDirectEventTypes: {
29+
export const customDirectEventTypes: {
3030
[eventName: string]: $ReadOnly<{
3131
registrationName: string,
3232
}>,
3333
...
3434
} = {};
3535

36-
exports.customBubblingEventTypes = customBubblingEventTypes;
37-
exports.customDirectEventTypes = customDirectEventTypes;
38-
3936
const viewConfigCallbacks = new Map<string, ?() => ViewConfig>();
4037
const viewConfigs = new Map<string, ViewConfig>();
4138

@@ -77,7 +74,7 @@ function processEventTypes(viewConfig: ViewConfig): void {
7774
* A callback is provided to load the view config from UIManager.
7875
* The callback is deferred until the view is actually rendered.
7976
*/
80-
exports.register = function (name: string, callback: () => ViewConfig): string {
77+
export function register(name: string, callback: () => ViewConfig): string {
8178
invariant(
8279
!viewConfigCallbacks.has(name),
8380
'Tried to register two views with the same name %s',
@@ -91,14 +88,14 @@ exports.register = function (name: string, callback: () => ViewConfig): string {
9188
);
9289
viewConfigCallbacks.set(name, callback);
9390
return name;
94-
};
91+
}
9592

9693
/**
9794
* Retrieves a config for the specified view.
9895
* If this is the first time the view has been used,
9996
* This configuration will be lazy-loaded from UIManager.
10097
*/
101-
exports.get = function (name: string): ViewConfig {
98+
export function get(name: string): ViewConfig {
10299
let viewConfig;
103100
if (!viewConfigs.has(name)) {
104101
const callback = viewConfigCallbacks.get(name);
@@ -126,4 +123,4 @@ exports.get = function (name: string): ViewConfig {
126123
}
127124
invariant(viewConfig, 'View config not found for name %s', name);
128125
return viewConfig;
129-
};
126+
}

0 commit comments

Comments
 (0)