Skip to content

Commit 9a70bc0

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrated files in Libraries/Blob to use export syntax. (#48761)
Summary: Pull Request resolved: #48761 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling. ## This diff - Updates files in Libraries/Blob 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 the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/Blob` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. Reviewed By: cortinico Differential Revision: D68326103 fbshipit-source-id: ff0b5e0125987ed44b34c35f39af1eefa9799d8f
1 parent 140b3b3 commit 9a70bc0

File tree

13 files changed

+35
-43
lines changed

13 files changed

+35
-43
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Blob {
5858
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob
5959
*/
6060
constructor(parts: Array<Blob | string> = [], options?: BlobOptions) {
61-
const BlobManager = require('./BlobManager');
61+
const BlobManager = require('./BlobManager').default;
6262
this.data = BlobManager.createFromParts(parts, options).data;
6363
}
6464

@@ -82,7 +82,7 @@ class Blob {
8282
}
8383

8484
slice(start?: number, end?: number, contentType: string = ''): Blob {
85-
const BlobManager = require('./BlobManager');
85+
const BlobManager = require('./BlobManager').default;
8686
let {offset, size} = this.data;
8787

8888
if (typeof start === 'number') {
@@ -132,7 +132,7 @@ class Blob {
132132
* `new Blob([blob, ...])` actually copies the data in memory.
133133
*/
134134
close() {
135-
const BlobManager = require('./BlobManager');
135+
const BlobManager = require('./BlobManager').default;
136136
BlobManager.release(this.data.blobId);
137137
this.data = null;
138138
}
@@ -155,4 +155,4 @@ class Blob {
155155
}
156156
}
157157

158-
module.exports = Blob;
158+
export default Blob;

packages/react-native/Libraries/Blob/BlobManager.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
* @format
99
*/
1010

11+
import typeof BlobT from './Blob';
1112
import type {BlobCollector, BlobData, BlobOptions} from './BlobTypes';
1213

1314
import NativeBlobModule from './NativeBlobModule';
1415
import invariant from 'invariant';
1516

16-
const Blob = require('./Blob');
17+
const Blob: BlobT = require('./Blob').default;
1718
const BlobRegistry = require('./BlobRegistry');
1819

1920
/*eslint-disable no-bitwise */
@@ -176,4 +177,4 @@ class BlobManager {
176177
}
177178
}
178179

179-
module.exports = BlobManager;
180+
export default BlobManager;

packages/react-native/Libraries/Blob/BlobRegistry.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const registry: Map<string, number> = new Map();
1212

13-
const register = (id: string) => {
13+
export const register = (id: string) => {
1414
const used = registry.get(id);
1515

1616
if (used != null) {
@@ -20,7 +20,7 @@ const register = (id: string) => {
2020
}
2121
};
2222

23-
const unregister = (id: string) => {
23+
export const unregister = (id: string) => {
2424
const used = registry.get(id);
2525

2626
if (used != null) {
@@ -32,12 +32,6 @@ const unregister = (id: string) => {
3232
}
3333
};
3434

35-
const has = (id: string): number | boolean => {
35+
export const has = (id: string): number | boolean => {
3636
return registry.get(id) || false;
3737
};
38-
39-
module.exports = {
40-
register,
41-
unregister,
42-
has,
43-
};

packages/react-native/Libraries/Blob/File.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ class File extends Blob {
5353
}
5454
}
5555

56-
module.exports = File;
56+
export default File;

packages/react-native/Libraries/Blob/FileReader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@ class FileReader extends (EventTarget(...READER_EVENTS): typeof EventTarget) {
183183
}
184184
}
185185

186-
module.exports = FileReader;
186+
export default FileReader;

packages/react-native/Libraries/Blob/__tests__/Blob-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jest.setMock('../../BatchedBridge/NativeModules', {
1717
},
1818
});
1919

20-
const Blob = require('../Blob');
20+
const Blob = require('../Blob').default;
2121

2222
describe('Blob', function () {
2323
it('should create empty blob', () => {

packages/react-native/Libraries/Blob/__tests__/BlobManager-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jest.setMock('../../BatchedBridge/NativeModules', {
1717
},
1818
});
1919

20-
const Blob = require('../Blob');
21-
const BlobManager = require('../BlobManager');
20+
const Blob = require('../Blob').default;
21+
const BlobManager = require('../BlobManager').default;
2222

2323
describe('BlobManager', function () {
2424
it('should create blob from parts', () => {

packages/react-native/Libraries/Blob/__tests__/File-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jest.setMock('../../BatchedBridge/NativeModules', {
1717
},
1818
});
1919

20-
const Blob = require('../Blob');
21-
const File = require('../File');
20+
const Blob = require('../Blob').default;
21+
const File = require('../File').default;
2222

2323
describe('babel 7 smoke test', function () {
2424
it('should be able to extend a class with native name', function () {

packages/react-native/Libraries/Blob/__tests__/FileReader-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jest.unmock('event-target-shim').setMock('../../BatchedBridge/NativeModules', {
1818
},
1919
});
2020

21-
const Blob = require('../Blob');
22-
const FileReader = require('../FileReader');
21+
const Blob = require('../Blob').default;
22+
const FileReader = require('../FileReader').default;
2323

2424
describe('FileReader', function () {
2525
it('should read blob as text', async () => {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ polyfillGlobal('Headers', () => require('../Network/fetch').Headers);
2626
polyfillGlobal('Request', () => require('../Network/fetch').Request);
2727
polyfillGlobal('Response', () => require('../Network/fetch').Response);
2828
polyfillGlobal('WebSocket', () => require('../WebSocket/WebSocket'));
29-
polyfillGlobal('Blob', () => require('../Blob/Blob'));
30-
polyfillGlobal('File', () => require('../Blob/File'));
31-
polyfillGlobal('FileReader', () => require('../Blob/FileReader'));
32-
polyfillGlobal('URL', () => require('../Blob/URL').URL); // flowlint-line untyped-import:off
33-
polyfillGlobal('URLSearchParams', () => require('../Blob/URL').URLSearchParams); // flowlint-line untyped-import:off
29+
polyfillGlobal('Blob', () => require('../Blob/Blob').default);
30+
polyfillGlobal('File', () => require('../Blob/File').default);
31+
polyfillGlobal('FileReader', () => require('../Blob/FileReader').default);
32+
polyfillGlobal('URL', () => require('../Blob/URL').URL);
33+
polyfillGlobal('URLSearchParams', () => require('../Blob/URL').URLSearchParams);
3434
polyfillGlobal(
3535
'AbortController',
3636
() => require('abort-controller/dist/abort-controller').AbortController, // flowlint-line untyped-import:off

packages/react-native/Libraries/Network/XMLHttpRequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
1515
import {type EventSubscription} from '../vendor/emitter/EventEmitter';
1616
import EventTarget from 'event-target-shim';
1717

18-
const BlobManager = require('../Blob/BlobManager');
18+
const BlobManager = require('../Blob/BlobManager').default;
1919
const GlobalPerformanceLogger = require('../Utilities/GlobalPerformanceLogger');
2020
const RCTNetworking = require('./RCTNetworking').default;
2121
const base64 = require('base64-js');

packages/react-native/Libraries/Network/convertRequestBody.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
'use strict';
1212

13-
const Blob = require('../Blob/Blob');
13+
import typeof BlobT from '../Blob/Blob';
14+
15+
const Blob: BlobT = require('../Blob/Blob').default;
1416
const binaryToBase64 = require('../Utilities/binaryToBase64');
1517
const FormData = require('./FormData');
1618

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ exports[`public API should not change unintentionally Libraries/Blob/Blob.js 1`]
13641364
get size(): number;
13651365
get type(): string;
13661366
}
1367-
declare module.exports: Blob;
1367+
declare export default typeof Blob;
13681368
"
13691369
`;
13701370

@@ -1382,19 +1382,14 @@ exports[`public API should not change unintentionally Libraries/Blob/BlobManager
13821382
static removeWebSocketHandler(socketId: number): void;
13831383
static sendOverSocket(blob: Blob, socketId: number): void;
13841384
}
1385-
declare module.exports: BlobManager;
1385+
declare export default typeof BlobManager;
13861386
"
13871387
`;
13881388

13891389
exports[`public API should not change unintentionally Libraries/Blob/BlobRegistry.js 1`] = `
1390-
"declare const register: (id: string) => void;
1391-
declare const unregister: (id: string) => void;
1392-
declare const has: (id: string) => number | boolean;
1393-
declare module.exports: {
1394-
register: register,
1395-
unregister: unregister,
1396-
has: has,
1397-
};
1390+
"declare export const register: (id: string) => void;
1391+
declare export const unregister: (id: string) => void;
1392+
declare export const has: (id: string) => number | boolean;
13981393
"
13991394
`;
14001395

@@ -1428,7 +1423,7 @@ exports[`public API should not change unintentionally Libraries/Blob/File.js 1`]
14281423
get name(): string;
14291424
get lastModified(): number;
14301425
}
1431-
declare module.exports: File;
1426+
declare export default typeof File;
14321427
"
14331428
`;
14341429

@@ -1457,7 +1452,7 @@ declare class FileReader extends EventTarget {
14571452
get error(): ?Error;
14581453
get result(): ?ReaderResult;
14591454
}
1460-
declare module.exports: FileReader;
1455+
declare export default typeof FileReader;
14611456
"
14621457
`;
14631458

0 commit comments

Comments
 (0)