Repository navigation
Expand file tree
/
Copy pathpolyfills.js
More file actions
285 lines (270 loc) 路 9.99 KB
/
Copy pathpolyfills.js
File metadata and controls
285 lines (270 loc) 路 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
const POLYFILL_PATTERNS = [
{ pattern: /Array\.prototype\.toSorted/, feature: "ArrayToSorted" },
{ pattern: /Array\.prototype\.findLast/, feature: "ArrayFindLast" },
{ pattern: /Array\.prototype\.findLastIndex/, feature: "ArrayFindLastIndex" },
{ pattern: /Array\.prototype\.at/, feature: "ArrayAt" },
{ pattern: /String\.prototype\.replaceAll/, feature: "StringReplaceAll" },
{ pattern: /String\.prototype\.matchAll/, feature: "StringMatchAll" },
{ pattern: /String\.prototype\.at/, feature: "StringAt" },
{ pattern: /Object\.hasOwn/, feature: "ObjectHasOwn" },
{ pattern: /Promise\.any/, feature: "PromiseAny" },
{ pattern: /RegExp\.prototype\.exec/, feature: "RegExpExec" },
{ pattern: /globalThis/, feature: "GlobalThis" },
];
const IMPORT_PATTERNS = [
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.array\.to-sorted['"]/,
feature: "ArrayToSorted",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.array\.find-last['"]/,
feature: "ArrayFindLast",
},
{
pattern:
/(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.array\.find-last-index['"]/,
feature: "ArrayFindLastIndex",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.array\.at['"]/,
feature: "ArrayAt",
},
{
pattern:
/(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.string\.replace-all['"]/,
feature: "StringReplaceAll",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.string\.match-all['"]/,
feature: "StringMatchAll",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.string\.at['"]/,
feature: "StringAt",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.object\.has-own['"]/,
feature: "ObjectHasOwn",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.promise\.any['"]/,
feature: "PromiseAny",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.regexp\.exec['"]/,
feature: "RegExpExec",
},
{
pattern: /(?:from\s+|require\s*\(\s*|import\s+)['"]core-js\/modules\/es\.global-this['"]/,
feature: "GlobalThis",
},
];
const FEATURE_TO_POLYFILL_MAP = {
"Array.from": [
/\bArray\.from\s*=/,
/['"]core-js\/modules\/es\.array\.from['"]/,
/['"]core-js\/actual\/array\/from['"]/,
],
"Array.of": [
/\bArray\.of\s*=/,
/['"]core-js\/modules\/es\.array\.of['"]/,
/['"]core-js\/actual\/array\/of['"]/,
],
"Array.prototype.find": [
/\bArray\.prototype\.find\s*=/,
/['"]core-js\/modules\/es\.array\.find['"]/,
],
"Array.prototype.findIndex": [
/\bArray\.prototype\.findIndex\s*=/,
/['"]core-js\/modules\/es\.array\.find-index['"]/,
],
"Object.assign": [
/\bObject\.assign\s*=/,
/['"]core-js\/modules\/es\.object\.assign['"]/,
/\bobject-assign\b/,
],
Promise: [/\bPromise\s*=/, /['"]core-js\/modules\/es\.promise['"]/, /es6-promise/],
"String.prototype.startsWith": [
/\bString\.prototype\.startsWith\s*=/,
/['"]core-js\/modules\/es\.string\.starts-with['"]/,
],
"String.prototype.endsWith": [
/\bString\.prototype\.endsWith\s*=/,
/['"]core-js\/modules\/es\.string\.ends-with['"]/,
],
"String.prototype.includes": [
/\bString\.prototype\.includes\s*=/,
/['"]core-js\/modules\/es\.string\.includes['"]/,
],
Symbol: [/\bSymbol\s*=/, /['"]core-js\/modules\/es\.symbol['"]/],
Map: [/\bMap\s*=/, /['"]core-js\/modules\/es\.map['"]/],
Set: [/\bSet\s*=/, /['"]core-js\/modules\/es\.set['"]/],
WeakMap: [/\bWeakMap\s*=/, /['"]core-js\/modules\/es\.weak-map['"]/],
WeakSet: [/\bWeakSet\s*=/, /['"]core-js\/modules\/es\.weak-set['"]/],
"Array.prototype.includes": [
/\bArray\.prototype\.includes\s*=/,
/['"]core-js\/modules\/es\.array\.includes['"]/,
],
"Object.values": [/\bObject\.values\s*=/, /['"]core-js\/modules\/es\.object\.values['"]/],
"Object.entries": [/\bObject\.entries\s*=/, /['"]core-js\/modules\/es\.object\.entries['"]/],
"Object.getOwnPropertyDescriptors": [
/\bObject\.getOwnPropertyDescriptors\s*=/,
/['"]core-js\/modules\/es\.object\.get-own-property-descriptors['"]/,
],
"String.prototype.padStart": [
/\bString\.prototype\.padStart\s*=/,
/['"]core-js\/modules\/es\.string\.pad-start['"]/,
],
"String.prototype.padEnd": [
/\bString\.prototype\.padEnd\s*=/,
/['"]core-js\/modules\/es\.string\.pad-end['"]/,
],
"Promise.prototype.finally": [
/\bPromise\.prototype\.finally\s*=/,
/['"]core-js\/modules\/es\.promise\.finally['"]/,
],
"Array.prototype.flat": [
/\bArray\.prototype\.flat\s*=/,
/['"]core-js\/modules\/es\.array\.flat['"]/,
],
"Array.prototype.flatMap": [
/\bArray\.prototype\.flatMap\s*=/,
/['"]core-js\/modules\/es\.array\.flat-map['"]/,
],
"Object.fromEntries": [
/\bObject\.fromEntries\s*=/,
/['"]core-js\/modules\/es\.object\.from-entries['"]/,
],
"String.prototype.trimStart": [
/\bString\.prototype\.trimStart\s*=/,
/['"]core-js\/modules\/es\.string\.trim-start['"]/,
],
"String.prototype.trimEnd": [
/\bString\.prototype\.trimEnd\s*=/,
/['"]core-js\/modules\/es\.string\.trim-end['"]/,
],
"Promise.allSettled": [
/\bPromise\.allSettled\s*=/,
/['"]core-js\/modules\/es\.promise\.all-settled['"]/,
],
"String.prototype.matchAll": [
/\bString\.prototype\.matchAll\s*=/,
/['"]core-js\/modules\/es\.string\.match-all['"]/,
],
globalThis: [/\bglobalThis\s*=/, /['"]core-js\/modules\/es\.global-this['"]/],
BigInt: [/\bBigInt\s*=/, /['"]core-js\/modules\/es\.bigint['"]/],
"Promise.any": [/\bPromise\.any\s*=/, /['"]core-js\/modules\/es\.promise\.any['"]/],
"String.prototype.replaceAll": [
/\bString\.prototype\.replaceAll\s*=/,
/['"]core-js\/modules\/es\.string\.replace-all['"]/,
],
"Array.prototype.at": [
/\bArray\.prototype\.at\s*=/,
/['"]core-js\/modules\/es\.array\.at['"]/,
/['"]core-js\/actual\/array\/at['"]/,
],
"String.prototype.at": [
/\bString\.prototype\.at\s*=/,
/['"]core-js\/modules\/es\.string\.at['"]/,
/['"]core-js\/actual\/string\/at['"]/,
],
"Array.prototype.findLast": [
/\bArray\.prototype\.findLast\s*=/,
/['"]core-js\/modules\/es\.array\.find-last['"]/,
],
"Array.prototype.findLastIndex": [
/\bArray\.prototype\.findLastIndex\s*=/,
/['"]core-js\/modules\/es\.array\.find-last-index['"]/,
],
"Array.prototype.toReversed": [
/\bArray\.prototype\.toReversed\s*=/,
/['"]core-js\/modules\/es\.array\.to-reversed['"]/,
/['"]core-js\/actual\/array\/to-reversed['"]/,
/['"]core-js\/stable\/array\/to-reversed['"]/,
/(?:__webpack_require__\([^)]*core-js[^)]*to-reversed|core[-_]js[^/\n]*toReversed)/,
/\bcore[-_]js[-_]modules[-_][^/\n]*to[-_]reversed/,
],
"Array.prototype.toSorted": [
/\bArray\.prototype\.toSorted\s*=/,
/['"]core-js\/modules\/es\.array\.to-sorted['"]/,
/['"]core-js\/actual\/array\/to-sorted['"]/,
/['"]core-js\/stable\/array\/to-sorted['"]/,
/__webpack_require__\([^)]*core-js\/modules\/es\.array\.to-sorted[^)]*\)/,
/\bcore[-_]js[-_]modules[-_][^/\n]*to[-_]sorted/,
],
"Array.prototype.toSpliced": [
/\bArray\.prototype\.toSpliced\s*=/,
/['"]core-js\/modules\/es\.array\.to-spliced['"]/,
/['"]core-js\/actual\/array\/to-spliced['"]/,
],
"Array.prototype.with": [
/\bArray\.prototype\.with\s*=/,
/['"]core-js\/modules\/es\.array\.with['"]/,
/['"]core-js\/actual\/array\/with['"]/,
/['"]core-js\/stable\/array\/with['"]/,
/(?:__webpack_require__\([^)]*core-js[^)]*array[^)]*with|core[-_]js[^/\n]*array[-_]with)/,
/\bcore[-_]js[-_]modules[-_][^/\n]*array[-_]with/,
],
"Object.hasOwn": [/\bObject\.hasOwn\s*=/, /['"]core-js\/modules\/es\.object\.has-own['"]/],
"String.prototype.isWellFormed": [
/\bString\.prototype\.isWellFormed\s*=/,
/['"]core-js\/modules\/es\.string\.is-well-formed['"]/,
],
"String.prototype.toWellFormed": [
/\bString\.prototype\.toWellFormed\s*=/,
/['"]core-js\/modules\/es\.string\.to-well-formed['"]/,
],
"Array.prototype.group": [
/\bArray\.prototype\.group\s*=/,
/['"]core-js\/modules\/es\.array\.group['"]/,
],
"Array.prototype.groupToMap": [
/\bArray\.prototype\.groupToMap\s*=/,
/['"]core-js\/modules\/es\.array\.group-to-map['"]/,
],
"Promise.try": [/\bPromise\.try\s*=/, /['"]core-js\/modules\/es\.promise\.try['"]/],
"Array.fromAsync": [
/\bArray\.fromAsync\s*=/,
/['"]core-js\/modules\/es\.array\.from-async['"]/,
/['"]core-js\/actual\/array\/from-async['"]/,
],
"Error.isError": [
/\bError\.isError\s*=/,
/['"]core-js\/modules\/es\.error\.is-error['"]/,
/['"]core-js\/actual\/error\/is-error['"]/,
],
"Intl.DurationFormat": [
/\bIntl\.DurationFormat\s*=/,
/['"]core-js\/modules\/es\.intl\.duration-format['"]/,
/['"]@formatjs\/intl-durationformat['"]/,
],
ArrayToSorted: [
/\bArray\.prototype\.toSorted\s*=/,
/['"]core-js\/modules\/es\.array\.to-sorted['"]/,
/['"]core-js\/actual\/array\/to-sorted['"]/,
/['"]core-js\/stable\/array\/to-sorted['"]/,
/__webpack_require__\([^)]*core-js\/modules\/es\.array\.to-sorted[^)]*\)/,
/\bcore[-_]js[-_]modules[-_]es[-_]array[-_]toSorted\b/,
],
ArrayToReversed: [
/\bArray\.prototype\.toReversed\s*=/,
/['"]core-js\/modules\/es\.array\.to-reversed['"]/,
/['"]core-js\/actual\/array\/to-reversed['"]/,
/['"]core-js\/stable\/array\/to-reversed['"]/,
/(?:__webpack_require__\([^)]*core-js[^)]*to-reversed|core[-_]js[^/\n]*toReversed)/,
/\bcore[-_]js[-_]modules[-_][^/\n]*to[-_]reversed/,
],
ArrayWith: [
/\bArray\.prototype\.with\s*=/,
/['"]core-js\/modules\/es\.array\.with['"]/,
/['"]core-js\/actual\/array\/with['"]/,
/['"]core-js\/stable\/array\/with['"]/,
/(?:__webpack_require__\([^)]*core-js[^)]*array[^)]*with|core[-_]js[-_]array[-_]with)/,
/\bcore[-_]js[-_]modules[-_][^/\n]*array[-_]with/,
],
};
module.exports = {
POLYFILL_PATTERNS,
IMPORT_PATTERNS,
FEATURE_TO_POLYFILL_MAP,
};