Skip to content

Commit 0970032

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrated BugReporting, ErrorUtils, Vibration & YellowBox to use export syntax. (#48763)
Summary: Pull Request resolved: #48763 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling. ## This diff - Updates files in `Libraries/BugReporting`, `Libraries/vendor`, `Libraries/Vibration` and `Libraries/YellowBox` to use `export` syntax - `export default` for qualified objects, many `export` statements for collections (determined by how it's imported) - Appends `.default` to requires of the changed files. - Updates Jest mocks. - Updates the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/BugReporting`, `Libraries/vendor`, `Libraries/Vibration` and `Libraries/YellowBox` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. Reviewed By: cortinico Differential Revision: D68329075 fbshipit-source-id: 7079a54ce3631171f8d7559bc33cab014df1d16d
1 parent 9a70bc0 commit 0970032

File tree

12 files changed

+24
-21
lines changed

12 files changed

+24
-21
lines changed

packages/react-native/Libraries/BatchedBridge/MessageQueue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Systrace = require('../Performance/Systrace');
1414
const deepFreezeAndThrowOnMutationInDev = require('../Utilities/deepFreezeAndThrowOnMutationInDev');
1515
const stringifySafe = require('../Utilities/stringifySafe').default;
1616
const warnOnce = require('../Utilities/warnOnce');
17-
const ErrorUtils = require('../vendor/core/ErrorUtils');
17+
const ErrorUtils = require('../vendor/core/ErrorUtils').default;
1818
const invariant = require('invariant');
1919

2020
export type SpyData = {

packages/react-native/Libraries/BugReporting/BugReporting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type DebugData = {
2323

2424
function defaultExtras() {
2525
BugReporting.addFileSource('react_hierarchy.txt', () =>
26-
require('./dumpReactTree')(),
26+
require('./dumpReactTree').default(),
2727
);
2828
}
2929

@@ -137,4 +137,4 @@ class BugReporting {
137137
}
138138
}
139139

140-
module.exports = BugReporting;
140+
export default BugReporting;

packages/react-native/Libraries/BugReporting/dumpReactTree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'use strict';
1212

1313
/*
14-
const getReactData = require('getReactData');
14+
const getReactData = require('getReactData').default;
1515
1616
const INDENTATION_SIZE = 2;
1717
const MAX_DEPTH = 2;
@@ -148,4 +148,4 @@ function indent(size: number) {
148148
}
149149
*/
150150

151-
module.exports = dumpReactTree;
151+
export default dumpReactTree;

packages/react-native/Libraries/BugReporting/getReactData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ function copyWithSet(
184184
return copyWithSetImpl(obj, path, 0, value);
185185
}
186186

187-
module.exports = getData;
187+
export default getData;

packages/react-native/Libraries/Core/setUpErrorHandling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (global.RN$useAlwaysAvailableJSErrorHandling !== true) {
3434
}
3535
};
3636

37-
const ErrorUtils = require('../vendor/core/ErrorUtils');
37+
const ErrorUtils = require('../vendor/core/ErrorUtils').default;
3838
ErrorUtils.setGlobalHandler(handleError);
3939
}
4040
}

packages/react-native/Libraries/Vibration/Vibration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ const Vibration = {
110110
},
111111
};
112112

113-
module.exports = Vibration;
113+
export default Vibration;

packages/react-native/Libraries/YellowBox/YellowBoxDeprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (__DEV__) {
6868
}
6969

7070
// $FlowFixMe[method-unbinding]
71-
module.exports = (YellowBox: Class<React.Component<Props>> & {
71+
export default (YellowBox: Class<React.Component<Props>> & {
7272
ignoreWarnings($ReadOnlyArray<IgnorePattern>): void,
7373
install(): void,
7474
uninstall(): void,

packages/react-native/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'use strict';
1313

1414
const LogBox = require('../../LogBox/LogBox').default;
15-
const YellowBox = require('../YellowBoxDeprecated');
15+
const YellowBox = require('../YellowBoxDeprecated').default;
1616

1717
describe('YellowBox', () => {
1818
beforeEach(() => {

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ declare class BugReporting {
15401540
): { remove: () => void, ... };
15411541
static collectExtraData(): DebugData;
15421542
}
1543-
declare module.exports: BugReporting;
1543+
declare export default typeof BugReporting;
15441544
"
15451545
`;
15461546

@@ -1552,13 +1552,13 @@ declare export default typeof NativeBugReporting;
15521552

15531553
exports[`public API should not change unintentionally Libraries/BugReporting/dumpReactTree.js 1`] = `
15541554
"declare function dumpReactTree(): string;
1555-
declare module.exports: dumpReactTree;
1555+
declare export default typeof dumpReactTree;
15561556
"
15571557
`;
15581558

15591559
exports[`public API should not change unintentionally Libraries/BugReporting/getReactData.js 1`] = `
15601560
"declare function getData(element: Object): Object;
1561-
declare module.exports: getData;
1561+
declare export default typeof getData;
15621562
"
15631563
`;
15641564

@@ -9406,7 +9406,7 @@ exports[`public API should not change unintentionally Libraries/Vibration/Vibrat
94069406
vibrate: (pattern: number | Array<number>, repeat: boolean) => void,
94079407
cancel: () => void,
94089408
};
9409-
declare module.exports: Vibration;
9409+
declare export default typeof Vibration;
94109410
"
94119411
`;
94129412

@@ -9510,7 +9510,7 @@ declare module.exports: WebSocketInterceptor;
95109510

95119511
exports[`public API should not change unintentionally Libraries/YellowBox/YellowBoxDeprecated.js 1`] = `
95129512
"type Props = $ReadOnly<{}>;
9513-
declare module.exports: Class<React.Component<Props>> & {
9513+
declare export default Class<React.Component<Props>> & {
95149514
ignoreWarnings($ReadOnlyArray<IgnorePattern>): void,
95159515
install(): void,
95169516
uninstall(): void,
@@ -9526,7 +9526,7 @@ declare export default typeof rejectionTrackingOptions;
95269526
`;
95279527

95289528
exports[`public API should not change unintentionally Libraries/vendor/core/ErrorUtils.js 1`] = `
9529-
"declare module.exports: ErrorUtilsT;
9529+
"declare export default ErrorUtilsT;
95309530
"
95319531
`;
95329532

packages/react-native/Libraries/vendor/core/ErrorUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ import type {ErrorUtilsT} from '@react-native/js-polyfills/error-guard';
2222
* that use it aren't just using a global variable, so simply export the global
2323
* variable here. ErrorUtils is originally defined in a file named error-guard.js.
2424
*/
25-
module.exports = (global.ErrorUtils: ErrorUtilsT);
25+
export default (global.ErrorUtils: ErrorUtilsT);

0 commit comments

Comments
 (0)