Skip to content

Commit f2d96d8

Browse files
authored
Fix a regression that leads to larger bundle size (#2006)
* Fix a regression that leads to larger bundle size * [AUTOMATED]: Prettier Code Styling * remove type annotations
1 parent 9173c90 commit f2d96d8

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

config/tsconfig.base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"moduleResolution": "node",
2020
"sourceMap": true,
2121
"target": "es5",
22-
"downlevelIteration": true,
2322
"typeRoots": [
2423
"../node_modules/@types"
2524
]

packages/database/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"strict": false
5+
"strict": false,
6+
"downlevelIteration": true
67
},
78
"exclude": [
89
"dist/**/*"

packages/util/src/crypt.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,56 +85,77 @@ const byteArrayToString = function(bytes: number[]): string {
8585
return out.join('');
8686
};
8787

88+
interface Base64 {
89+
byteToCharMap_: { [key: number]: string } | null;
90+
charToByteMap_: { [key: string]: number } | null;
91+
byteToCharMapWebSafe_: { [key: number]: string } | null;
92+
charToByteMapWebSafe_: { [key: string]: number } | null;
93+
ENCODED_VALS_BASE: string;
94+
readonly ENCODED_VALS: string;
95+
readonly ENCODED_VALS_WEBSAFE: string;
96+
HAS_NATIVE_SUPPORT: boolean;
97+
encodeByteArray(input: number[] | Uint8Array, webSafe?: boolean): string;
98+
encodeString(input: string, webSafe?: boolean): string;
99+
decodeString(input: string, webSafe: boolean): string;
100+
decodeStringToByteArray(input: string, webSafe: boolean): number[];
101+
init_(): void;
102+
}
103+
104+
// We define it as an object literal instead of a class because a class compiled down to es5 can't
105+
// be treeshaked. https://github.com/rollup/rollup/issues/1691
88106
// Static lookup maps, lazily populated by init_()
89-
class Base64 {
107+
export const base64: Base64 = {
90108
/**
91109
* Maps bytes to characters.
92110
*/
93-
byteToCharMap_: { [key: number]: string } | null = null;
111+
byteToCharMap_: null,
94112

95113
/**
96114
* Maps characters to bytes.
97115
*/
98-
charToByteMap_: { [key: string]: number } | null = null;
116+
charToByteMap_: null,
99117

100118
/**
101119
* Maps bytes to websafe characters.
120+
* @private
102121
*/
103-
byteToCharMapWebSafe_: { [key: number]: string } | null = null;
122+
byteToCharMapWebSafe_: null,
104123

105124
/**
106125
* Maps websafe characters to bytes.
126+
* @private
107127
*/
108-
charToByteMapWebSafe_: { [key: string]: number } | null = null;
128+
charToByteMapWebSafe_: null,
109129

110130
/**
111-
* Our default alphabet shared between
131+
* Our default alphabet, shared between
112132
* ENCODED_VALS and ENCODED_VALS_WEBSAFE
113133
*/
114-
ENCODED_VALS_BASE: string =
115-
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789';
134+
ENCODED_VALS_BASE:
135+
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789',
116136

117137
/**
118138
* Our default alphabet. Value 64 (=) is special; it means "nothing."
119139
*/
120-
get ENCODED_VALS(): string {
140+
get ENCODED_VALS() {
121141
return this.ENCODED_VALS_BASE + '+/=';
122-
}
142+
},
123143

124144
/**
125145
* Our websafe alphabet.
126146
*/
127-
get ENCODED_VALS_WEBSAFE(): string {
147+
get ENCODED_VALS_WEBSAFE() {
128148
return this.ENCODED_VALS_BASE + '-_.';
129-
}
149+
},
130150

131151
/**
132152
* Whether this browser supports the atob and btoa functions. This extension
133153
* started at Mozilla but is now implemented by many browsers. We use the
134154
* ASSUME_* variables to avoid pulling in the full useragent detection library
135155
* but still allowing the standard per-browser compilations.
156+
*
136157
*/
137-
HAS_NATIVE_SUPPORT: boolean = typeof atob === 'function';
158+
HAS_NATIVE_SUPPORT: typeof atob === 'function',
138159

139160
/**
140161
* Base64-encode an array of bytes.
@@ -187,7 +208,7 @@ class Base64 {
187208
}
188209

189210
return output.join('');
190-
}
211+
},
191212

192213
/**
193214
* Base64-encode a string.
@@ -204,7 +225,7 @@ class Base64 {
204225
return btoa(input);
205226
}
206227
return this.encodeByteArray(stringToByteArray(input), webSafe);
207-
}
228+
},
208229

209230
/**
210231
* Base64-decode a string.
@@ -221,7 +242,7 @@ class Base64 {
221242
return atob(input);
222243
}
223244
return byteArrayToString(this.decodeStringToByteArray(input, webSafe));
224-
}
245+
},
225246

226247
/**
227248
* Base64-decode a string.
@@ -281,14 +302,14 @@ class Base64 {
281302
}
282303

283304
return output;
284-
}
305+
},
285306

286307
/**
287308
* Lazy static initialization function. Called before
288309
* accessing any of the static map variables.
289310
* @private
290311
*/
291-
init_(): void {
312+
init_() {
292313
if (!this.byteToCharMap_) {
293314
this.byteToCharMap_ = {};
294315
this.charToByteMap_ = {};
@@ -310,7 +331,7 @@ class Base64 {
310331
}
311332
}
312333
}
313-
}
334+
};
314335

315336
/**
316337
* URL-safe base64 encoding
@@ -337,5 +358,3 @@ export const base64Decode = function(str: string): string | null {
337358
}
338359
return null;
339360
};
340-
341-
export const base64 = new Base64();

0 commit comments

Comments
 (0)