Skip to content

Commit 98abf1b

Browse files
mischnicfacebook-github-bot
authored andcommitted
Complete missing Flow declarations in URL (#32566)
Summary: When transpiling flow with a Babel config like ``` { plugins: [['babel/plugin-transform-flow-strip-types', {requireDirective: true}]] } ``` all files containing Flow syntax need to have `flow` at the top of the file. ``` node_modules/react-native/Libraries/Blob/URL.js: A flow directive is required when using Flow annotations with the `requireDirective` option. 55 | _searchParams = []; 56 | > 57 | constructor(params: any) { | ^^^^^ 58 | if (typeof params === 'object') { 59 | Object.keys(params).forEach(key => this.append(key, params[key])); 60 | } ``` In URL, it was removed (mistakenly I think) by 6303850#diff-552f9731d5c9bc329105a5f4224319966395e59b5bb23202b756c5d152e0f007. Only the `strict-local´ part should have been removed, not the whole line. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - Complete missing Flow declarations in URL Pull Request resolved: #32566 Test Plan: See above Reviewed By: yungsters Differential Revision: D32295816 Pulled By: lunaleaps fbshipit-source-id: 1ad19a032e3399434f4e6a8eebbf37071a0f97be
1 parent 02e50a7 commit 98abf1b

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

Libraries/Blob/URL.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8+
* @flow
89
*/
910

1011
const Blob = require('./Blob');
@@ -18,6 +19,7 @@ if (
1819
typeof NativeBlobModule.getConstants().BLOB_URI_SCHEME === 'string'
1920
) {
2021
const constants = NativeBlobModule.getConstants();
22+
// $FlowFixMe[incompatible-type] asserted above
2123
BLOB_URL_PREFIX = constants.BLOB_URI_SCHEME + ':';
2224
if (typeof constants.BLOB_URI_HOST === 'string') {
2325
BLOB_URL_PREFIX += `//${constants.BLOB_URI_HOST}/`;
@@ -64,35 +66,36 @@ export class URLSearchParams {
6466
this._searchParams.push([key, value]);
6567
}
6668

67-
delete(name) {
69+
delete(name: string) {
6870
throw new Error('URLSearchParams.delete is not implemented');
6971
}
7072

71-
get(name) {
73+
get(name: string) {
7274
throw new Error('URLSearchParams.get is not implemented');
7375
}
7476

75-
getAll(name) {
77+
getAll(name: string) {
7678
throw new Error('URLSearchParams.getAll is not implemented');
7779
}
7880

79-
has(name) {
81+
has(name: string) {
8082
throw new Error('URLSearchParams.has is not implemented');
8183
}
8284

83-
set(name, value) {
85+
set(name: string, value: string) {
8486
throw new Error('URLSearchParams.set is not implemented');
8587
}
8688

8789
sort() {
8890
throw new Error('URLSearchParams.sort is not implemented');
8991
}
9092

93+
// $FlowFixMe[unsupported-syntax]
9194
[Symbol.iterator]() {
9295
return this._searchParams[Symbol.iterator]();
9396
}
9497

95-
toString() {
98+
toString(): string {
9699
if (this._searchParams.length === 0) {
97100
return '';
98101
}
@@ -111,9 +114,10 @@ function validateBaseUrl(url: string) {
111114
}
112115

113116
export class URL {
117+
_url: string;
114118
_searchParamsInstance = null;
115119

116-
static createObjectURL(blob: Blob) {
120+
static createObjectURL(blob: Blob): string {
117121
if (BLOB_URL_PREFIX === null) {
118122
throw new Error('Cannot create URL for blob!');
119123
}
@@ -124,7 +128,7 @@ export class URL {
124128
// Do nothing.
125129
}
126130

127-
constructor(url: string, base: string) {
131+
constructor(url: string, base: string | URL) {
128132
let baseUrl = null;
129133
if (!base || validateBaseUrl(url)) {
130134
this._url = url;
@@ -137,7 +141,7 @@ export class URL {
137141
if (!validateBaseUrl(baseUrl)) {
138142
throw new TypeError(`Invalid base URL: ${baseUrl}`);
139143
}
140-
} else if (typeof base === 'object') {
144+
} else {
141145
baseUrl = base.toString();
142146
}
143147
if (baseUrl.endsWith('/')) {
@@ -153,43 +157,43 @@ export class URL {
153157
}
154158
}
155159

156-
get hash() {
160+
get hash(): string {
157161
throw new Error('URL.hash is not implemented');
158162
}
159163

160-
get host() {
164+
get host(): string {
161165
throw new Error('URL.host is not implemented');
162166
}
163167

164-
get hostname() {
168+
get hostname(): string {
165169
throw new Error('URL.hostname is not implemented');
166170
}
167171

168172
get href(): string {
169173
return this.toString();
170174
}
171175

172-
get origin() {
176+
get origin(): string {
173177
throw new Error('URL.origin is not implemented');
174178
}
175179

176-
get password() {
180+
get password(): string {
177181
throw new Error('URL.password is not implemented');
178182
}
179183

180-
get pathname() {
184+
get pathname(): string {
181185
throw new Error('URL.pathname not implemented');
182186
}
183187

184-
get port() {
188+
get port(): string {
185189
throw new Error('URL.port is not implemented');
186190
}
187191

188-
get protocol() {
192+
get protocol(): string {
189193
throw new Error('URL.protocol is not implemented');
190194
}
191195

192-
get search() {
196+
get search(): string {
193197
throw new Error('URL.search is not implemented');
194198
}
195199

@@ -208,11 +212,12 @@ export class URL {
208212
if (this._searchParamsInstance === null) {
209213
return this._url;
210214
}
215+
const instanceString = this._searchParamsInstance.toString();
211216
const separator = this._url.indexOf('?') > -1 ? '&' : '?';
212-
return this._url + separator + this._searchParamsInstance.toString();
217+
return this._url + separator + instanceString;
213218
}
214219

215-
get username() {
220+
get username(): string {
216221
throw new Error('URL.username is not implemented');
217222
}
218223
}

0 commit comments

Comments
 (0)