mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrated BugReporting, ErrorUtils, Vibration & YellowBox to use export syntax. (#48763)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9a70bc0418
commit
09700327f7
@@ -14,7 +14,7 @@ const Systrace = require('../Performance/Systrace');
|
||||
const deepFreezeAndThrowOnMutationInDev = require('../Utilities/deepFreezeAndThrowOnMutationInDev');
|
||||
const stringifySafe = require('../Utilities/stringifySafe').default;
|
||||
const warnOnce = require('../Utilities/warnOnce');
|
||||
const ErrorUtils = require('../vendor/core/ErrorUtils');
|
||||
const ErrorUtils = require('../vendor/core/ErrorUtils').default;
|
||||
const invariant = require('invariant');
|
||||
|
||||
export type SpyData = {
|
||||
|
||||
@@ -23,7 +23,7 @@ type DebugData = {
|
||||
|
||||
function defaultExtras() {
|
||||
BugReporting.addFileSource('react_hierarchy.txt', () =>
|
||||
require('./dumpReactTree')(),
|
||||
require('./dumpReactTree').default(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,4 +137,4 @@ class BugReporting {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BugReporting;
|
||||
export default BugReporting;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
const getReactData = require('getReactData');
|
||||
const getReactData = require('getReactData').default;
|
||||
|
||||
const INDENTATION_SIZE = 2;
|
||||
const MAX_DEPTH = 2;
|
||||
@@ -148,4 +148,4 @@ function indent(size: number) {
|
||||
}
|
||||
*/
|
||||
|
||||
module.exports = dumpReactTree;
|
||||
export default dumpReactTree;
|
||||
|
||||
@@ -184,4 +184,4 @@ function copyWithSet(
|
||||
return copyWithSetImpl(obj, path, 0, value);
|
||||
}
|
||||
|
||||
module.exports = getData;
|
||||
export default getData;
|
||||
|
||||
@@ -34,7 +34,7 @@ if (global.RN$useAlwaysAvailableJSErrorHandling !== true) {
|
||||
}
|
||||
};
|
||||
|
||||
const ErrorUtils = require('../vendor/core/ErrorUtils');
|
||||
const ErrorUtils = require('../vendor/core/ErrorUtils').default;
|
||||
ErrorUtils.setGlobalHandler(handleError);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -110,4 +110,4 @@ const Vibration = {
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = Vibration;
|
||||
export default Vibration;
|
||||
|
||||
@@ -68,7 +68,7 @@ if (__DEV__) {
|
||||
}
|
||||
|
||||
// $FlowFixMe[method-unbinding]
|
||||
module.exports = (YellowBox: Class<React.Component<Props>> & {
|
||||
export default (YellowBox: Class<React.Component<Props>> & {
|
||||
ignoreWarnings($ReadOnlyArray<IgnorePattern>): void,
|
||||
install(): void,
|
||||
uninstall(): void,
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
'use strict';
|
||||
|
||||
const LogBox = require('../../LogBox/LogBox').default;
|
||||
const YellowBox = require('../YellowBoxDeprecated');
|
||||
const YellowBox = require('../YellowBoxDeprecated').default;
|
||||
|
||||
describe('YellowBox', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1540,7 +1540,7 @@ declare class BugReporting {
|
||||
): { remove: () => void, ... };
|
||||
static collectExtraData(): DebugData;
|
||||
}
|
||||
declare module.exports: BugReporting;
|
||||
declare export default typeof BugReporting;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -1552,13 +1552,13 @@ declare export default typeof NativeBugReporting;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/BugReporting/dumpReactTree.js 1`] = `
|
||||
"declare function dumpReactTree(): string;
|
||||
declare module.exports: dumpReactTree;
|
||||
declare export default typeof dumpReactTree;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/BugReporting/getReactData.js 1`] = `
|
||||
"declare function getData(element: Object): Object;
|
||||
declare module.exports: getData;
|
||||
declare export default typeof getData;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -9406,7 +9406,7 @@ exports[`public API should not change unintentionally Libraries/Vibration/Vibrat
|
||||
vibrate: (pattern: number | Array<number>, repeat: boolean) => void,
|
||||
cancel: () => void,
|
||||
};
|
||||
declare module.exports: Vibration;
|
||||
declare export default typeof Vibration;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -9510,7 +9510,7 @@ declare module.exports: WebSocketInterceptor;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/YellowBox/YellowBoxDeprecated.js 1`] = `
|
||||
"type Props = $ReadOnly<{}>;
|
||||
declare module.exports: Class<React.Component<Props>> & {
|
||||
declare export default Class<React.Component<Props>> & {
|
||||
ignoreWarnings($ReadOnlyArray<IgnorePattern>): void,
|
||||
install(): void,
|
||||
uninstall(): void,
|
||||
@@ -9526,7 +9526,7 @@ declare export default typeof rejectionTrackingOptions;
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/vendor/core/ErrorUtils.js 1`] = `
|
||||
"declare module.exports: ErrorUtilsT;
|
||||
"declare export default ErrorUtilsT;
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
@@ -22,4 +22,4 @@ import type {ErrorUtilsT} from '@react-native/js-polyfills/error-guard';
|
||||
* that use it aren't just using a global variable, so simply export the global
|
||||
* variable here. ErrorUtils is originally defined in a file named error-guard.js.
|
||||
*/
|
||||
module.exports = (global.ErrorUtils: ErrorUtilsT);
|
||||
export default (global.ErrorUtils: ErrorUtilsT);
|
||||
|
||||
Vendored
+2
-2
@@ -350,10 +350,10 @@ module.exports = {
|
||||
return require('./Libraries/UTFSequence').default;
|
||||
},
|
||||
get Vibration(): Vibration {
|
||||
return require('./Libraries/Vibration/Vibration');
|
||||
return require('./Libraries/Vibration/Vibration').default;
|
||||
},
|
||||
get YellowBox(): YellowBox {
|
||||
return require('./Libraries/YellowBox/YellowBoxDeprecated');
|
||||
return require('./Libraries/YellowBox/YellowBoxDeprecated').default;
|
||||
},
|
||||
|
||||
// Plugins
|
||||
|
||||
Vendored
+5
-2
@@ -430,8 +430,11 @@ jest
|
||||
return jest.requireActual('./mockNativeComponent');
|
||||
})
|
||||
.mock('../Libraries/Vibration/Vibration', () => ({
|
||||
vibrate: jest.fn(),
|
||||
cancel: jest.fn(),
|
||||
__esModule: true,
|
||||
default: {
|
||||
vibrate: jest.fn(),
|
||||
cancel: jest.fn(),
|
||||
},
|
||||
}))
|
||||
.mock('../Libraries/Components/View/ViewNativeComponent', () => {
|
||||
const React = require('react');
|
||||
|
||||
Reference in New Issue
Block a user