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
|
const options = @import("./options.zig");
usingnamespace @import("ast/base.zig");
usingnamespace @import("global.zig");
const std = @import("std");
pub const ProdSourceContent = @embedFile("./runtime.out.js");
pub const Runtime = struct {
pub fn sourceContent() string {
if (isDebug) {
var runtime_path = std.fs.path.join(std.heap.c_allocator, &[_]string{ std.fs.path.dirname(@src().file).?, "runtime.out.js" }) catch unreachable;
const file = std.fs.openFileAbsolute(runtime_path, .{}) catch unreachable;
defer file.close();
return file.readToEndAlloc(std.heap.c_allocator, (file.stat() catch unreachable).size) catch unreachable;
} else {
return ProdSourceContent;
}
}
pub var version_hash = @embedFile("./runtime.version");
pub fn version() string {
return version_hash;
}
pub const Features = struct {
react_fast_refresh: bool = false,
hot_module_reloading: bool = false,
hot_module_reloading_entry: bool = false,
keep_names_for_arrow_functions: bool = true,
};
pub const Names = struct {
pub const ActivateFunction = "activate";
};
// If you change this, remember to update "runtime.footer.js" and rebuild the runtime.js
pub const Imports = struct {
__name: ?Ref = null,
__toModule: ?Ref = null,
__commonJS: ?Ref = null,
__require: ?Ref = null,
__export: ?Ref = null,
__reExport: ?Ref = null,
__load: ?Ref = null,
load_from_bundle: ?Ref = null,
register: ?Ref = null,
lazy_export: ?Ref = null,
__HMRModule: ?Ref = null,
__HMRClient: ?Ref = null,
pub const all = [_][]const u8{
"__name",
"__toModule",
"__require",
"__commonJS",
"__export",
"__reExport",
"__load",
// require
"load_from_bundle",
//
"register",
"lazy_export",
"__HMRModule",
"__HMRClient",
};
pub const Name = "<RUNTIME";
pub const Iterator = struct {
i: usize = 0,
runtime_imports: *Imports,
const Entry = struct {
key: u16,
value: Ref,
};
pub fn next(this: *Iterator) ?Entry {
while (this.i < all.len) {
defer this.i += 1;
switch (this.i) {
0 => {
if (@field(this.runtime_imports, all[0])) |val| {
return Entry{ .key = 0, .value = val };
}
},
1 => {
if (@field(this.runtime_imports, all[1])) |val| {
return Entry{ .key = 1, .value = val };
}
},
2 => {
if (@field(this.runtime_imports, all[2])) |val| {
return Entry{ .key = 2, .value = val };
}
},
3 => {
if (@field(this.runtime_imports, all[3])) |val| {
return Entry{ .key = 3, .value = val };
}
},
4 => {
if (@field(this.runtime_imports, all[4])) |val| {
return Entry{ .key = 4, .value = val };
}
},
5 => {
if (@field(this.runtime_imports, all[5])) |val| {
return Entry{ .key = 5, .value = val };
}
},
6 => {
if (@field(this.runtime_imports, all[6])) |val| {
return Entry{ .key = 6, .value = val };
}
},
7 => {
if (@field(this.runtime_imports, all[7])) |val| {
return Entry{ .key = 7, .value = val };
}
},
8 => {
if (@field(this.runtime_imports, all[8])) |val| {
return Entry{ .key = 8, .value = val };
}
},
9 => {
if (@field(this.runtime_imports, all[9])) |val| {
return Entry{ .key = 9, .value = val };
}
},
10 => {
if (@field(this.runtime_imports, all[10])) |val| {
return Entry{ .key = 10, .value = val };
}
},
11 => {
if (@field(this.runtime_imports, all[11])) |val| {
return Entry{ .key = 11, .value = val };
}
},
else => {
return null;
},
}
}
return null;
}
};
pub fn iter(imports: *Imports) Iterator {
return Iterator{ .runtime_imports = imports };
}
pub fn contains(imports: *const Imports, comptime key: string) bool {
return @field(imports, key) != null;
}
pub fn hasAny(imports: *const Imports) bool {
inline for (all) |field| {
if (@field(imports, field) != null) {
return true;
}
}
return false;
}
pub fn put(imports: *Imports, comptime key: string, ref: Ref) void {
@field(imports, key) = ref;
}
pub fn at(
imports: *Imports,
comptime key: string,
) ?Ref {
return @field(imports, key);
}
pub fn get(
imports: *const Imports,
key: anytype,
) ?Ref {
return switch (key) {
0 => @field(imports, all[0]),
1 => @field(imports, all[1]),
2 => @field(imports, all[2]),
3 => @field(imports, all[3]),
4 => @field(imports, all[4]),
5 => @field(imports, all[5]),
6 => @field(imports, all[6]),
7 => @field(imports, all[7]),
8 => @field(imports, all[8]),
9 => @field(imports, all[9]),
10 => @field(imports, all[10]),
11 => @field(imports, all[11]),
else => null,
};
}
pub fn count(imports: *const Imports) usize {
var i: usize = 0;
inline for (all) |field| {
if (@field(imports, field) != null) {
i += 1;
}
}
return i;
}
};
};
|