-
-
Notifications
You must be signed in to change notification settings - Fork 810
Expand file tree
/
Copy pathesbuild-shim.js
More file actions
58 lines (50 loc) · 1.01 KB
/
esbuild-shim.js
File metadata and controls
58 lines (50 loc) · 1.01 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
const global = (1, eval)("this")
global.global = global
global.globalThis = global
global.frames = global
global.self = global
const document = {
documentElement: {
style: {},
},
getElementById: () => undefined,
}
const navigator = {
platform: "win32",
}
const window = {
document,
location: {
href: "",
},
navigator,
}
global.navigator = navigator
global.window = window
global.document = document
// Polyfill URLSearchParams (which is a constructor). Just add a dummy "get" method that returns an empty string
global.URLSearchParams = class {
get() {
return ""
}
}
// Intl polyfill is required until v8go supports Intl
class NoopFormat {
format(arg0) {
return arg0 ? arg0.toString() : ""
}
}
global.Intl = {
NumberFormat: NoopFormat,
DateTimeFormat: NoopFormat,
}
class TextEncoder {
encode(str) {
const arr = new Uint8Array(str.length)
for (let i = 0; i < str.length; i++) {
arr[i] = str.charCodeAt(i)
}
return arr
}
}
global.TextEncoder = TextEncoder