@b4moss/hyogen-md 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/README_ja.md +130 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +2930 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +3109 -0
- package/package.json +70 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,2930 @@
|
|
|
1
|
+
import { parse as Ne } from "yaml";
|
|
2
|
+
const He = { file_not_found: "File not found: {path} (referenced from {from} via {via})", frontmatter_too_large: "Front matter exceeds size limit in {path} ({size} bytes, limit {limit})", duplicate_component_alias: 'Duplicate component alias "{alias}" in {path}', alias_collision: 'Component alias "{alias}" collides with an existing binding in {path}', forbidden_property_access: 'Forbidden property access "{property}" in {path}', parse_error: "Parse error in {path}: {message}", component_multiline_output: 'Component "{alias}" returned multiline output (single line required)', server_context_on_client: "serverContext is not allowed with renderClient", load_failed: "Failed to load {path}: {reason}" }, Pe = { circular_include: "Circular reference detected; skipped {path} (referenced from {from} via {via})", nest_limit_exceeded: "Nesting limit exceeded ({limit}); skipped block in {path}", extend_in_component: "extend is not allowed inside a component; skipped in {path}", prop_type_mismatch: 'Prop "{prop}" type mismatch in component "{component}"; expected {expected}, got {actual}', prop_missing: 'Required prop "{prop}" is missing for component "{component}"', prop_unknown: 'Unknown prop "{prop}" passed to component "{component}"; ignored', suspicious_context_value: 'Suspicious value in context key "{key}" ({reason})' }, Fe = { contains_html_script_tag: "contains HTML script tag", contains_event_handler: "contains inline event handler", contains_dangerous_scheme: "contains dangerous URL scheme", contains_embed_tag: "contains embeddable HTML tag", contains_meta_refresh: "contains meta refresh" }, J = {
|
|
3
|
+
errors: He,
|
|
4
|
+
warnings: Pe,
|
|
5
|
+
warningReasons: Fe
|
|
6
|
+
}, Ie = J.errors, ze = J.warnings;
|
|
7
|
+
function we(t, e) {
|
|
8
|
+
return t === void 0 ? "" : t.replace(/\{([^}]+)\}/g, (n, i) => {
|
|
9
|
+
if (e === void 0 || !(i in e))
|
|
10
|
+
return n;
|
|
11
|
+
const s = e[i];
|
|
12
|
+
return s == null ? "" : String(s);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function Ue(t, e) {
|
|
16
|
+
return we(Ie[t], e);
|
|
17
|
+
}
|
|
18
|
+
function O(t, e) {
|
|
19
|
+
return we(ze[t], e);
|
|
20
|
+
}
|
|
21
|
+
function u(t) {
|
|
22
|
+
const e = t.message ?? Ue(t.code, t.details), n = new Error(e);
|
|
23
|
+
return n.name = "HyogenError", n.code = t.code, n.message = e, n.path = t.path, n.details = t.details, n;
|
|
24
|
+
}
|
|
25
|
+
function _(...t) {
|
|
26
|
+
const e = {};
|
|
27
|
+
for (const n of t)
|
|
28
|
+
n != null && Object.assign(e, n);
|
|
29
|
+
return e;
|
|
30
|
+
}
|
|
31
|
+
class be {
|
|
32
|
+
components = /* @__PURE__ */ new Map();
|
|
33
|
+
register(e, n, i) {
|
|
34
|
+
if (this.components.has(e.alias))
|
|
35
|
+
throw u({
|
|
36
|
+
code: "duplicate_component_alias",
|
|
37
|
+
path: i ?? e.definedAt,
|
|
38
|
+
details: { alias: e.alias }
|
|
39
|
+
});
|
|
40
|
+
if (n.includes(e.alias))
|
|
41
|
+
throw u({
|
|
42
|
+
code: "alias_collision",
|
|
43
|
+
path: i ?? e.definedAt,
|
|
44
|
+
details: { alias: e.alias }
|
|
45
|
+
});
|
|
46
|
+
this.components.set(e.alias, e);
|
|
47
|
+
}
|
|
48
|
+
get(e) {
|
|
49
|
+
return this.components.get(e);
|
|
50
|
+
}
|
|
51
|
+
has(e) {
|
|
52
|
+
return this.components.has(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const le = 64 * 1024;
|
|
56
|
+
function H(t, e) {
|
|
57
|
+
if (!t.startsWith("---"))
|
|
58
|
+
return { context: {}, body: t };
|
|
59
|
+
const n = t.indexOf(`
|
|
60
|
+
`);
|
|
61
|
+
if (n === -1)
|
|
62
|
+
return { context: {}, body: t };
|
|
63
|
+
const i = t.indexOf(`
|
|
64
|
+
---`, n);
|
|
65
|
+
if (i === -1)
|
|
66
|
+
return { context: {}, body: t };
|
|
67
|
+
const s = t.slice(n + 1, i), r = Buffer.byteLength(s, "utf8");
|
|
68
|
+
if (r > le)
|
|
69
|
+
throw u({
|
|
70
|
+
code: "frontmatter_too_large",
|
|
71
|
+
path: e,
|
|
72
|
+
details: {
|
|
73
|
+
size: r,
|
|
74
|
+
limit: le
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (s.trim().length === 0)
|
|
78
|
+
throw u({
|
|
79
|
+
code: "parse_error",
|
|
80
|
+
path: e,
|
|
81
|
+
details: { message: "empty front matter" }
|
|
82
|
+
});
|
|
83
|
+
let o;
|
|
84
|
+
try {
|
|
85
|
+
const h = Ne(s);
|
|
86
|
+
if (h == null)
|
|
87
|
+
o = {};
|
|
88
|
+
else if (typeof h == "object" && !Array.isArray(h))
|
|
89
|
+
o = h;
|
|
90
|
+
else
|
|
91
|
+
throw new Error("front matter must be a YAML mapping");
|
|
92
|
+
} catch (h) {
|
|
93
|
+
throw u({
|
|
94
|
+
code: "parse_error",
|
|
95
|
+
path: e,
|
|
96
|
+
details: {
|
|
97
|
+
message: h instanceof Error ? h.message : "invalid YAML front matter"
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const a = i + 4;
|
|
102
|
+
let c = t.slice(a);
|
|
103
|
+
return c.startsWith(`
|
|
104
|
+
`) ? c = c.slice(1) : c.startsWith(`\r
|
|
105
|
+
`) && (c = c.slice(2)), {
|
|
106
|
+
context: o,
|
|
107
|
+
body: c,
|
|
108
|
+
rawFrontMatter: `---
|
|
109
|
+
${s}
|
|
110
|
+
---`
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const Ze = /* @__PURE__ */ new Set([
|
|
114
|
+
"string",
|
|
115
|
+
"number",
|
|
116
|
+
"boolean",
|
|
117
|
+
"object",
|
|
118
|
+
"array"
|
|
119
|
+
]);
|
|
120
|
+
function qe(t, e) {
|
|
121
|
+
const n = t.props;
|
|
122
|
+
if (n === void 0)
|
|
123
|
+
return {};
|
|
124
|
+
if (typeof n != "object" || n === null || Array.isArray(n))
|
|
125
|
+
throw u({
|
|
126
|
+
code: "parse_error",
|
|
127
|
+
path: e,
|
|
128
|
+
details: { message: "props must be a YAML mapping" }
|
|
129
|
+
});
|
|
130
|
+
const i = {};
|
|
131
|
+
for (const [s, r] of Object.entries(n)) {
|
|
132
|
+
if (typeof r != "object" || r === null || Array.isArray(r)) {
|
|
133
|
+
i[s] = {};
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const o = r, a = {};
|
|
137
|
+
if ("type" in o && o.type !== void 0) {
|
|
138
|
+
const c = String(o.type);
|
|
139
|
+
Ze.has(c) ? a.type = c : a.type = void 0;
|
|
140
|
+
}
|
|
141
|
+
"isRequired" in o && (a.isRequired = !!o.isRequired), "default" in o && (a.default = o.default), i[s] = a;
|
|
142
|
+
}
|
|
143
|
+
return i;
|
|
144
|
+
}
|
|
145
|
+
function Ve(t) {
|
|
146
|
+
if (t != null) {
|
|
147
|
+
if (typeof t == "string") return "string";
|
|
148
|
+
if (typeof t == "number") return "number";
|
|
149
|
+
if (typeof t == "boolean") return "boolean";
|
|
150
|
+
if (Array.isArray(t)) return "array";
|
|
151
|
+
if (typeof t == "object") return "object";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function Ke(t, e) {
|
|
155
|
+
return e === "array" ? Array.isArray(t) : e === "object" ? typeof t == "object" && t !== null && !Array.isArray(t) : typeof t === e;
|
|
156
|
+
}
|
|
157
|
+
function U(t, e) {
|
|
158
|
+
return {
|
|
159
|
+
code: t,
|
|
160
|
+
message: O(t, e),
|
|
161
|
+
details: e
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function Ye(t, e, n) {
|
|
165
|
+
const i = [], s = {}, r = new Set(Object.keys(e));
|
|
166
|
+
for (const [o, a] of Object.entries(e)) {
|
|
167
|
+
const c = Object.prototype.hasOwnProperty.call(t, o);
|
|
168
|
+
let h = c ? t[o] : void 0;
|
|
169
|
+
if (c || (a.default !== void 0 ? h = a.default : (a.isRequired && i.push(
|
|
170
|
+
U("prop_missing", {
|
|
171
|
+
prop: o,
|
|
172
|
+
component: n
|
|
173
|
+
})
|
|
174
|
+
), h = void 0)), c && h !== void 0 && h !== null) {
|
|
175
|
+
const l = a.type ?? Ve(h);
|
|
176
|
+
l && !Ke(h, l) && (i.push(
|
|
177
|
+
U("prop_type_mismatch", {
|
|
178
|
+
prop: o,
|
|
179
|
+
component: n,
|
|
180
|
+
expected: l,
|
|
181
|
+
actual: typeof h
|
|
182
|
+
})
|
|
183
|
+
), h = void 0);
|
|
184
|
+
}
|
|
185
|
+
s[o] = h;
|
|
186
|
+
}
|
|
187
|
+
for (const o of Object.keys(t))
|
|
188
|
+
r.has(o) || (Object.keys(e).length > 0 ? i.push(
|
|
189
|
+
U("prop_unknown", {
|
|
190
|
+
prop: o,
|
|
191
|
+
component: n
|
|
192
|
+
})
|
|
193
|
+
) : s[o] = t[o]);
|
|
194
|
+
return { values: s, warnings: i };
|
|
195
|
+
}
|
|
196
|
+
function ye(t) {
|
|
197
|
+
return /^https?:\/\//i.test(t);
|
|
198
|
+
}
|
|
199
|
+
function Ge(t) {
|
|
200
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
201
|
+
}
|
|
202
|
+
var Z, he;
|
|
203
|
+
function Je() {
|
|
204
|
+
if (he) return Z;
|
|
205
|
+
he = 1;
|
|
206
|
+
function t(s) {
|
|
207
|
+
if (typeof s != "string")
|
|
208
|
+
throw new TypeError("Path must be a string. Received " + JSON.stringify(s));
|
|
209
|
+
}
|
|
210
|
+
function e(s, r) {
|
|
211
|
+
for (var o = "", a = 0, c = -1, h = 0, l, d = 0; d <= s.length; ++d) {
|
|
212
|
+
if (d < s.length)
|
|
213
|
+
l = s.charCodeAt(d);
|
|
214
|
+
else {
|
|
215
|
+
if (l === 47)
|
|
216
|
+
break;
|
|
217
|
+
l = 47;
|
|
218
|
+
}
|
|
219
|
+
if (l === 47) {
|
|
220
|
+
if (!(c === d - 1 || h === 1)) if (c !== d - 1 && h === 2) {
|
|
221
|
+
if (o.length < 2 || a !== 2 || o.charCodeAt(o.length - 1) !== 46 || o.charCodeAt(o.length - 2) !== 46) {
|
|
222
|
+
if (o.length > 2) {
|
|
223
|
+
var f = o.lastIndexOf("/");
|
|
224
|
+
if (f !== o.length - 1) {
|
|
225
|
+
f === -1 ? (o = "", a = 0) : (o = o.slice(0, f), a = o.length - 1 - o.lastIndexOf("/")), c = d, h = 0;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
} else if (o.length === 2 || o.length === 1) {
|
|
229
|
+
o = "", a = 0, c = d, h = 0;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
r && (o.length > 0 ? o += "/.." : o = "..", a = 2);
|
|
234
|
+
} else
|
|
235
|
+
o.length > 0 ? o += "/" + s.slice(c + 1, d) : o = s.slice(c + 1, d), a = d - c - 1;
|
|
236
|
+
c = d, h = 0;
|
|
237
|
+
} else l === 46 && h !== -1 ? ++h : h = -1;
|
|
238
|
+
}
|
|
239
|
+
return o;
|
|
240
|
+
}
|
|
241
|
+
function n(s, r) {
|
|
242
|
+
var o = r.dir || r.root, a = r.base || (r.name || "") + (r.ext || "");
|
|
243
|
+
return o ? o === r.root ? o + a : o + s + a : a;
|
|
244
|
+
}
|
|
245
|
+
var i = {
|
|
246
|
+
// path.resolve([from ...], to)
|
|
247
|
+
resolve: function() {
|
|
248
|
+
for (var r = "", o = !1, a, c = arguments.length - 1; c >= -1 && !o; c--) {
|
|
249
|
+
var h;
|
|
250
|
+
c >= 0 ? h = arguments[c] : (a === void 0 && (a = process.cwd()), h = a), t(h), h.length !== 0 && (r = h + "/" + r, o = h.charCodeAt(0) === 47);
|
|
251
|
+
}
|
|
252
|
+
return r = e(r, !o), o ? r.length > 0 ? "/" + r : "/" : r.length > 0 ? r : ".";
|
|
253
|
+
},
|
|
254
|
+
normalize: function(r) {
|
|
255
|
+
if (t(r), r.length === 0) return ".";
|
|
256
|
+
var o = r.charCodeAt(0) === 47, a = r.charCodeAt(r.length - 1) === 47;
|
|
257
|
+
return r = e(r, !o), r.length === 0 && !o && (r = "."), r.length > 0 && a && (r += "/"), o ? "/" + r : r;
|
|
258
|
+
},
|
|
259
|
+
isAbsolute: function(r) {
|
|
260
|
+
return t(r), r.length > 0 && r.charCodeAt(0) === 47;
|
|
261
|
+
},
|
|
262
|
+
join: function() {
|
|
263
|
+
if (arguments.length === 0)
|
|
264
|
+
return ".";
|
|
265
|
+
for (var r, o = 0; o < arguments.length; ++o) {
|
|
266
|
+
var a = arguments[o];
|
|
267
|
+
t(a), a.length > 0 && (r === void 0 ? r = a : r += "/" + a);
|
|
268
|
+
}
|
|
269
|
+
return r === void 0 ? "." : i.normalize(r);
|
|
270
|
+
},
|
|
271
|
+
relative: function(r, o) {
|
|
272
|
+
if (t(r), t(o), r === o || (r = i.resolve(r), o = i.resolve(o), r === o)) return "";
|
|
273
|
+
for (var a = 1; a < r.length && r.charCodeAt(a) === 47; ++a)
|
|
274
|
+
;
|
|
275
|
+
for (var c = r.length, h = c - a, l = 1; l < o.length && o.charCodeAt(l) === 47; ++l)
|
|
276
|
+
;
|
|
277
|
+
for (var d = o.length, f = d - l, g = h < f ? h : f, m = -1, p = 0; p <= g; ++p) {
|
|
278
|
+
if (p === g) {
|
|
279
|
+
if (f > g) {
|
|
280
|
+
if (o.charCodeAt(l + p) === 47)
|
|
281
|
+
return o.slice(l + p + 1);
|
|
282
|
+
if (p === 0)
|
|
283
|
+
return o.slice(l + p);
|
|
284
|
+
} else h > g && (r.charCodeAt(a + p) === 47 ? m = p : p === 0 && (m = 0));
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
var A = r.charCodeAt(a + p), L = o.charCodeAt(l + p);
|
|
288
|
+
if (A !== L)
|
|
289
|
+
break;
|
|
290
|
+
A === 47 && (m = p);
|
|
291
|
+
}
|
|
292
|
+
var b = "";
|
|
293
|
+
for (p = a + m + 1; p <= c; ++p)
|
|
294
|
+
(p === c || r.charCodeAt(p) === 47) && (b.length === 0 ? b += ".." : b += "/..");
|
|
295
|
+
return b.length > 0 ? b + o.slice(l + m) : (l += m, o.charCodeAt(l) === 47 && ++l, o.slice(l));
|
|
296
|
+
},
|
|
297
|
+
_makeLong: function(r) {
|
|
298
|
+
return r;
|
|
299
|
+
},
|
|
300
|
+
dirname: function(r) {
|
|
301
|
+
if (t(r), r.length === 0) return ".";
|
|
302
|
+
for (var o = r.charCodeAt(0), a = o === 47, c = -1, h = !0, l = r.length - 1; l >= 1; --l)
|
|
303
|
+
if (o = r.charCodeAt(l), o === 47) {
|
|
304
|
+
if (!h) {
|
|
305
|
+
c = l;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
} else
|
|
309
|
+
h = !1;
|
|
310
|
+
return c === -1 ? a ? "/" : "." : a && c === 1 ? "//" : r.slice(0, c);
|
|
311
|
+
},
|
|
312
|
+
basename: function(r, o) {
|
|
313
|
+
if (o !== void 0 && typeof o != "string") throw new TypeError('"ext" argument must be a string');
|
|
314
|
+
t(r);
|
|
315
|
+
var a = 0, c = -1, h = !0, l;
|
|
316
|
+
if (o !== void 0 && o.length > 0 && o.length <= r.length) {
|
|
317
|
+
if (o.length === r.length && o === r) return "";
|
|
318
|
+
var d = o.length - 1, f = -1;
|
|
319
|
+
for (l = r.length - 1; l >= 0; --l) {
|
|
320
|
+
var g = r.charCodeAt(l);
|
|
321
|
+
if (g === 47) {
|
|
322
|
+
if (!h) {
|
|
323
|
+
a = l + 1;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
} else
|
|
327
|
+
f === -1 && (h = !1, f = l + 1), d >= 0 && (g === o.charCodeAt(d) ? --d === -1 && (c = l) : (d = -1, c = f));
|
|
328
|
+
}
|
|
329
|
+
return a === c ? c = f : c === -1 && (c = r.length), r.slice(a, c);
|
|
330
|
+
} else {
|
|
331
|
+
for (l = r.length - 1; l >= 0; --l)
|
|
332
|
+
if (r.charCodeAt(l) === 47) {
|
|
333
|
+
if (!h) {
|
|
334
|
+
a = l + 1;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
} else c === -1 && (h = !1, c = l + 1);
|
|
338
|
+
return c === -1 ? "" : r.slice(a, c);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
extname: function(r) {
|
|
342
|
+
t(r);
|
|
343
|
+
for (var o = -1, a = 0, c = -1, h = !0, l = 0, d = r.length - 1; d >= 0; --d) {
|
|
344
|
+
var f = r.charCodeAt(d);
|
|
345
|
+
if (f === 47) {
|
|
346
|
+
if (!h) {
|
|
347
|
+
a = d + 1;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
c === -1 && (h = !1, c = d + 1), f === 46 ? o === -1 ? o = d : l !== 1 && (l = 1) : o !== -1 && (l = -1);
|
|
353
|
+
}
|
|
354
|
+
return o === -1 || c === -1 || // We saw a non-dot character immediately before the dot
|
|
355
|
+
l === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
356
|
+
l === 1 && o === c - 1 && o === a + 1 ? "" : r.slice(o, c);
|
|
357
|
+
},
|
|
358
|
+
format: function(r) {
|
|
359
|
+
if (r === null || typeof r != "object")
|
|
360
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof r);
|
|
361
|
+
return n("/", r);
|
|
362
|
+
},
|
|
363
|
+
parse: function(r) {
|
|
364
|
+
t(r);
|
|
365
|
+
var o = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
366
|
+
if (r.length === 0) return o;
|
|
367
|
+
var a = r.charCodeAt(0), c = a === 47, h;
|
|
368
|
+
c ? (o.root = "/", h = 1) : h = 0;
|
|
369
|
+
for (var l = -1, d = 0, f = -1, g = !0, m = r.length - 1, p = 0; m >= h; --m) {
|
|
370
|
+
if (a = r.charCodeAt(m), a === 47) {
|
|
371
|
+
if (!g) {
|
|
372
|
+
d = m + 1;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
f === -1 && (g = !1, f = m + 1), a === 46 ? l === -1 ? l = m : p !== 1 && (p = 1) : l !== -1 && (p = -1);
|
|
378
|
+
}
|
|
379
|
+
return l === -1 || f === -1 || // We saw a non-dot character immediately before the dot
|
|
380
|
+
p === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
381
|
+
p === 1 && l === f - 1 && l === d + 1 ? f !== -1 && (d === 0 && c ? o.base = o.name = r.slice(1, f) : o.base = o.name = r.slice(d, f)) : (d === 0 && c ? (o.name = r.slice(1, l), o.base = r.slice(1, f)) : (o.name = r.slice(d, l), o.base = r.slice(d, f)), o.ext = r.slice(l, f)), d > 0 ? o.dir = r.slice(0, d - 1) : c && (o.dir = "/"), o;
|
|
382
|
+
},
|
|
383
|
+
sep: "/",
|
|
384
|
+
delimiter: ":",
|
|
385
|
+
win32: null,
|
|
386
|
+
posix: null
|
|
387
|
+
};
|
|
388
|
+
return i.posix = i, Z = i, Z;
|
|
389
|
+
}
|
|
390
|
+
var Xe = Je();
|
|
391
|
+
const y = /* @__PURE__ */ Ge(Xe);
|
|
392
|
+
function Qe(t, e) {
|
|
393
|
+
const n = y.relative(e, t);
|
|
394
|
+
return n === "" || !n.startsWith("..") && !y.isAbsolute(n);
|
|
395
|
+
}
|
|
396
|
+
function et(t, e, n) {
|
|
397
|
+
const i = y.resolve(e), s = y.resolve(t);
|
|
398
|
+
if (!Qe(s, i))
|
|
399
|
+
throw u({
|
|
400
|
+
code: "parse_error",
|
|
401
|
+
path: n,
|
|
402
|
+
details: { message: "path resolves outside root directory" }
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function ve(t, e = {}) {
|
|
406
|
+
const { rootDir: n, fromPath: i, documentPath: s, constrainToRoot: r = !1, hyogenPath: o = !1 } = e;
|
|
407
|
+
if (t.length === 0)
|
|
408
|
+
throw u({
|
|
409
|
+
code: "parse_error",
|
|
410
|
+
path: s,
|
|
411
|
+
details: { message: "empty template path" }
|
|
412
|
+
});
|
|
413
|
+
let a;
|
|
414
|
+
if (t.startsWith("/"))
|
|
415
|
+
if (n)
|
|
416
|
+
a = y.resolve(n, t.slice(1));
|
|
417
|
+
else {
|
|
418
|
+
if (o)
|
|
419
|
+
throw u({
|
|
420
|
+
code: "parse_error",
|
|
421
|
+
path: s,
|
|
422
|
+
details: { message: "root-relative paths require a doc root" }
|
|
423
|
+
});
|
|
424
|
+
if (y.isAbsolute(t))
|
|
425
|
+
a = y.resolve(t);
|
|
426
|
+
else
|
|
427
|
+
throw u({
|
|
428
|
+
code: "parse_error",
|
|
429
|
+
path: s,
|
|
430
|
+
details: { message: "root-relative paths require a doc root" }
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
else if (t.startsWith("./") || t.startsWith("../"))
|
|
434
|
+
if (i)
|
|
435
|
+
a = y.resolve(y.dirname(i), t);
|
|
436
|
+
else if (n)
|
|
437
|
+
a = y.resolve(n, t);
|
|
438
|
+
else
|
|
439
|
+
throw u({
|
|
440
|
+
code: "parse_error",
|
|
441
|
+
path: s,
|
|
442
|
+
details: { message: "root is required for relative template paths" }
|
|
443
|
+
});
|
|
444
|
+
else if (y.isAbsolute(t))
|
|
445
|
+
a = y.resolve(t);
|
|
446
|
+
else if (n)
|
|
447
|
+
a = y.resolve(n, t);
|
|
448
|
+
else
|
|
449
|
+
throw u({
|
|
450
|
+
code: "parse_error",
|
|
451
|
+
path: s,
|
|
452
|
+
details: { message: "root is required for relative template paths" }
|
|
453
|
+
});
|
|
454
|
+
return n && r && et(a, n, s), a;
|
|
455
|
+
}
|
|
456
|
+
async function tt(t) {
|
|
457
|
+
const e = t.registry.get(t.alias);
|
|
458
|
+
if (!e)
|
|
459
|
+
throw u({
|
|
460
|
+
code: "parse_error",
|
|
461
|
+
path: t.path,
|
|
462
|
+
details: {
|
|
463
|
+
message: `unregistered component: ${t.alias}`
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
const n = ye(e.componentPath) ? e.componentPath : ve(e.componentPath, {
|
|
467
|
+
rootDir: t.rootDir,
|
|
468
|
+
fromPath: e.definedAt,
|
|
469
|
+
documentPath: t.path,
|
|
470
|
+
constrainToRoot: t.constrainToRoot,
|
|
471
|
+
hyogenPath: !0
|
|
472
|
+
}), i = await t.loader(n), { context: s, body: r } = H(i, n), o = qe(s, n), { values: a, warnings: c } = Ye(
|
|
473
|
+
t.props,
|
|
474
|
+
o,
|
|
475
|
+
t.alias
|
|
476
|
+
);
|
|
477
|
+
t.warnings.push(...c);
|
|
478
|
+
const { props: h, ...l } = s, d = _(
|
|
479
|
+
t.parentContext,
|
|
480
|
+
l,
|
|
481
|
+
a
|
|
482
|
+
), g = (await ae(r, {
|
|
483
|
+
context: d,
|
|
484
|
+
loader: t.loader,
|
|
485
|
+
root: t.rootDir,
|
|
486
|
+
path: n,
|
|
487
|
+
registry: t.registry,
|
|
488
|
+
warnings: t.warnings,
|
|
489
|
+
visitStack: t.visitStack,
|
|
490
|
+
inComponent: !0,
|
|
491
|
+
preserveFrontMatter: !1,
|
|
492
|
+
preserveHgComments: t.preserveHgComments,
|
|
493
|
+
constrainToRoot: t.constrainToRoot
|
|
494
|
+
})).trim();
|
|
495
|
+
if (g.includes(`
|
|
496
|
+
`))
|
|
497
|
+
throw u({
|
|
498
|
+
code: "component_multiline_output",
|
|
499
|
+
path: n,
|
|
500
|
+
details: { alias: t.alias }
|
|
501
|
+
});
|
|
502
|
+
return g;
|
|
503
|
+
}
|
|
504
|
+
const nt = /* @__PURE__ */ new Set([
|
|
505
|
+
"__proto__",
|
|
506
|
+
"prototype",
|
|
507
|
+
"constructor",
|
|
508
|
+
"__defineGetter__"
|
|
509
|
+
]);
|
|
510
|
+
function it(t) {
|
|
511
|
+
return nt.has(t);
|
|
512
|
+
}
|
|
513
|
+
function de(t, e) {
|
|
514
|
+
if (it(t))
|
|
515
|
+
throw u({
|
|
516
|
+
code: "forbidden_property_access",
|
|
517
|
+
path: e,
|
|
518
|
+
details: { property: t }
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function M(t) {
|
|
522
|
+
return !t;
|
|
523
|
+
}
|
|
524
|
+
function rt(t, e) {
|
|
525
|
+
if (t != null && typeof t == "object")
|
|
526
|
+
return t[e];
|
|
527
|
+
}
|
|
528
|
+
function st(t, e, n) {
|
|
529
|
+
switch (t) {
|
|
530
|
+
case "+":
|
|
531
|
+
return e + n;
|
|
532
|
+
case "-":
|
|
533
|
+
return e - n;
|
|
534
|
+
case "*":
|
|
535
|
+
return e * n;
|
|
536
|
+
case "/":
|
|
537
|
+
return e / n;
|
|
538
|
+
case "===":
|
|
539
|
+
return e === n;
|
|
540
|
+
case "!==":
|
|
541
|
+
return e !== n;
|
|
542
|
+
case "==":
|
|
543
|
+
return e == n;
|
|
544
|
+
case "!=":
|
|
545
|
+
return e != n;
|
|
546
|
+
case ">=":
|
|
547
|
+
return e >= n;
|
|
548
|
+
case "<=":
|
|
549
|
+
return e <= n;
|
|
550
|
+
case ">":
|
|
551
|
+
return e > n;
|
|
552
|
+
case "<":
|
|
553
|
+
return e < n;
|
|
554
|
+
case "&&":
|
|
555
|
+
return M(e) ? e : n;
|
|
556
|
+
case "||":
|
|
557
|
+
return M(e) ? n : e;
|
|
558
|
+
default:
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async function w(t, e) {
|
|
563
|
+
const { context: n, path: i } = e;
|
|
564
|
+
switch (t.type) {
|
|
565
|
+
case "literal":
|
|
566
|
+
return t.value;
|
|
567
|
+
case "identifier":
|
|
568
|
+
return de(t.name, i), n[t.name];
|
|
569
|
+
case "member": {
|
|
570
|
+
de(t.property, i);
|
|
571
|
+
const s = await w(t.object, e);
|
|
572
|
+
return rt(s, t.property);
|
|
573
|
+
}
|
|
574
|
+
case "default": {
|
|
575
|
+
const s = await w(t.left, e);
|
|
576
|
+
return M(s) ? w(t.right, e) : s;
|
|
577
|
+
}
|
|
578
|
+
case "unary": {
|
|
579
|
+
const s = await w(t.operand, e);
|
|
580
|
+
return t.op === "!" ? !s : void 0;
|
|
581
|
+
}
|
|
582
|
+
case "binary": {
|
|
583
|
+
if (t.op === "&&") {
|
|
584
|
+
const o = await w(t.left, e);
|
|
585
|
+
return M(o) ? o : w(t.right, e);
|
|
586
|
+
}
|
|
587
|
+
if (t.op === "||") {
|
|
588
|
+
const o = await w(t.left, e);
|
|
589
|
+
return M(o) ? w(t.right, e) : o;
|
|
590
|
+
}
|
|
591
|
+
const s = await w(t.left, e), r = await w(t.right, e);
|
|
592
|
+
return st(t.op, s, r);
|
|
593
|
+
}
|
|
594
|
+
case "call": {
|
|
595
|
+
if (!e.registry || !e.loader || !e.visitStack)
|
|
596
|
+
throw u({
|
|
597
|
+
code: "parse_error",
|
|
598
|
+
path: i,
|
|
599
|
+
details: {
|
|
600
|
+
message: `function calls are not allowed: ${t.callee}()`
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
if (!e.registry.has(t.callee))
|
|
604
|
+
throw u({
|
|
605
|
+
code: "parse_error",
|
|
606
|
+
path: i,
|
|
607
|
+
details: {
|
|
608
|
+
message: `unregistered component: ${t.callee}`
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
const s = {};
|
|
612
|
+
for (const [r, o] of Object.entries(t.args))
|
|
613
|
+
s[r] = await w(o, e);
|
|
614
|
+
return tt({
|
|
615
|
+
alias: t.callee,
|
|
616
|
+
props: s,
|
|
617
|
+
parentContext: e.parentContext ?? n,
|
|
618
|
+
registry: e.registry,
|
|
619
|
+
loader: e.loader,
|
|
620
|
+
rootDir: e.rootDir,
|
|
621
|
+
path: i,
|
|
622
|
+
warnings: e.warnings ?? [],
|
|
623
|
+
visitStack: e.visitStack,
|
|
624
|
+
preserveHgComments: e.preserveHgComments,
|
|
625
|
+
constrainToRoot: e.constrainToRoot
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
case "method": {
|
|
629
|
+
if (t.method !== "toLocaleString")
|
|
630
|
+
throw u({
|
|
631
|
+
code: "parse_error",
|
|
632
|
+
path: i,
|
|
633
|
+
details: { message: `unsupported method: ${t.method}()` }
|
|
634
|
+
});
|
|
635
|
+
const s = await w(t.object, e);
|
|
636
|
+
return s == null || typeof s.toLocaleString != "function" ? void 0 : s.toLocaleString(
|
|
637
|
+
...t.args
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
case "ternary": {
|
|
641
|
+
const s = await w(t.condition, e);
|
|
642
|
+
return M(s) ? w(t.alternate, e) : w(t.consequent, e);
|
|
643
|
+
}
|
|
644
|
+
case "template": {
|
|
645
|
+
let s = "";
|
|
646
|
+
for (const r of t.parts)
|
|
647
|
+
if (typeof r == "string")
|
|
648
|
+
s += r;
|
|
649
|
+
else {
|
|
650
|
+
const o = await w(r, e);
|
|
651
|
+
o != null && (s += String(o));
|
|
652
|
+
}
|
|
653
|
+
return s;
|
|
654
|
+
}
|
|
655
|
+
default:
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function q(t) {
|
|
660
|
+
return /[A-Za-z_$]/.test(t);
|
|
661
|
+
}
|
|
662
|
+
function ot(t) {
|
|
663
|
+
return /[A-Za-z0-9_$]/.test(t);
|
|
664
|
+
}
|
|
665
|
+
function C(t, e, n = {}) {
|
|
666
|
+
const i = t.trim();
|
|
667
|
+
if (i.length === 0)
|
|
668
|
+
throw x(e, "empty expression");
|
|
669
|
+
const s = new at(i, e, n), r = s.parseExpression();
|
|
670
|
+
if (s.skipWhitespace(), s.hasMore())
|
|
671
|
+
throw x(e, `unexpected token at position ${s.position}`);
|
|
672
|
+
return r;
|
|
673
|
+
}
|
|
674
|
+
function x(t, e) {
|
|
675
|
+
throw u({
|
|
676
|
+
code: "parse_error",
|
|
677
|
+
path: t,
|
|
678
|
+
details: { message: e }
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
class at {
|
|
682
|
+
constructor(e, n, i = {}) {
|
|
683
|
+
this.input = e, this.path = n, this.allowCalls = i.allowCalls !== !1;
|
|
684
|
+
}
|
|
685
|
+
input;
|
|
686
|
+
path;
|
|
687
|
+
index = 0;
|
|
688
|
+
allowCalls;
|
|
689
|
+
get position() {
|
|
690
|
+
return this.index;
|
|
691
|
+
}
|
|
692
|
+
hasMore() {
|
|
693
|
+
return this.skipWhitespace(), this.index < this.input.length;
|
|
694
|
+
}
|
|
695
|
+
skipWhitespace() {
|
|
696
|
+
for (; this.index < this.input.length && /\s/.test(this.input[this.index]); )
|
|
697
|
+
this.index++;
|
|
698
|
+
}
|
|
699
|
+
parseExpression() {
|
|
700
|
+
return this.parsePipe();
|
|
701
|
+
}
|
|
702
|
+
parsePipe() {
|
|
703
|
+
let e = this.parseTernary();
|
|
704
|
+
for (; this.skipWhitespace(), !(this.peek() !== "|" || this.input[this.index + 1] === "|"); ) {
|
|
705
|
+
this.index++;
|
|
706
|
+
const n = this.parseTernary();
|
|
707
|
+
e = { type: "default", left: e, right: n };
|
|
708
|
+
}
|
|
709
|
+
return e;
|
|
710
|
+
}
|
|
711
|
+
parseTernary() {
|
|
712
|
+
const e = this.parseLogicalOr();
|
|
713
|
+
if (this.skipWhitespace(), this.peek() !== "?")
|
|
714
|
+
return e;
|
|
715
|
+
this.index++;
|
|
716
|
+
const n = this.parseTernary();
|
|
717
|
+
if (this.skipWhitespace(), this.peek() !== ":")
|
|
718
|
+
throw x(this.path, "expected ':' in ternary expression");
|
|
719
|
+
this.index++;
|
|
720
|
+
const i = this.parseTernary();
|
|
721
|
+
return { type: "ternary", condition: e, consequent: n, alternate: i };
|
|
722
|
+
}
|
|
723
|
+
parseLogicalOr() {
|
|
724
|
+
let e = this.parseLogicalAnd();
|
|
725
|
+
for (; this.skipWhitespace(), !!this.match("||"); ) {
|
|
726
|
+
const n = this.parseLogicalAnd();
|
|
727
|
+
e = { type: "binary", op: "||", left: e, right: n };
|
|
728
|
+
}
|
|
729
|
+
return e;
|
|
730
|
+
}
|
|
731
|
+
parseLogicalAnd() {
|
|
732
|
+
let e = this.parseComparison();
|
|
733
|
+
for (; this.skipWhitespace(), !!this.match("&&"); ) {
|
|
734
|
+
const n = this.parseComparison();
|
|
735
|
+
e = { type: "binary", op: "&&", left: e, right: n };
|
|
736
|
+
}
|
|
737
|
+
return e;
|
|
738
|
+
}
|
|
739
|
+
parseComparison() {
|
|
740
|
+
let e = this.parseAdditive();
|
|
741
|
+
for (; ; ) {
|
|
742
|
+
this.skipWhitespace();
|
|
743
|
+
const n = this.readComparisonOp();
|
|
744
|
+
if (!n)
|
|
745
|
+
break;
|
|
746
|
+
const i = this.parseAdditive();
|
|
747
|
+
e = { type: "binary", op: n, left: e, right: i };
|
|
748
|
+
}
|
|
749
|
+
return e;
|
|
750
|
+
}
|
|
751
|
+
readComparisonOp() {
|
|
752
|
+
const e = [
|
|
753
|
+
"===",
|
|
754
|
+
"!==",
|
|
755
|
+
"==",
|
|
756
|
+
"!=",
|
|
757
|
+
">=",
|
|
758
|
+
"<=",
|
|
759
|
+
">",
|
|
760
|
+
"<"
|
|
761
|
+
];
|
|
762
|
+
for (const n of e)
|
|
763
|
+
if (this.input.startsWith(n, this.index))
|
|
764
|
+
return this.index += n.length, n;
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
parseAdditive() {
|
|
768
|
+
let e = this.parseMultiplicative();
|
|
769
|
+
for (; ; ) {
|
|
770
|
+
this.skipWhitespace();
|
|
771
|
+
const n = this.peek();
|
|
772
|
+
if (n !== "+" && n !== "-")
|
|
773
|
+
break;
|
|
774
|
+
this.index++;
|
|
775
|
+
const i = this.parseMultiplicative();
|
|
776
|
+
e = { type: "binary", op: n, left: e, right: i };
|
|
777
|
+
}
|
|
778
|
+
return e;
|
|
779
|
+
}
|
|
780
|
+
parseMultiplicative() {
|
|
781
|
+
let e = this.parseUnary();
|
|
782
|
+
for (; ; ) {
|
|
783
|
+
this.skipWhitespace();
|
|
784
|
+
const n = this.peek();
|
|
785
|
+
if (n !== "*" && n !== "/")
|
|
786
|
+
break;
|
|
787
|
+
this.index++;
|
|
788
|
+
const i = this.parseUnary();
|
|
789
|
+
e = { type: "binary", op: n, left: e, right: i };
|
|
790
|
+
}
|
|
791
|
+
return e;
|
|
792
|
+
}
|
|
793
|
+
parseUnary() {
|
|
794
|
+
return this.skipWhitespace(), this.peek() === "!" ? (this.index++, { type: "unary", op: "!", operand: this.parseUnary() }) : this.parsePostfix();
|
|
795
|
+
}
|
|
796
|
+
parsePostfix() {
|
|
797
|
+
let e = this.parsePrimary();
|
|
798
|
+
for (; ; ) {
|
|
799
|
+
if (this.skipWhitespace(), this.peek() === ".") {
|
|
800
|
+
this.index++, e = this.parseAfterDot(e);
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
return e;
|
|
806
|
+
}
|
|
807
|
+
parseAfterDot(e) {
|
|
808
|
+
this.skipWhitespace();
|
|
809
|
+
const n = this.readIdentifier();
|
|
810
|
+
if (!n)
|
|
811
|
+
throw x(this.path, "expected property name after '.'");
|
|
812
|
+
if (this.skipWhitespace(), this.peek() === "(") {
|
|
813
|
+
if (n !== "toLocaleString")
|
|
814
|
+
throw x(this.path, `unsupported method: ${n}()`);
|
|
815
|
+
this.index++;
|
|
816
|
+
const i = this.parseMethodArgs();
|
|
817
|
+
return { type: "method", object: e, method: n, args: i };
|
|
818
|
+
}
|
|
819
|
+
return { type: "member", object: e, property: n };
|
|
820
|
+
}
|
|
821
|
+
parseMethodArgs() {
|
|
822
|
+
this.skipWhitespace();
|
|
823
|
+
const e = [];
|
|
824
|
+
if (this.peek() === ")")
|
|
825
|
+
return this.index++, e;
|
|
826
|
+
for (e.push(this.parseLiteralValue()), this.skipWhitespace(); this.peek() === ","; )
|
|
827
|
+
this.index++, e.push(this.parseLiteralValue()), this.skipWhitespace();
|
|
828
|
+
if (this.peek() !== ")")
|
|
829
|
+
throw x(this.path, "expected ')' after method arguments");
|
|
830
|
+
return this.index++, e;
|
|
831
|
+
}
|
|
832
|
+
parsePrimary() {
|
|
833
|
+
this.skipWhitespace();
|
|
834
|
+
const e = this.peek();
|
|
835
|
+
if (e === "(") {
|
|
836
|
+
this.index++;
|
|
837
|
+
const n = this.parseExpression();
|
|
838
|
+
if (this.skipWhitespace(), this.peek() !== ")")
|
|
839
|
+
throw x(this.path, "expected ')'");
|
|
840
|
+
return this.index++, n;
|
|
841
|
+
}
|
|
842
|
+
if (e === "`")
|
|
843
|
+
return this.parseTemplateLiteral();
|
|
844
|
+
if (e === '"' || e === "'")
|
|
845
|
+
return { type: "literal", value: this.readString() };
|
|
846
|
+
if (e === "-" || e >= "0" && e <= "9")
|
|
847
|
+
return { type: "literal", value: this.readNumber() };
|
|
848
|
+
if (e === "{")
|
|
849
|
+
return { type: "literal", value: this.parseObjectLiteral() };
|
|
850
|
+
if (e === "[")
|
|
851
|
+
return { type: "literal", value: this.parseArrayLiteral() };
|
|
852
|
+
if (q(e)) {
|
|
853
|
+
const n = this.readIdentifier();
|
|
854
|
+
if (n === "true" || n === "false" || n === "null" || n === "undefined")
|
|
855
|
+
return { type: "literal", value: n === "true" ? !0 : n === "false" ? !1 : n === "null" ? null : void 0 };
|
|
856
|
+
if (this.skipWhitespace(), this.peek() === "(") {
|
|
857
|
+
if (!this.allowCalls)
|
|
858
|
+
throw x(
|
|
859
|
+
this.path,
|
|
860
|
+
"component calls are not allowed in template literals"
|
|
861
|
+
);
|
|
862
|
+
this.index++;
|
|
863
|
+
const i = this.parseCallArgs();
|
|
864
|
+
return { type: "call", callee: n, args: i };
|
|
865
|
+
}
|
|
866
|
+
if (this.peek() === "[")
|
|
867
|
+
throw x(this.path, "bracket access is not allowed");
|
|
868
|
+
return { type: "identifier", name: n };
|
|
869
|
+
}
|
|
870
|
+
throw x(this.path, `unexpected character '${e}'`);
|
|
871
|
+
}
|
|
872
|
+
parseTemplateLiteral() {
|
|
873
|
+
this.index++;
|
|
874
|
+
const e = [];
|
|
875
|
+
let n = "";
|
|
876
|
+
for (; this.index < this.input.length; ) {
|
|
877
|
+
const i = this.input[this.index];
|
|
878
|
+
if (i === "`")
|
|
879
|
+
return this.index++, e.push(n), { type: "template", parts: e };
|
|
880
|
+
if (i === "\\") {
|
|
881
|
+
if (this.index++, this.index >= this.input.length)
|
|
882
|
+
throw x(this.path, "unterminated template literal escape");
|
|
883
|
+
n += this.input[this.index], this.index++;
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
if (i === "$" && this.input[this.index + 1] === "{") {
|
|
887
|
+
e.push(n), n = "", this.index += 2;
|
|
888
|
+
const s = this.readTemplateExpression(), r = C(s, this.path, {
|
|
889
|
+
allowCalls: !1
|
|
890
|
+
});
|
|
891
|
+
e.push(r);
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
n += i, this.index++;
|
|
895
|
+
}
|
|
896
|
+
throw x(this.path, "unterminated template literal");
|
|
897
|
+
}
|
|
898
|
+
readTemplateExpression() {
|
|
899
|
+
let e = 1;
|
|
900
|
+
const n = this.index;
|
|
901
|
+
let i = null;
|
|
902
|
+
for (; this.index < this.input.length; ) {
|
|
903
|
+
const s = this.input[this.index];
|
|
904
|
+
if (i) {
|
|
905
|
+
if (s === "\\") {
|
|
906
|
+
this.index += 2;
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
s === i && (i = null), this.index++;
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
if (s === '"' || s === "'" || s === "`") {
|
|
913
|
+
i = s, this.index++;
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
if (s === "{") {
|
|
917
|
+
e++, this.index++;
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
if (s === "}") {
|
|
921
|
+
if (e--, e === 0) {
|
|
922
|
+
const r = this.input.slice(n, this.index);
|
|
923
|
+
return this.index++, r;
|
|
924
|
+
}
|
|
925
|
+
this.index++;
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
this.index++;
|
|
929
|
+
}
|
|
930
|
+
throw x(this.path, "unterminated template expression");
|
|
931
|
+
}
|
|
932
|
+
parseCallArgs() {
|
|
933
|
+
if (this.skipWhitespace(), this.peek() === ")")
|
|
934
|
+
return this.index++, {};
|
|
935
|
+
if (this.peek() !== "{")
|
|
936
|
+
throw x(this.path, "expected object literal");
|
|
937
|
+
this.index++, this.skipWhitespace();
|
|
938
|
+
const e = {};
|
|
939
|
+
if (this.peek() === "}") {
|
|
940
|
+
if (this.index++, this.skipWhitespace(), this.peek() !== ")")
|
|
941
|
+
throw x(this.path, "expected ')' after call arguments");
|
|
942
|
+
return this.index++, e;
|
|
943
|
+
}
|
|
944
|
+
for (; ; ) {
|
|
945
|
+
this.skipWhitespace();
|
|
946
|
+
const n = this.readIdentifier();
|
|
947
|
+
if (!n)
|
|
948
|
+
throw x(this.path, "expected property name in object literal");
|
|
949
|
+
if (this.skipWhitespace(), this.peek() !== ":")
|
|
950
|
+
throw x(this.path, "expected ':' in object literal");
|
|
951
|
+
if (this.index++, this.skipWhitespace(), e[n] = this.parseTernary(), this.skipWhitespace(), this.peek() === "}") {
|
|
952
|
+
this.index++;
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
if (this.peek() === ",") {
|
|
956
|
+
if (this.index++, this.skipWhitespace(), this.peek() === "}") {
|
|
957
|
+
this.index++;
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
throw x(this.path, "expected ',' or '}' in object literal");
|
|
963
|
+
}
|
|
964
|
+
if (this.skipWhitespace(), this.peek() !== ")")
|
|
965
|
+
throw x(this.path, "expected ')' after call arguments");
|
|
966
|
+
return this.index++, e;
|
|
967
|
+
}
|
|
968
|
+
parseObjectLiteral() {
|
|
969
|
+
if (this.peek() !== "{")
|
|
970
|
+
throw x(this.path, "expected object literal");
|
|
971
|
+
this.index++, this.skipWhitespace();
|
|
972
|
+
const e = {};
|
|
973
|
+
if (this.peek() === "}")
|
|
974
|
+
return this.index++, e;
|
|
975
|
+
for (; ; ) {
|
|
976
|
+
this.skipWhitespace();
|
|
977
|
+
const n = this.readIdentifier();
|
|
978
|
+
if (!n)
|
|
979
|
+
throw x(this.path, "expected property name in object literal");
|
|
980
|
+
if (this.skipWhitespace(), this.peek() !== ":")
|
|
981
|
+
throw x(this.path, "expected ':' in object literal");
|
|
982
|
+
if (this.index++, this.skipWhitespace(), e[n] = this.parseLiteralValue(), this.skipWhitespace(), this.peek() === "}") {
|
|
983
|
+
this.index++;
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
if (this.peek() === ",") {
|
|
987
|
+
if (this.index++, this.skipWhitespace(), this.peek() === "}") {
|
|
988
|
+
this.index++;
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
} else
|
|
992
|
+
throw x(this.path, "expected ',' or '}' in object literal");
|
|
993
|
+
}
|
|
994
|
+
return e;
|
|
995
|
+
}
|
|
996
|
+
parseArrayLiteral() {
|
|
997
|
+
if (this.peek() !== "[")
|
|
998
|
+
throw x(this.path, "expected array literal");
|
|
999
|
+
this.index++, this.skipWhitespace();
|
|
1000
|
+
const e = [];
|
|
1001
|
+
if (this.peek() === "]")
|
|
1002
|
+
return this.index++, e;
|
|
1003
|
+
for (; ; ) {
|
|
1004
|
+
if (this.skipWhitespace(), e.push(this.parseLiteralValue()), this.skipWhitespace(), this.peek() === "]") {
|
|
1005
|
+
this.index++;
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
if (this.peek() === ",") {
|
|
1009
|
+
if (this.index++, this.skipWhitespace(), this.peek() === "]") {
|
|
1010
|
+
this.index++;
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
} else
|
|
1014
|
+
throw x(this.path, "expected ',' or ']' in array literal");
|
|
1015
|
+
}
|
|
1016
|
+
return e;
|
|
1017
|
+
}
|
|
1018
|
+
parseLiteralValue() {
|
|
1019
|
+
this.skipWhitespace();
|
|
1020
|
+
const e = this.peek();
|
|
1021
|
+
if (e === '"' || e === "'")
|
|
1022
|
+
return this.readString();
|
|
1023
|
+
if (e === "-" || e >= "0" && e <= "9")
|
|
1024
|
+
return this.readNumber();
|
|
1025
|
+
if (e === "{")
|
|
1026
|
+
return this.parseObjectLiteral();
|
|
1027
|
+
if (e === "[")
|
|
1028
|
+
return this.parseArrayLiteral();
|
|
1029
|
+
if (q(e)) {
|
|
1030
|
+
const n = this.readIdentifier();
|
|
1031
|
+
if (n === "true") return !0;
|
|
1032
|
+
if (n === "false") return !1;
|
|
1033
|
+
if (n === "null") return null;
|
|
1034
|
+
throw x(this.path, "object literal values must be literals");
|
|
1035
|
+
}
|
|
1036
|
+
throw x(this.path, "object literal values must be literals");
|
|
1037
|
+
}
|
|
1038
|
+
match(e) {
|
|
1039
|
+
return this.skipWhitespace(), this.input.startsWith(e, this.index) ? (this.index += e.length, !0) : !1;
|
|
1040
|
+
}
|
|
1041
|
+
peek() {
|
|
1042
|
+
return this.input[this.index] ?? "";
|
|
1043
|
+
}
|
|
1044
|
+
readIdentifier() {
|
|
1045
|
+
this.skipWhitespace();
|
|
1046
|
+
const e = this.index;
|
|
1047
|
+
if (!q(this.peek()))
|
|
1048
|
+
return "";
|
|
1049
|
+
for (this.index++; this.index < this.input.length && ot(this.peek()); )
|
|
1050
|
+
this.index++;
|
|
1051
|
+
return this.input.slice(e, this.index);
|
|
1052
|
+
}
|
|
1053
|
+
readString() {
|
|
1054
|
+
const e = this.peek();
|
|
1055
|
+
this.index++;
|
|
1056
|
+
let n = "";
|
|
1057
|
+
for (; this.index < this.input.length; ) {
|
|
1058
|
+
const i = this.input[this.index];
|
|
1059
|
+
if (i === e)
|
|
1060
|
+
return this.index++, n;
|
|
1061
|
+
if (i === "\\") {
|
|
1062
|
+
if (this.index++, this.index >= this.input.length)
|
|
1063
|
+
throw x(this.path, "unterminated string escape");
|
|
1064
|
+
const s = this.input[this.index];
|
|
1065
|
+
n += s, this.index++;
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1068
|
+
n += i, this.index++;
|
|
1069
|
+
}
|
|
1070
|
+
throw x(this.path, "unterminated string literal");
|
|
1071
|
+
}
|
|
1072
|
+
readNumber() {
|
|
1073
|
+
const e = this.index;
|
|
1074
|
+
for (this.peek() === "-" && this.index++; this.index < this.input.length && /[0-9.]/.test(this.peek()); )
|
|
1075
|
+
this.index++;
|
|
1076
|
+
const n = this.input.slice(e, this.index), i = Number(n);
|
|
1077
|
+
if (Number.isNaN(i))
|
|
1078
|
+
throw x(this.path, `invalid number '${n}'`);
|
|
1079
|
+
return i;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
async function _e(t, e, n = {}) {
|
|
1083
|
+
const i = n.path;
|
|
1084
|
+
let s = "", r = 0;
|
|
1085
|
+
for (; r < t.length; ) {
|
|
1086
|
+
const o = t.indexOf("{", r);
|
|
1087
|
+
if (o === -1) {
|
|
1088
|
+
s += t.slice(r);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
s += t.slice(r, o);
|
|
1092
|
+
const a = t[o + 1] === "{" && t[o + 2] === "{" && (o === 0 || t[o - 1] !== "\\");
|
|
1093
|
+
if (!(!a && t[o + 1] === "{" && (o === 0 || t[o - 1] !== "\\")) && !a) {
|
|
1094
|
+
s += "{", r = o + 1;
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
const h = a ? 3 : 2, l = a ? "}}}" : "}}", d = t.indexOf(l, o + h);
|
|
1098
|
+
if (d === -1)
|
|
1099
|
+
throw u({
|
|
1100
|
+
code: "parse_error",
|
|
1101
|
+
path: i,
|
|
1102
|
+
details: { message: "unclosed expression" }
|
|
1103
|
+
});
|
|
1104
|
+
const f = t.slice(o + h, d).trim(), g = C(f, i), m = await w(g, {
|
|
1105
|
+
...n,
|
|
1106
|
+
context: e,
|
|
1107
|
+
path: i,
|
|
1108
|
+
parentContext: n.parentContext ?? e
|
|
1109
|
+
});
|
|
1110
|
+
s += m == null ? "" : String(m), r = d + l.length;
|
|
1111
|
+
}
|
|
1112
|
+
return s;
|
|
1113
|
+
}
|
|
1114
|
+
function ct(t, e) {
|
|
1115
|
+
let n = 0, i = 0;
|
|
1116
|
+
for (; i < t.length; ) {
|
|
1117
|
+
const s = t.indexOf(e, i);
|
|
1118
|
+
if (s === -1)
|
|
1119
|
+
break;
|
|
1120
|
+
n++, i = s + e.length;
|
|
1121
|
+
}
|
|
1122
|
+
return n;
|
|
1123
|
+
}
|
|
1124
|
+
function X(t) {
|
|
1125
|
+
const e = t.includes("@hg"), n = t.includes("@endhg"), i = ct(t, "@@");
|
|
1126
|
+
return e && n ? i > 0 ? "mixed" : "hg" : i >= 2 && !e && !n ? "at-at" : (e || n) && i > 0 ? "mixed" : e && !n || i === 1 && !n ? "unclosed" : "none";
|
|
1127
|
+
}
|
|
1128
|
+
function Q(t) {
|
|
1129
|
+
return t.replace(/@endhg/g, "").replace(/@hg/g, "").replace(/@@/g, "");
|
|
1130
|
+
}
|
|
1131
|
+
function ee(t, e) {
|
|
1132
|
+
let n = 0, i = !1;
|
|
1133
|
+
for (; n < e; ) {
|
|
1134
|
+
const s = t.indexOf("```", n);
|
|
1135
|
+
if (s === -1 || s >= e)
|
|
1136
|
+
break;
|
|
1137
|
+
i = !i, n = s + 3;
|
|
1138
|
+
}
|
|
1139
|
+
return i;
|
|
1140
|
+
}
|
|
1141
|
+
function T(t) {
|
|
1142
|
+
const e = [];
|
|
1143
|
+
let n = 0;
|
|
1144
|
+
for (; n < t.length; ) {
|
|
1145
|
+
const i = t.indexOf("<!--", n);
|
|
1146
|
+
if (i === -1)
|
|
1147
|
+
break;
|
|
1148
|
+
if (ee(t, i)) {
|
|
1149
|
+
n = i + 4;
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
const s = t.indexOf("-->", i + 4);
|
|
1153
|
+
if (s === -1)
|
|
1154
|
+
break;
|
|
1155
|
+
const r = t.slice(i, s + 3), o = r.slice(4, r.length - 3), a = X(o);
|
|
1156
|
+
(a === "hg" || a === "at-at") && e.push({
|
|
1157
|
+
start: i,
|
|
1158
|
+
end: s + 3,
|
|
1159
|
+
inner: o,
|
|
1160
|
+
raw: r
|
|
1161
|
+
}), n = s + 3;
|
|
1162
|
+
}
|
|
1163
|
+
return e;
|
|
1164
|
+
}
|
|
1165
|
+
function Se(t) {
|
|
1166
|
+
let e = 0;
|
|
1167
|
+
for (; e < t.length; ) {
|
|
1168
|
+
const n = t.indexOf("<!--", e);
|
|
1169
|
+
if (n === -1)
|
|
1170
|
+
return !1;
|
|
1171
|
+
if (ee(t, n)) {
|
|
1172
|
+
e = n + 4;
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
const i = t.indexOf("-->", n + 4);
|
|
1176
|
+
if (i === -1)
|
|
1177
|
+
return !1;
|
|
1178
|
+
const s = t.slice(n + 4, i), r = X(s);
|
|
1179
|
+
if (r === "unclosed" || r === "mixed")
|
|
1180
|
+
return !0;
|
|
1181
|
+
e = i + 3;
|
|
1182
|
+
}
|
|
1183
|
+
return !1;
|
|
1184
|
+
}
|
|
1185
|
+
function Ce(t) {
|
|
1186
|
+
let e = 0;
|
|
1187
|
+
for (; e < t.length; ) {
|
|
1188
|
+
const n = t.indexOf("<!--", e);
|
|
1189
|
+
if (n === -1)
|
|
1190
|
+
return null;
|
|
1191
|
+
if (ee(t, n)) {
|
|
1192
|
+
e = n + 4;
|
|
1193
|
+
continue;
|
|
1194
|
+
}
|
|
1195
|
+
const i = t.indexOf("-->", n + 4);
|
|
1196
|
+
if (i === -1)
|
|
1197
|
+
return null;
|
|
1198
|
+
const s = t.slice(n + 4, i), r = X(s);
|
|
1199
|
+
if (r === "mixed")
|
|
1200
|
+
return "mixed @hg and @@ markers are not allowed";
|
|
1201
|
+
if (r === "unclosed")
|
|
1202
|
+
return "unclosed hyogen block (missing closing marker)";
|
|
1203
|
+
e = i + 3;
|
|
1204
|
+
}
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
function E(t) {
|
|
1208
|
+
return Q(t).trim().split(/\r?\n/).map((n) => n.trim()).filter((n) => n.length > 0);
|
|
1209
|
+
}
|
|
1210
|
+
const lt = /^(if\s+.+|else\s+if\s+.+|else|endif|each\s+[A-Za-z_$][A-Za-z0-9_$]*\s+in\s+.+|endeach)$/i;
|
|
1211
|
+
function Ae(t) {
|
|
1212
|
+
return lt.test(t.trim());
|
|
1213
|
+
}
|
|
1214
|
+
function V(t, e) {
|
|
1215
|
+
throw u({
|
|
1216
|
+
code: "parse_error",
|
|
1217
|
+
path: t,
|
|
1218
|
+
details: { message: e }
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
function ht(t, e) {
|
|
1222
|
+
let n = t;
|
|
1223
|
+
const i = /^<!--([\s\S]*?)-->$/.exec(t.trim());
|
|
1224
|
+
i && (n = i[1]);
|
|
1225
|
+
const s = E(n);
|
|
1226
|
+
if (s.length !== 1)
|
|
1227
|
+
return null;
|
|
1228
|
+
const r = s[0];
|
|
1229
|
+
if (/^include\s+/i.test(r) || /^component\s+/i.test(r) || /^const\s+/i.test(r) || /^let\s+/i.test(r) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*=/.test(r))
|
|
1230
|
+
return null;
|
|
1231
|
+
if (r === "else")
|
|
1232
|
+
return { kind: "else" };
|
|
1233
|
+
if (r === "endif")
|
|
1234
|
+
return { kind: "endif" };
|
|
1235
|
+
if (r === "endeach")
|
|
1236
|
+
return { kind: "endeach" };
|
|
1237
|
+
if (/^IF\b/.test(r) || /^ELSE\b/.test(r) || /^ENDIF\b/.test(r))
|
|
1238
|
+
throw V(e, "control keywords must be lowercase");
|
|
1239
|
+
const o = /^else\s+if\s+(.+)$/.exec(r);
|
|
1240
|
+
if (o)
|
|
1241
|
+
return {
|
|
1242
|
+
kind: "else_if",
|
|
1243
|
+
expr: C(o[1], e)
|
|
1244
|
+
};
|
|
1245
|
+
const a = /^if\s+(.+)$/.exec(r);
|
|
1246
|
+
if (a)
|
|
1247
|
+
return {
|
|
1248
|
+
kind: "if",
|
|
1249
|
+
expr: C(a[1], e)
|
|
1250
|
+
};
|
|
1251
|
+
const c = /^each\s+([A-Za-z_$][A-Za-z0-9_$]*)\s+in\s+(.+)$/.exec(r);
|
|
1252
|
+
if (c)
|
|
1253
|
+
return {
|
|
1254
|
+
kind: "each",
|
|
1255
|
+
item: c[1],
|
|
1256
|
+
expr: C(c[2], e)
|
|
1257
|
+
};
|
|
1258
|
+
if (r === "if")
|
|
1259
|
+
throw V(e, "if requires an expression");
|
|
1260
|
+
if (/^each\s+/.test(r))
|
|
1261
|
+
throw V(e, "invalid each directive");
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
function R(t) {
|
|
1265
|
+
return { start: t.start, end: t.end, raw: t.raw };
|
|
1266
|
+
}
|
|
1267
|
+
function S(t, e) {
|
|
1268
|
+
throw u({
|
|
1269
|
+
code: "parse_error",
|
|
1270
|
+
path: t,
|
|
1271
|
+
details: { message: e }
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
function dt(t, e) {
|
|
1275
|
+
const n = [];
|
|
1276
|
+
for (const i of T(t)) {
|
|
1277
|
+
const s = ht(i.inner, e);
|
|
1278
|
+
s && n.push({
|
|
1279
|
+
start: i.start,
|
|
1280
|
+
end: i.end,
|
|
1281
|
+
raw: i.raw,
|
|
1282
|
+
opener: s
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
return n;
|
|
1286
|
+
}
|
|
1287
|
+
function We(t) {
|
|
1288
|
+
return t.kind === "if" || t.kind === "each";
|
|
1289
|
+
}
|
|
1290
|
+
function ut(t, e) {
|
|
1291
|
+
const n = dt(t, e);
|
|
1292
|
+
if (n.length === 0)
|
|
1293
|
+
return t.length > 0 ? [{ kind: "text", content: t }] : [];
|
|
1294
|
+
const { nodes: i, nextIndex: s } = j(t, n, 0, n.length, e);
|
|
1295
|
+
if (s < n.length) {
|
|
1296
|
+
const r = n[s];
|
|
1297
|
+
if (r.opener.kind === "endif")
|
|
1298
|
+
throw S(e, "endif without matching if");
|
|
1299
|
+
if (r.opener.kind === "endeach")
|
|
1300
|
+
throw S(e, "endeach without matching each");
|
|
1301
|
+
if (r.opener.kind === "else" || r.opener.kind === "else_if")
|
|
1302
|
+
throw S(e, "else without matching if");
|
|
1303
|
+
}
|
|
1304
|
+
return i;
|
|
1305
|
+
}
|
|
1306
|
+
function j(t, e, n, i, s, r = 0, o) {
|
|
1307
|
+
const a = o ?? t.length, c = [];
|
|
1308
|
+
let h = r, l = n;
|
|
1309
|
+
for (; l < i; ) {
|
|
1310
|
+
const d = e[l];
|
|
1311
|
+
if (d.start >= a)
|
|
1312
|
+
break;
|
|
1313
|
+
if (d.end <= r) {
|
|
1314
|
+
l++;
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (d.start > h && c.push({
|
|
1318
|
+
kind: "text",
|
|
1319
|
+
content: t.slice(h, d.start)
|
|
1320
|
+
}), d.opener.kind === "if") {
|
|
1321
|
+
const f = ft(t, e, l, i, s);
|
|
1322
|
+
c.push(f.node), h = f.endPos, l = f.nextIndex;
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
if (d.opener.kind === "each") {
|
|
1326
|
+
const f = pt(t, e, l, i, s);
|
|
1327
|
+
c.push(f.node), h = f.endPos, l = f.nextIndex;
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
if (d.opener.kind === "else" || d.opener.kind === "else_if")
|
|
1331
|
+
throw S(s, "else without matching if");
|
|
1332
|
+
if (d.opener.kind === "endif")
|
|
1333
|
+
throw S(s, "endif without matching if");
|
|
1334
|
+
if (d.opener.kind === "endeach")
|
|
1335
|
+
throw S(s, "endeach without matching each");
|
|
1336
|
+
l++;
|
|
1337
|
+
}
|
|
1338
|
+
return h < a && c.push({ kind: "text", content: t.slice(h, a) }), { nodes: c, nextIndex: l };
|
|
1339
|
+
}
|
|
1340
|
+
function ft(t, e, n, i, s) {
|
|
1341
|
+
const r = e[n];
|
|
1342
|
+
if (r.opener.kind !== "if")
|
|
1343
|
+
throw S(s, "expected if");
|
|
1344
|
+
const o = [];
|
|
1345
|
+
let a = n, c = r.end, h = 0;
|
|
1346
|
+
for (; a < i; ) {
|
|
1347
|
+
const l = e[a];
|
|
1348
|
+
if (a === n) {
|
|
1349
|
+
if (l.opener.kind !== "if")
|
|
1350
|
+
throw S(s, "expected if");
|
|
1351
|
+
o.push({
|
|
1352
|
+
kind: "if",
|
|
1353
|
+
expr: l.opener.expr,
|
|
1354
|
+
opener: R(l),
|
|
1355
|
+
body: []
|
|
1356
|
+
}), a++;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (We(l.opener)) {
|
|
1360
|
+
h++, a++;
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (l.opener.kind === "endif") {
|
|
1364
|
+
if (h === 0)
|
|
1365
|
+
return o[o.length - 1].body = j(
|
|
1366
|
+
t,
|
|
1367
|
+
e,
|
|
1368
|
+
n + 1,
|
|
1369
|
+
a,
|
|
1370
|
+
s,
|
|
1371
|
+
c,
|
|
1372
|
+
l.start
|
|
1373
|
+
).nodes, {
|
|
1374
|
+
node: { kind: "if", branches: o, closer: R(l) },
|
|
1375
|
+
nextIndex: a + 1,
|
|
1376
|
+
endPos: l.end
|
|
1377
|
+
};
|
|
1378
|
+
h--, a++;
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
if (l.opener.kind === "endeach") {
|
|
1382
|
+
h--, a++;
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
if (h === 0) {
|
|
1386
|
+
if (l.opener.kind === "else_if") {
|
|
1387
|
+
o[o.length - 1].body = j(
|
|
1388
|
+
t,
|
|
1389
|
+
e,
|
|
1390
|
+
n + 1,
|
|
1391
|
+
a,
|
|
1392
|
+
s,
|
|
1393
|
+
c,
|
|
1394
|
+
l.start
|
|
1395
|
+
).nodes, o.push({
|
|
1396
|
+
kind: "else_if",
|
|
1397
|
+
expr: l.opener.expr,
|
|
1398
|
+
opener: R(l),
|
|
1399
|
+
body: []
|
|
1400
|
+
}), c = l.end, a++;
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
if (l.opener.kind === "else") {
|
|
1404
|
+
o[o.length - 1].body = j(
|
|
1405
|
+
t,
|
|
1406
|
+
e,
|
|
1407
|
+
n + 1,
|
|
1408
|
+
a,
|
|
1409
|
+
s,
|
|
1410
|
+
c,
|
|
1411
|
+
l.start
|
|
1412
|
+
).nodes, o.push({
|
|
1413
|
+
kind: "else",
|
|
1414
|
+
opener: R(l),
|
|
1415
|
+
body: []
|
|
1416
|
+
}), c = l.end, a++;
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
a++;
|
|
1421
|
+
}
|
|
1422
|
+
throw S(s, "unclosed if block (missing endif)");
|
|
1423
|
+
}
|
|
1424
|
+
function pt(t, e, n, i, s) {
|
|
1425
|
+
const r = e[n];
|
|
1426
|
+
if (r.opener.kind !== "each")
|
|
1427
|
+
throw S(s, "expected each");
|
|
1428
|
+
let o = n + 1;
|
|
1429
|
+
const a = r.end;
|
|
1430
|
+
let c = 0;
|
|
1431
|
+
for (; o < i; ) {
|
|
1432
|
+
const h = e[o];
|
|
1433
|
+
if (We(h.opener)) {
|
|
1434
|
+
c++, o++;
|
|
1435
|
+
continue;
|
|
1436
|
+
}
|
|
1437
|
+
if (h.opener.kind === "endeach") {
|
|
1438
|
+
if (c === 0) {
|
|
1439
|
+
const l = j(
|
|
1440
|
+
t,
|
|
1441
|
+
e,
|
|
1442
|
+
n + 1,
|
|
1443
|
+
o,
|
|
1444
|
+
s,
|
|
1445
|
+
a,
|
|
1446
|
+
h.start
|
|
1447
|
+
).nodes;
|
|
1448
|
+
return {
|
|
1449
|
+
node: {
|
|
1450
|
+
kind: "each",
|
|
1451
|
+
item: r.opener.item,
|
|
1452
|
+
expr: r.opener.expr,
|
|
1453
|
+
opener: R(r),
|
|
1454
|
+
body: l,
|
|
1455
|
+
closer: R(h)
|
|
1456
|
+
},
|
|
1457
|
+
nextIndex: o + 1,
|
|
1458
|
+
endPos: h.end
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
c--, o++;
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
if (h.opener.kind === "endif") {
|
|
1465
|
+
c--, o++;
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
o++;
|
|
1469
|
+
}
|
|
1470
|
+
throw S(s, "unclosed each block (missing endeach)");
|
|
1471
|
+
}
|
|
1472
|
+
const ue = 20;
|
|
1473
|
+
class mt {
|
|
1474
|
+
depth = 0;
|
|
1475
|
+
get currentDepth() {
|
|
1476
|
+
return this.depth;
|
|
1477
|
+
}
|
|
1478
|
+
enter() {
|
|
1479
|
+
return this.depth >= ue ? { exceeded: !0, limit: ue } : (this.depth++, { exceeded: !1, depth: this.depth });
|
|
1480
|
+
}
|
|
1481
|
+
exit() {
|
|
1482
|
+
this.depth > 0 && this.depth--;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
function gt(t) {
|
|
1486
|
+
return !!t;
|
|
1487
|
+
}
|
|
1488
|
+
function xt(t) {
|
|
1489
|
+
return t != null && typeof t[Symbol.iterator] == "function";
|
|
1490
|
+
}
|
|
1491
|
+
function $e(t) {
|
|
1492
|
+
return {
|
|
1493
|
+
code: "nest_limit_exceeded",
|
|
1494
|
+
message: "structure nest limit exceeded",
|
|
1495
|
+
path: t,
|
|
1496
|
+
details: { limit: 20 }
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
function te(t) {
|
|
1500
|
+
return t.startsWith(`
|
|
1501
|
+
`) ? t.slice(1) : t;
|
|
1502
|
+
}
|
|
1503
|
+
async function kt(t, e) {
|
|
1504
|
+
const n = e.path, i = e.warnings ?? [], s = ut(t, n), r = new mt();
|
|
1505
|
+
return ne(s, e, r, i);
|
|
1506
|
+
}
|
|
1507
|
+
async function ne(t, e, n, i) {
|
|
1508
|
+
const s = e.preserveHgComments === !0;
|
|
1509
|
+
let r = "", o = !1;
|
|
1510
|
+
for (const a of t) {
|
|
1511
|
+
let c = await wt(a, e, n, i);
|
|
1512
|
+
o && (c = te(c)), r += c, o = !s && (a.kind === "if" || a.kind === "each");
|
|
1513
|
+
}
|
|
1514
|
+
return r;
|
|
1515
|
+
}
|
|
1516
|
+
async function wt(t, e, n, i) {
|
|
1517
|
+
switch (t.kind) {
|
|
1518
|
+
case "text":
|
|
1519
|
+
return t.content;
|
|
1520
|
+
case "if":
|
|
1521
|
+
return bt(t, e, n, i);
|
|
1522
|
+
case "each":
|
|
1523
|
+
return yt(t, e, n, i);
|
|
1524
|
+
default:
|
|
1525
|
+
return "";
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
async function bt(t, e, n, i) {
|
|
1529
|
+
if (n.enter().exceeded)
|
|
1530
|
+
return i.push($e(e.path)), "";
|
|
1531
|
+
try {
|
|
1532
|
+
let r = -1;
|
|
1533
|
+
for (let c = 0; c < t.branches.length; c++) {
|
|
1534
|
+
const h = t.branches[c];
|
|
1535
|
+
if (h.kind === "else") {
|
|
1536
|
+
r = c;
|
|
1537
|
+
break;
|
|
1538
|
+
}
|
|
1539
|
+
const l = await w(h.expr, e);
|
|
1540
|
+
if (gt(l)) {
|
|
1541
|
+
r = c;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
const o = e.preserveHgComments === !0;
|
|
1546
|
+
let a = "";
|
|
1547
|
+
for (let c = 0; c < t.branches.length; c++) {
|
|
1548
|
+
const h = t.branches[c];
|
|
1549
|
+
if (o && (a += h.opener.raw), c === r) {
|
|
1550
|
+
let l = await ne(h.body, e, n, i);
|
|
1551
|
+
o || (l = te(l)), a += l;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return o && (a += t.closer.raw), a;
|
|
1555
|
+
} finally {
|
|
1556
|
+
n.exit();
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
async function yt(t, e, n, i) {
|
|
1560
|
+
if (n.enter().exceeded)
|
|
1561
|
+
return i.push($e(e.path)), "";
|
|
1562
|
+
try {
|
|
1563
|
+
const r = await w(t.expr, e);
|
|
1564
|
+
if (!xt(r))
|
|
1565
|
+
return "";
|
|
1566
|
+
const o = e.preserveHgComments === !0;
|
|
1567
|
+
let a = "";
|
|
1568
|
+
for (const c of r) {
|
|
1569
|
+
const h = { ...e.context, [t.item]: c };
|
|
1570
|
+
o && (a += t.opener.raw);
|
|
1571
|
+
let l = await ne(t.body, {
|
|
1572
|
+
...e,
|
|
1573
|
+
context: h
|
|
1574
|
+
}, n, i);
|
|
1575
|
+
o || (l = te(l));
|
|
1576
|
+
const d = await _e(l, h, {
|
|
1577
|
+
path: e.path,
|
|
1578
|
+
registry: e.registry,
|
|
1579
|
+
loader: e.loader,
|
|
1580
|
+
rootDir: e.rootDir,
|
|
1581
|
+
warnings: i,
|
|
1582
|
+
visitStack: e.visitStack,
|
|
1583
|
+
parentContext: e.parentContext ?? e.context,
|
|
1584
|
+
preserveHgComments: e.preserveHgComments,
|
|
1585
|
+
constrainToRoot: e.constrainToRoot
|
|
1586
|
+
});
|
|
1587
|
+
a += d, o && (a += t.closer.raw);
|
|
1588
|
+
}
|
|
1589
|
+
return a;
|
|
1590
|
+
} finally {
|
|
1591
|
+
n.exit();
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
function Y(t, e, n, i, s = !1, r = !1) {
|
|
1595
|
+
return ye(e) ? e : ve(e, {
|
|
1596
|
+
rootDir: t,
|
|
1597
|
+
fromPath: i,
|
|
1598
|
+
documentPath: n,
|
|
1599
|
+
constrainToRoot: s,
|
|
1600
|
+
hyogenPath: r
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
function Te(t) {
|
|
1604
|
+
let e = 0;
|
|
1605
|
+
for (let n = t.length - 1; n >= 0 && t[n] === `
|
|
1606
|
+
`; n--)
|
|
1607
|
+
e++;
|
|
1608
|
+
return e;
|
|
1609
|
+
}
|
|
1610
|
+
function Ee(t) {
|
|
1611
|
+
let e = 0;
|
|
1612
|
+
for (; e < t.length && t[e] === `
|
|
1613
|
+
`; )
|
|
1614
|
+
e++;
|
|
1615
|
+
return e;
|
|
1616
|
+
}
|
|
1617
|
+
function D(t, e) {
|
|
1618
|
+
const n = Te(t), i = Ee(e), s = Math.max(n, i);
|
|
1619
|
+
return t.slice(0, t.length - n) + `
|
|
1620
|
+
`.repeat(s) + e.slice(i);
|
|
1621
|
+
}
|
|
1622
|
+
function ie(t, e) {
|
|
1623
|
+
const n = Te(t), i = Ee(e);
|
|
1624
|
+
return n + i - Math.max(n, i);
|
|
1625
|
+
}
|
|
1626
|
+
function fe(t, e, n) {
|
|
1627
|
+
const i = t.indexOf(e);
|
|
1628
|
+
if (i < 0)
|
|
1629
|
+
return t;
|
|
1630
|
+
const s = t.slice(0, i), r = t.slice(i + e.length);
|
|
1631
|
+
return D(D(s, n), r);
|
|
1632
|
+
}
|
|
1633
|
+
async function vt(t) {
|
|
1634
|
+
let e = t.source;
|
|
1635
|
+
for (const n of t.directives) {
|
|
1636
|
+
const i = Y(
|
|
1637
|
+
t.root,
|
|
1638
|
+
n.path,
|
|
1639
|
+
t.path,
|
|
1640
|
+
t.path,
|
|
1641
|
+
t.constrainToRoot,
|
|
1642
|
+
!0
|
|
1643
|
+
);
|
|
1644
|
+
if (t.visitStack) {
|
|
1645
|
+
const s = t.visitStack.check(i);
|
|
1646
|
+
if (s.circular) {
|
|
1647
|
+
t.warnings?.push({
|
|
1648
|
+
code: "circular_include",
|
|
1649
|
+
message: O("circular_include", {
|
|
1650
|
+
path: i,
|
|
1651
|
+
from: s.from,
|
|
1652
|
+
via: "include"
|
|
1653
|
+
}),
|
|
1654
|
+
path: t.path,
|
|
1655
|
+
details: {
|
|
1656
|
+
path: i,
|
|
1657
|
+
from: s.from,
|
|
1658
|
+
via: "include"
|
|
1659
|
+
}
|
|
1660
|
+
}), e = fe(e, n.marker, "");
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
t.visitStack.push(i);
|
|
1664
|
+
}
|
|
1665
|
+
try {
|
|
1666
|
+
const s = await t.loader(i), r = await Yt(s, {
|
|
1667
|
+
context: t.context,
|
|
1668
|
+
loader: t.loader,
|
|
1669
|
+
root: t.root,
|
|
1670
|
+
path: i,
|
|
1671
|
+
preserveFrontMatter: t.preserveFrontMatter,
|
|
1672
|
+
preserveHgComments: t.preserveHgComments,
|
|
1673
|
+
visitStack: t.visitStack,
|
|
1674
|
+
warnings: t.warnings,
|
|
1675
|
+
registry: t.registry
|
|
1676
|
+
}), o = t.preserveHgComments && n.raw ? `${n.raw}
|
|
1677
|
+
${r}` : r;
|
|
1678
|
+
e = fe(e, n.marker, o);
|
|
1679
|
+
} finally {
|
|
1680
|
+
t.visitStack?.pop();
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
return e;
|
|
1684
|
+
}
|
|
1685
|
+
class Le {
|
|
1686
|
+
stack = [];
|
|
1687
|
+
check(e) {
|
|
1688
|
+
return e.length === 0 ? { circular: !1 } : this.stack.indexOf(e) !== -1 ? {
|
|
1689
|
+
circular: !0,
|
|
1690
|
+
path: e,
|
|
1691
|
+
from: this.stack[this.stack.length - 1] ?? e
|
|
1692
|
+
} : { circular: !1 };
|
|
1693
|
+
}
|
|
1694
|
+
push(e) {
|
|
1695
|
+
this.stack.push(e);
|
|
1696
|
+
}
|
|
1697
|
+
pop() {
|
|
1698
|
+
this.stack.pop();
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
async function _t(t, e, n = {}) {
|
|
1702
|
+
const { path: i, constBindings: s = /* @__PURE__ */ new Set() } = n, r = await w(t.expr, { context: e, path: i });
|
|
1703
|
+
switch (t.kind) {
|
|
1704
|
+
case "const": {
|
|
1705
|
+
if (s.has(t.name))
|
|
1706
|
+
throw u({
|
|
1707
|
+
code: "parse_error",
|
|
1708
|
+
path: i,
|
|
1709
|
+
details: {
|
|
1710
|
+
message: `cannot reassign const binding: ${t.name}`
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
e[t.name] = r, s.add(t.name);
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
case "let": {
|
|
1717
|
+
e[t.name] = r;
|
|
1718
|
+
break;
|
|
1719
|
+
}
|
|
1720
|
+
case "assign": {
|
|
1721
|
+
if (s.has(t.name))
|
|
1722
|
+
throw u({
|
|
1723
|
+
code: "parse_error",
|
|
1724
|
+
path: i,
|
|
1725
|
+
details: {
|
|
1726
|
+
message: `cannot reassign const binding: ${t.name}`
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
if (!(t.name in e))
|
|
1730
|
+
throw u({
|
|
1731
|
+
code: "parse_error",
|
|
1732
|
+
path: i,
|
|
1733
|
+
details: {
|
|
1734
|
+
message: `assignment to undeclared variable: ${t.name}`
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
e[t.name] = r;
|
|
1738
|
+
break;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
function pe(t) {
|
|
1743
|
+
return !t;
|
|
1744
|
+
}
|
|
1745
|
+
async function B(t, e, n = {}) {
|
|
1746
|
+
const { path: i, constBindings: s = /* @__PURE__ */ new Set(), onUpdate: r } = n;
|
|
1747
|
+
switch (t.kind) {
|
|
1748
|
+
case "const":
|
|
1749
|
+
case "let":
|
|
1750
|
+
case "assign": {
|
|
1751
|
+
await _t(t, e, { path: i, constBindings: s }), r?.(t.name);
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
case "update": {
|
|
1755
|
+
if (s.has(t.name))
|
|
1756
|
+
throw u({
|
|
1757
|
+
code: "parse_error",
|
|
1758
|
+
path: i,
|
|
1759
|
+
details: {
|
|
1760
|
+
message: `cannot reassign const binding: ${t.name}`
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
if (!(t.name in e))
|
|
1764
|
+
throw u({
|
|
1765
|
+
code: "parse_error",
|
|
1766
|
+
path: i,
|
|
1767
|
+
details: {
|
|
1768
|
+
message: `assignment to undeclared variable: ${t.name}`
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
const o = Number(e[t.name]), a = t.op === "++" ? o + 1 : o - 1;
|
|
1772
|
+
e[t.name] = a, r?.(t.name);
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
case "compound_assign": {
|
|
1776
|
+
if (s.has(t.name))
|
|
1777
|
+
throw u({
|
|
1778
|
+
code: "parse_error",
|
|
1779
|
+
path: i,
|
|
1780
|
+
details: {
|
|
1781
|
+
message: `cannot reassign const binding: ${t.name}`
|
|
1782
|
+
}
|
|
1783
|
+
});
|
|
1784
|
+
if (!(t.name in e))
|
|
1785
|
+
throw u({
|
|
1786
|
+
code: "parse_error",
|
|
1787
|
+
path: i,
|
|
1788
|
+
details: {
|
|
1789
|
+
message: `assignment to undeclared variable: ${t.name}`
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
const o = await w(t.expr, { context: e, path: i }), a = Number(e[t.name]), c = Number(o);
|
|
1793
|
+
let h;
|
|
1794
|
+
switch (t.op) {
|
|
1795
|
+
case "+=":
|
|
1796
|
+
h = a + c;
|
|
1797
|
+
break;
|
|
1798
|
+
case "-=":
|
|
1799
|
+
h = a - c;
|
|
1800
|
+
break;
|
|
1801
|
+
case "*=":
|
|
1802
|
+
h = a * c;
|
|
1803
|
+
break;
|
|
1804
|
+
case "/=":
|
|
1805
|
+
h = a / c;
|
|
1806
|
+
break;
|
|
1807
|
+
}
|
|
1808
|
+
e[t.name] = h, r?.(t.name);
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
case "for": {
|
|
1812
|
+
for (t.init && await B(t.init, e, n); ; ) {
|
|
1813
|
+
const o = await w(t.cond, {
|
|
1814
|
+
context: e,
|
|
1815
|
+
path: i
|
|
1816
|
+
});
|
|
1817
|
+
if (pe(o))
|
|
1818
|
+
break;
|
|
1819
|
+
for (const a of t.body)
|
|
1820
|
+
await B(a, e, n);
|
|
1821
|
+
t.update && await B(t.update, e, n);
|
|
1822
|
+
}
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
case "do_while": {
|
|
1826
|
+
do {
|
|
1827
|
+
for (const a of t.body)
|
|
1828
|
+
await B(a, e, n);
|
|
1829
|
+
const o = await w(t.cond, {
|
|
1830
|
+
context: e,
|
|
1831
|
+
path: i
|
|
1832
|
+
});
|
|
1833
|
+
if (pe(o))
|
|
1834
|
+
break;
|
|
1835
|
+
} while (!0);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
async function me(t, e, n = {}) {
|
|
1841
|
+
for (const i of t)
|
|
1842
|
+
await B(i, e, n);
|
|
1843
|
+
}
|
|
1844
|
+
const St = /* @__PURE__ */ new Set([
|
|
1845
|
+
"if",
|
|
1846
|
+
"else",
|
|
1847
|
+
"endif",
|
|
1848
|
+
"const",
|
|
1849
|
+
"let",
|
|
1850
|
+
"for",
|
|
1851
|
+
"do",
|
|
1852
|
+
"while",
|
|
1853
|
+
"each",
|
|
1854
|
+
"endeach",
|
|
1855
|
+
"block",
|
|
1856
|
+
"endblock",
|
|
1857
|
+
"extend",
|
|
1858
|
+
"include",
|
|
1859
|
+
"component",
|
|
1860
|
+
"as"
|
|
1861
|
+
]);
|
|
1862
|
+
function Me(t) {
|
|
1863
|
+
return St.has(t);
|
|
1864
|
+
}
|
|
1865
|
+
function re(t) {
|
|
1866
|
+
let e = "", n = 0, i = null;
|
|
1867
|
+
for (; n < t.length; ) {
|
|
1868
|
+
const s = t[n];
|
|
1869
|
+
if (i) {
|
|
1870
|
+
if (e += s, s === "\\" && n + 1 < t.length) {
|
|
1871
|
+
e += t[++n], n++;
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
s === i && (i = null), n++;
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1877
|
+
if (s === '"' || s === "'" || s === "`") {
|
|
1878
|
+
i = s, e += s, n++;
|
|
1879
|
+
continue;
|
|
1880
|
+
}
|
|
1881
|
+
if (t.startsWith("//", n)) {
|
|
1882
|
+
for (; n < t.length && t[n] !== `
|
|
1883
|
+
`; )
|
|
1884
|
+
n++;
|
|
1885
|
+
continue;
|
|
1886
|
+
}
|
|
1887
|
+
if (t.startsWith("/*", n)) {
|
|
1888
|
+
const r = t.indexOf("*/", n + 2);
|
|
1889
|
+
if (r === -1)
|
|
1890
|
+
break;
|
|
1891
|
+
n = r + 2;
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1894
|
+
e += s, n++;
|
|
1895
|
+
}
|
|
1896
|
+
return e;
|
|
1897
|
+
}
|
|
1898
|
+
function k(t, e) {
|
|
1899
|
+
throw u({
|
|
1900
|
+
code: "parse_error",
|
|
1901
|
+
path: t,
|
|
1902
|
+
details: { message: e }
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
function ge(t, e) {
|
|
1906
|
+
const n = re(t).trim();
|
|
1907
|
+
if (n.length === 0)
|
|
1908
|
+
throw k(e, "empty statement block");
|
|
1909
|
+
const i = new se(n, e), s = i.parseStatementList();
|
|
1910
|
+
if (i.skipWhitespace(), i.hasMore())
|
|
1911
|
+
throw k(
|
|
1912
|
+
e,
|
|
1913
|
+
`unexpected token at position ${i.position}`
|
|
1914
|
+
);
|
|
1915
|
+
if (s.length === 0)
|
|
1916
|
+
throw k(e, "empty statement block");
|
|
1917
|
+
return s;
|
|
1918
|
+
}
|
|
1919
|
+
function Re(t) {
|
|
1920
|
+
const e = re(t).trim();
|
|
1921
|
+
return e.length === 0 ? !1 : /^const\s+/.test(e) || /^let\s+/.test(e) || /^for\s*\(/.test(e) || /^do\b/.test(e) || /^(\+\+|--)/.test(e) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*(\+\+|--|[+\-*/]=|=)/.test(e);
|
|
1922
|
+
}
|
|
1923
|
+
class se {
|
|
1924
|
+
constructor(e, n) {
|
|
1925
|
+
this.input = e, this.path = n;
|
|
1926
|
+
}
|
|
1927
|
+
input;
|
|
1928
|
+
path;
|
|
1929
|
+
index = 0;
|
|
1930
|
+
get position() {
|
|
1931
|
+
return this.index;
|
|
1932
|
+
}
|
|
1933
|
+
hasMore() {
|
|
1934
|
+
return this.skipWhitespace(), this.index < this.input.length;
|
|
1935
|
+
}
|
|
1936
|
+
skipWhitespace() {
|
|
1937
|
+
for (; this.index < this.input.length && /\s/.test(this.input[this.index]); )
|
|
1938
|
+
this.index++;
|
|
1939
|
+
}
|
|
1940
|
+
parseStatementList() {
|
|
1941
|
+
const e = [];
|
|
1942
|
+
for (; this.hasMore() && this.peek() !== "}"; )
|
|
1943
|
+
e.push(this.parseStatement()), this.skipOptionalSemicolon();
|
|
1944
|
+
return e;
|
|
1945
|
+
}
|
|
1946
|
+
parseStatement() {
|
|
1947
|
+
if (this.skipWhitespace(), this.matchWord("for"))
|
|
1948
|
+
return this.parseFor();
|
|
1949
|
+
if (this.matchWord("do"))
|
|
1950
|
+
return this.parseDoWhile();
|
|
1951
|
+
if (this.matchWord("while"))
|
|
1952
|
+
throw k(
|
|
1953
|
+
this.path,
|
|
1954
|
+
"bare while loops are not allowed (use do…while)"
|
|
1955
|
+
);
|
|
1956
|
+
return this.parseSimpleStatement();
|
|
1957
|
+
}
|
|
1958
|
+
parseSimpleStatement() {
|
|
1959
|
+
this.skipWhitespace();
|
|
1960
|
+
const e = this.readPrefixUpdate();
|
|
1961
|
+
if (e)
|
|
1962
|
+
return e;
|
|
1963
|
+
if (this.matchWord("const"))
|
|
1964
|
+
return this.parseBindingDeclaration("const");
|
|
1965
|
+
if (this.matchWord("let"))
|
|
1966
|
+
return this.parseBindingDeclaration("let");
|
|
1967
|
+
const n = this.readIdentifier();
|
|
1968
|
+
if (!n)
|
|
1969
|
+
throw k(this.path, "expected statement");
|
|
1970
|
+
if (this.assertAssignableName(n), this.skipWhitespace(), this.match("++") || this.match("--")) {
|
|
1971
|
+
const s = this.input.slice(this.index - 2, this.index);
|
|
1972
|
+
return { kind: "update", name: n, op: s, position: "postfix" };
|
|
1973
|
+
}
|
|
1974
|
+
const i = this.readCompoundOp();
|
|
1975
|
+
if (i) {
|
|
1976
|
+
const s = this.readExpressionSourceUntilTerminator();
|
|
1977
|
+
return {
|
|
1978
|
+
kind: "compound_assign",
|
|
1979
|
+
name: n,
|
|
1980
|
+
op: i,
|
|
1981
|
+
expr: C(s, this.path)
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
if (this.match("=")) {
|
|
1985
|
+
if (this.peek() === "=")
|
|
1986
|
+
throw k(this.path, "unexpected '==' in assignment");
|
|
1987
|
+
const s = this.readExpressionSourceUntilTerminator();
|
|
1988
|
+
return {
|
|
1989
|
+
kind: "assign",
|
|
1990
|
+
name: n,
|
|
1991
|
+
expr: C(s, this.path)
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
throw k(this.path, `invalid statement starting with: ${n}`);
|
|
1995
|
+
}
|
|
1996
|
+
readPrefixUpdate() {
|
|
1997
|
+
if (this.skipWhitespace(), this.match("++") || this.match("--")) {
|
|
1998
|
+
const e = this.input.slice(this.index - 2, this.index), n = this.readIdentifier();
|
|
1999
|
+
if (!n)
|
|
2000
|
+
throw k(this.path, `expected identifier after ${e}`);
|
|
2001
|
+
return this.assertAssignableName(n), { kind: "update", name: n, op: e, position: "prefix" };
|
|
2002
|
+
}
|
|
2003
|
+
return null;
|
|
2004
|
+
}
|
|
2005
|
+
parseBindingDeclaration(e) {
|
|
2006
|
+
const n = this.readIdentifier();
|
|
2007
|
+
if (!n)
|
|
2008
|
+
throw k(this.path, `expected identifier after ${e}`);
|
|
2009
|
+
if (this.assertAssignableName(n), this.skipWhitespace(), !this.match("="))
|
|
2010
|
+
throw k(this.path, `expected '=' in ${e} declaration`);
|
|
2011
|
+
const i = this.readExpressionSourceUntilTerminator();
|
|
2012
|
+
return {
|
|
2013
|
+
kind: e,
|
|
2014
|
+
name: n,
|
|
2015
|
+
expr: C(i, this.path)
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
parseFor() {
|
|
2019
|
+
if (this.skipWhitespace(), !this.match("("))
|
|
2020
|
+
throw k(this.path, "expected '(' after for");
|
|
2021
|
+
const e = this.readBalanced(")"), n = Ct(e);
|
|
2022
|
+
if (n.length !== 3)
|
|
2023
|
+
throw k(
|
|
2024
|
+
this.path,
|
|
2025
|
+
"for…of / for…in are not allowed; use for (init; cond; update)"
|
|
2026
|
+
);
|
|
2027
|
+
const [i, s, r] = n;
|
|
2028
|
+
if (s.trim().length === 0)
|
|
2029
|
+
throw k(this.path, "for loop condition cannot be empty");
|
|
2030
|
+
if (/^\s*[A-Za-z_$][A-Za-z0-9_$]*\s+(of|in)\s+/.test(i))
|
|
2031
|
+
throw k(
|
|
2032
|
+
this.path,
|
|
2033
|
+
"for…of / for…in are not allowed; use for (init; cond; update)"
|
|
2034
|
+
);
|
|
2035
|
+
const o = i.trim().length === 0 ? null : this.parseClauseStatement(i.trim()), a = C(s.trim(), this.path), c = r.trim().length === 0 ? null : this.parseClauseStatement(r.trim());
|
|
2036
|
+
if (this.skipWhitespace(), !this.match("{"))
|
|
2037
|
+
throw k(this.path, "expected '{' after for (...)");
|
|
2038
|
+
const h = this.parseStatementList();
|
|
2039
|
+
if (this.skipWhitespace(), !this.match("}"))
|
|
2040
|
+
throw k(this.path, "expected '}' to close for body");
|
|
2041
|
+
return { kind: "for", init: o, cond: a, update: c, body: h };
|
|
2042
|
+
}
|
|
2043
|
+
parseDoWhile() {
|
|
2044
|
+
if (this.skipWhitespace(), !this.match("{"))
|
|
2045
|
+
throw k(this.path, "expected '{' after do");
|
|
2046
|
+
const e = this.parseStatementList();
|
|
2047
|
+
if (this.skipWhitespace(), !this.match("}"))
|
|
2048
|
+
throw k(this.path, "expected '}' to close do body");
|
|
2049
|
+
if (this.skipWhitespace(), !this.matchWord("while"))
|
|
2050
|
+
throw k(this.path, "expected 'while' after do body");
|
|
2051
|
+
if (this.skipWhitespace(), !this.match("("))
|
|
2052
|
+
throw k(this.path, "expected '(' after while");
|
|
2053
|
+
const n = this.readBalanced(")");
|
|
2054
|
+
if (n.trim().length === 0)
|
|
2055
|
+
throw k(this.path, "do…while condition cannot be empty");
|
|
2056
|
+
const i = C(n.trim(), this.path);
|
|
2057
|
+
return { kind: "do_while", body: e, cond: i };
|
|
2058
|
+
}
|
|
2059
|
+
parseClauseStatement(e) {
|
|
2060
|
+
const n = new se(e, this.path), i = n.parseSimpleStatement();
|
|
2061
|
+
if (n.skipWhitespace(), n.hasMore())
|
|
2062
|
+
throw k(
|
|
2063
|
+
this.path,
|
|
2064
|
+
`unexpected token in for clause at position ${n.position}`
|
|
2065
|
+
);
|
|
2066
|
+
return i;
|
|
2067
|
+
}
|
|
2068
|
+
assertAssignableName(e) {
|
|
2069
|
+
if (Me(e))
|
|
2070
|
+
throw k(
|
|
2071
|
+
this.path,
|
|
2072
|
+
`reserved word cannot be used as identifier: ${e}`
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
readExpressionSourceUntilTerminator() {
|
|
2076
|
+
this.skipWhitespace();
|
|
2077
|
+
const e = this.index;
|
|
2078
|
+
let n = 0, i = 0, s = 0, r = null;
|
|
2079
|
+
for (; this.index < this.input.length; ) {
|
|
2080
|
+
const a = this.input[this.index];
|
|
2081
|
+
if (r) {
|
|
2082
|
+
if (a === "\\") {
|
|
2083
|
+
this.index += 2;
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
a === r && (r = null), this.index++;
|
|
2087
|
+
continue;
|
|
2088
|
+
}
|
|
2089
|
+
if (a === '"' || a === "'" || a === "`") {
|
|
2090
|
+
r = a, this.index++;
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
if (a === "(" && n++, a === ")" && (n = Math.max(0, n - 1)), a === "{" && i++, a === "}") {
|
|
2094
|
+
if (i === 0 && n === 0 && s === 0)
|
|
2095
|
+
break;
|
|
2096
|
+
i = Math.max(0, i - 1);
|
|
2097
|
+
}
|
|
2098
|
+
if (a === "[" && s++, a === "]" && (s = Math.max(0, s - 1)), (a === ";" || a === `
|
|
2099
|
+
`) && n === 0 && i === 0 && s === 0)
|
|
2100
|
+
break;
|
|
2101
|
+
this.index++;
|
|
2102
|
+
}
|
|
2103
|
+
const o = this.input.slice(e, this.index).trim();
|
|
2104
|
+
if (o.length === 0)
|
|
2105
|
+
throw k(this.path, "expected expression");
|
|
2106
|
+
return o;
|
|
2107
|
+
}
|
|
2108
|
+
readBalanced(e) {
|
|
2109
|
+
const n = e === ")" ? "(" : "{";
|
|
2110
|
+
let i = 1;
|
|
2111
|
+
const s = this.index;
|
|
2112
|
+
let r = null;
|
|
2113
|
+
for (; this.index < this.input.length; ) {
|
|
2114
|
+
const o = this.input[this.index];
|
|
2115
|
+
if (r) {
|
|
2116
|
+
if (o === "\\") {
|
|
2117
|
+
this.index += 2;
|
|
2118
|
+
continue;
|
|
2119
|
+
}
|
|
2120
|
+
o === r && (r = null), this.index++;
|
|
2121
|
+
continue;
|
|
2122
|
+
}
|
|
2123
|
+
if (o === '"' || o === "'" || o === "`") {
|
|
2124
|
+
r = o, this.index++;
|
|
2125
|
+
continue;
|
|
2126
|
+
}
|
|
2127
|
+
if (o === n) {
|
|
2128
|
+
i++, this.index++;
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
if (o === e) {
|
|
2132
|
+
if (i--, i === 0) {
|
|
2133
|
+
const a = this.input.slice(s, this.index);
|
|
2134
|
+
return this.index++, a;
|
|
2135
|
+
}
|
|
2136
|
+
this.index++;
|
|
2137
|
+
continue;
|
|
2138
|
+
}
|
|
2139
|
+
this.index++;
|
|
2140
|
+
}
|
|
2141
|
+
throw k(this.path, `expected '${e}'`);
|
|
2142
|
+
}
|
|
2143
|
+
readCompoundOp() {
|
|
2144
|
+
this.skipWhitespace();
|
|
2145
|
+
const e = ["+=", "-=", "*=", "/="];
|
|
2146
|
+
for (const n of e)
|
|
2147
|
+
if (this.match(n))
|
|
2148
|
+
return n;
|
|
2149
|
+
return null;
|
|
2150
|
+
}
|
|
2151
|
+
skipOptionalSemicolon() {
|
|
2152
|
+
this.skipWhitespace(), this.peek() === ";" && this.index++;
|
|
2153
|
+
}
|
|
2154
|
+
match(e) {
|
|
2155
|
+
return this.skipWhitespace(), this.input.startsWith(e, this.index) ? (this.index += e.length, !0) : !1;
|
|
2156
|
+
}
|
|
2157
|
+
matchWord(e) {
|
|
2158
|
+
if (this.skipWhitespace(), !this.input.startsWith(e, this.index))
|
|
2159
|
+
return !1;
|
|
2160
|
+
const n = this.input[this.index + e.length];
|
|
2161
|
+
return n && /[A-Za-z0-9_$]/.test(n) ? !1 : (this.index += e.length, !0);
|
|
2162
|
+
}
|
|
2163
|
+
peek() {
|
|
2164
|
+
return this.input[this.index] ?? "";
|
|
2165
|
+
}
|
|
2166
|
+
readIdentifier() {
|
|
2167
|
+
this.skipWhitespace();
|
|
2168
|
+
const e = this.index, n = this.peek();
|
|
2169
|
+
if (!/[A-Za-z_$]/.test(n))
|
|
2170
|
+
return "";
|
|
2171
|
+
for (this.index++; this.index < this.input.length && /[A-Za-z0-9_$]/.test(this.input[this.index]); )
|
|
2172
|
+
this.index++;
|
|
2173
|
+
return this.input.slice(e, this.index);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
function Ct(t) {
|
|
2177
|
+
const e = [];
|
|
2178
|
+
let n = "", i = 0, s = null;
|
|
2179
|
+
for (let r = 0; r < t.length; r++) {
|
|
2180
|
+
const o = t[r];
|
|
2181
|
+
if (s) {
|
|
2182
|
+
if (n += o, o === "\\" && r + 1 < t.length) {
|
|
2183
|
+
n += t[++r];
|
|
2184
|
+
continue;
|
|
2185
|
+
}
|
|
2186
|
+
o === s && (s = null);
|
|
2187
|
+
continue;
|
|
2188
|
+
}
|
|
2189
|
+
if (o === '"' || o === "'" || o === "`") {
|
|
2190
|
+
s = o, n += o;
|
|
2191
|
+
continue;
|
|
2192
|
+
}
|
|
2193
|
+
if (o === "(" || o === "[" || o === "{") {
|
|
2194
|
+
i++, n += o;
|
|
2195
|
+
continue;
|
|
2196
|
+
}
|
|
2197
|
+
if (o === ")" || o === "]" || o === "}") {
|
|
2198
|
+
i = Math.max(0, i - 1), n += o;
|
|
2199
|
+
continue;
|
|
2200
|
+
}
|
|
2201
|
+
if (o === ";" && i === 0) {
|
|
2202
|
+
e.push(n), n = "";
|
|
2203
|
+
continue;
|
|
2204
|
+
}
|
|
2205
|
+
n += o;
|
|
2206
|
+
}
|
|
2207
|
+
return e.push(n), e;
|
|
2208
|
+
}
|
|
2209
|
+
function oe(t, e) {
|
|
2210
|
+
const n = t.trim();
|
|
2211
|
+
if (!/^extend\b/i.test(n)) return null;
|
|
2212
|
+
if (!/^extend\s+/i.test(n))
|
|
2213
|
+
throw u({
|
|
2214
|
+
code: "parse_error",
|
|
2215
|
+
path: e,
|
|
2216
|
+
details: { message: "missing extend path" }
|
|
2217
|
+
});
|
|
2218
|
+
const i = /^extend\s+(\S+)\s*$/.exec(n);
|
|
2219
|
+
if (!i)
|
|
2220
|
+
throw u({
|
|
2221
|
+
code: "parse_error",
|
|
2222
|
+
path: e,
|
|
2223
|
+
details: { message: "invalid extend directive" }
|
|
2224
|
+
});
|
|
2225
|
+
const s = i[1];
|
|
2226
|
+
if (s.length === 0)
|
|
2227
|
+
throw u({
|
|
2228
|
+
code: "parse_error",
|
|
2229
|
+
path: e,
|
|
2230
|
+
details: { message: "invalid extend path" }
|
|
2231
|
+
});
|
|
2232
|
+
return { path: s };
|
|
2233
|
+
}
|
|
2234
|
+
function At(t, e) {
|
|
2235
|
+
const n = E(t);
|
|
2236
|
+
if (n.length === 0) return null;
|
|
2237
|
+
const i = n[0], s = oe(i, e);
|
|
2238
|
+
if (!s) return null;
|
|
2239
|
+
for (const r of n.slice(1))
|
|
2240
|
+
if (/^extend\s+/i.test(r))
|
|
2241
|
+
throw u({
|
|
2242
|
+
code: "parse_error",
|
|
2243
|
+
path: e,
|
|
2244
|
+
details: { message: "extend must be the first line of extend block" }
|
|
2245
|
+
});
|
|
2246
|
+
return {
|
|
2247
|
+
path: s.path,
|
|
2248
|
+
declarationsSource: n.slice(1).join(`
|
|
2249
|
+
`)
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
async function Wt(t, e = {}) {
|
|
2253
|
+
const n = e.path, i = e.context ?? {};
|
|
2254
|
+
if (Se(t))
|
|
2255
|
+
throw u({
|
|
2256
|
+
code: "parse_error",
|
|
2257
|
+
path: n,
|
|
2258
|
+
details: {
|
|
2259
|
+
message: Ce(t) ?? "unclosed hyogen block (missing closing marker)"
|
|
2260
|
+
}
|
|
2261
|
+
});
|
|
2262
|
+
const s = T(t);
|
|
2263
|
+
if (s.length === 0)
|
|
2264
|
+
return { source: t, context: i, declarationUpdates: {} };
|
|
2265
|
+
const r = /* @__PURE__ */ new Set(), o = {}, a = (l) => {
|
|
2266
|
+
o[l] = i[l];
|
|
2267
|
+
};
|
|
2268
|
+
let c = t, h = 0;
|
|
2269
|
+
for (const l of s) {
|
|
2270
|
+
const d = E(l.inner);
|
|
2271
|
+
if (d.length === 1 && Ae(d[0]) || d.length === 1 && /^include\s+/i.test(d[0]) || d.length === 1 && /^component\s+/i.test(d[0]))
|
|
2272
|
+
continue;
|
|
2273
|
+
const f = At(l.inner, n);
|
|
2274
|
+
if (f) {
|
|
2275
|
+
if (f.declarationsSource.trim().length > 0) {
|
|
2276
|
+
const P = ge(
|
|
2277
|
+
f.declarationsSource,
|
|
2278
|
+
n
|
|
2279
|
+
);
|
|
2280
|
+
await me(P, i, {
|
|
2281
|
+
path: n,
|
|
2282
|
+
constBindings: r,
|
|
2283
|
+
onUpdate: a
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
const v = l.start - h, W = l.end - h, $ = `<!--@hg
|
|
2287
|
+
extend ${f.path}
|
|
2288
|
+
@endhg-->`;
|
|
2289
|
+
c = c.slice(0, v) + $ + c.slice(W), h += l.raw.length - $.length;
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
const g = d.join(`
|
|
2293
|
+
`);
|
|
2294
|
+
if (!Re(g)) {
|
|
2295
|
+
if (d.length === 1)
|
|
2296
|
+
continue;
|
|
2297
|
+
throw u({
|
|
2298
|
+
code: "parse_error",
|
|
2299
|
+
path: n,
|
|
2300
|
+
details: { message: `unsupported hyogen directive: ${d[0]}` }
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
const m = ge(g, n);
|
|
2304
|
+
await me(m, i, {
|
|
2305
|
+
path: n,
|
|
2306
|
+
constBindings: r,
|
|
2307
|
+
onUpdate: a
|
|
2308
|
+
});
|
|
2309
|
+
const p = l.start - h, A = l.end - h, L = c.slice(0, p), b = c.slice(A);
|
|
2310
|
+
c = D(L, b), h += l.raw.length + ie(L, b);
|
|
2311
|
+
}
|
|
2312
|
+
return { source: c, context: i, declarationUpdates: o };
|
|
2313
|
+
}
|
|
2314
|
+
const $t = /^component\s+(\S+)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*$/;
|
|
2315
|
+
function Tt(t, e) {
|
|
2316
|
+
const n = Q(t).trim();
|
|
2317
|
+
if (n.length === 0)
|
|
2318
|
+
throw u({
|
|
2319
|
+
code: "parse_error",
|
|
2320
|
+
path: e,
|
|
2321
|
+
details: { message: "empty hyogen block" }
|
|
2322
|
+
});
|
|
2323
|
+
const i = n.split(/\r?\n/).map((a) => a.trim()).filter((a) => a.length > 0);
|
|
2324
|
+
if (i.length !== 1)
|
|
2325
|
+
throw u({
|
|
2326
|
+
code: "parse_error",
|
|
2327
|
+
path: e,
|
|
2328
|
+
details: {
|
|
2329
|
+
message: "hyogen block must contain a single component directive"
|
|
2330
|
+
}
|
|
2331
|
+
});
|
|
2332
|
+
const s = i[0];
|
|
2333
|
+
if (/^include\s+/i.test(s))
|
|
2334
|
+
throw u({
|
|
2335
|
+
code: "parse_error",
|
|
2336
|
+
path: e,
|
|
2337
|
+
details: { message: "include and component cannot coexist in one block" }
|
|
2338
|
+
});
|
|
2339
|
+
const r = $t.exec(s);
|
|
2340
|
+
if (!r)
|
|
2341
|
+
throw u({
|
|
2342
|
+
code: "parse_error",
|
|
2343
|
+
path: e,
|
|
2344
|
+
details: { message: `unsupported component directive: ${s}` }
|
|
2345
|
+
});
|
|
2346
|
+
const o = r[1];
|
|
2347
|
+
if (o.length === 0)
|
|
2348
|
+
throw u({
|
|
2349
|
+
code: "parse_error",
|
|
2350
|
+
path: e,
|
|
2351
|
+
details: { message: "empty component path" }
|
|
2352
|
+
});
|
|
2353
|
+
return {
|
|
2354
|
+
kind: "component",
|
|
2355
|
+
path: o,
|
|
2356
|
+
alias: r[2]
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
function Et(t, e) {
|
|
2360
|
+
const n = Q(t).trim();
|
|
2361
|
+
if (n.length === 0)
|
|
2362
|
+
throw u({
|
|
2363
|
+
code: "parse_error",
|
|
2364
|
+
path: e,
|
|
2365
|
+
details: { message: "empty hyogen block" }
|
|
2366
|
+
});
|
|
2367
|
+
const i = n.split(/\r?\n/).map((o) => o.trim()).filter((o) => o.length > 0);
|
|
2368
|
+
if (i.length !== 1)
|
|
2369
|
+
throw u({
|
|
2370
|
+
code: "parse_error",
|
|
2371
|
+
path: e,
|
|
2372
|
+
details: { message: "hyogen block must contain a single include directive" }
|
|
2373
|
+
});
|
|
2374
|
+
const s = i[0], r = /^include\s+(\S+)\s*$/.exec(s);
|
|
2375
|
+
if (r)
|
|
2376
|
+
return { kind: "include", path: r[1] };
|
|
2377
|
+
throw u({
|
|
2378
|
+
code: "parse_error",
|
|
2379
|
+
path: e,
|
|
2380
|
+
details: { message: `unsupported hyogen directive: ${s}` }
|
|
2381
|
+
});
|
|
2382
|
+
}
|
|
2383
|
+
function Lt(t) {
|
|
2384
|
+
const e = re(t).trim();
|
|
2385
|
+
return e.length === 0 ? !1 : /^const\s+/.test(e) || /^let\s+/.test(e) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*=/.test(e);
|
|
2386
|
+
}
|
|
2387
|
+
const Mt = "\0HYOGEN_INCLUDE_";
|
|
2388
|
+
function Rt(t) {
|
|
2389
|
+
return `${Mt}${t}\0`;
|
|
2390
|
+
}
|
|
2391
|
+
function Ot(t, e) {
|
|
2392
|
+
const n = E(t);
|
|
2393
|
+
if (n.length === 1 && Ae(n[0]))
|
|
2394
|
+
return { kind: "control" };
|
|
2395
|
+
if (n.length === 1 && (Lt(n[0]) || Re(n[0])))
|
|
2396
|
+
return null;
|
|
2397
|
+
if (n.length !== 1)
|
|
2398
|
+
throw u({
|
|
2399
|
+
code: "parse_error",
|
|
2400
|
+
path: e,
|
|
2401
|
+
details: { message: "hyogen block must contain a single directive" }
|
|
2402
|
+
});
|
|
2403
|
+
const i = n[0];
|
|
2404
|
+
if (/^include\s+/i.test(i) && /\bcomponent\s+/i.test(i))
|
|
2405
|
+
throw u({
|
|
2406
|
+
code: "parse_error",
|
|
2407
|
+
path: e,
|
|
2408
|
+
details: { message: "include and component cannot coexist in one block" }
|
|
2409
|
+
});
|
|
2410
|
+
if (/^include\s+/i.test(i))
|
|
2411
|
+
return Et(t, e);
|
|
2412
|
+
if (/^component\s+/i.test(i))
|
|
2413
|
+
return Tt(t, e);
|
|
2414
|
+
if (i === "endblock" || /^block\s+/.test(i) || /^extend\s+/.test(i))
|
|
2415
|
+
return null;
|
|
2416
|
+
throw u({
|
|
2417
|
+
code: "parse_error",
|
|
2418
|
+
path: e,
|
|
2419
|
+
details: { message: `unsupported hyogen directive: ${i}` }
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
function Dt(t, e = {}) {
|
|
2423
|
+
const n = e.path;
|
|
2424
|
+
if (Se(t))
|
|
2425
|
+
throw u({
|
|
2426
|
+
code: "parse_error",
|
|
2427
|
+
path: n,
|
|
2428
|
+
details: {
|
|
2429
|
+
message: Ce(t) ?? "unclosed hyogen block (missing closing marker)"
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
const i = T(t);
|
|
2433
|
+
if (i.length === 0)
|
|
2434
|
+
return { source: t, directives: [] };
|
|
2435
|
+
const s = [];
|
|
2436
|
+
let r = t, o = 0, a = 0;
|
|
2437
|
+
for (const c of i) {
|
|
2438
|
+
const h = Ot(c.inner, n);
|
|
2439
|
+
if (!h || h.kind === "control")
|
|
2440
|
+
continue;
|
|
2441
|
+
const l = c.start - o, d = c.end - o;
|
|
2442
|
+
if (h.kind === "component") {
|
|
2443
|
+
e.registry && e.registry.register(
|
|
2444
|
+
{
|
|
2445
|
+
alias: h.alias,
|
|
2446
|
+
componentPath: h.path,
|
|
2447
|
+
definedAt: n
|
|
2448
|
+
},
|
|
2449
|
+
Object.keys(e.context ?? {}),
|
|
2450
|
+
n
|
|
2451
|
+
);
|
|
2452
|
+
const g = r.slice(0, l), m = r.slice(d);
|
|
2453
|
+
r = D(g, m), o += c.raw.length + ie(g, m);
|
|
2454
|
+
continue;
|
|
2455
|
+
}
|
|
2456
|
+
const f = Rt(a++);
|
|
2457
|
+
s.push({ ...h, marker: f, raw: c.raw }), r = r.slice(0, l) + f + r.slice(d), o += c.raw.length - f.length;
|
|
2458
|
+
}
|
|
2459
|
+
return { source: r, directives: s };
|
|
2460
|
+
}
|
|
2461
|
+
function Bt(t, e) {
|
|
2462
|
+
return !e.preserveFrontMatter || !e.rawFrontMatter ? t : t.length === 0 ? `${e.rawFrontMatter}
|
|
2463
|
+
` : `${e.rawFrontMatter}
|
|
2464
|
+
${t}`;
|
|
2465
|
+
}
|
|
2466
|
+
function jt(t, e = !1) {
|
|
2467
|
+
if (e)
|
|
2468
|
+
return t;
|
|
2469
|
+
const n = T(t);
|
|
2470
|
+
if (n.length === 0)
|
|
2471
|
+
return t;
|
|
2472
|
+
let i = t, s = 0;
|
|
2473
|
+
for (const r of n) {
|
|
2474
|
+
const o = r.start - s, a = r.end - s, c = i.slice(0, o), h = i.slice(a);
|
|
2475
|
+
i = D(c, h), s += r.raw.length + ie(c, h);
|
|
2476
|
+
}
|
|
2477
|
+
return i;
|
|
2478
|
+
}
|
|
2479
|
+
const Nt = /^block\s+([A-Za-z_$][A-Za-z0-9_$]*)$/;
|
|
2480
|
+
function Ht(t, e) {
|
|
2481
|
+
const n = t.trim();
|
|
2482
|
+
if (n === "endblock")
|
|
2483
|
+
return { kind: "endblock" };
|
|
2484
|
+
const i = Nt.exec(n);
|
|
2485
|
+
if (!i)
|
|
2486
|
+
throw u({
|
|
2487
|
+
code: "parse_error",
|
|
2488
|
+
path: e,
|
|
2489
|
+
details: { message: "invalid block directive" }
|
|
2490
|
+
});
|
|
2491
|
+
const s = i[1];
|
|
2492
|
+
if (Me(s))
|
|
2493
|
+
throw u({
|
|
2494
|
+
code: "parse_error",
|
|
2495
|
+
path: e,
|
|
2496
|
+
details: { message: `reserved word cannot be used as block name: ${s}` }
|
|
2497
|
+
});
|
|
2498
|
+
return { kind: "block", name: s };
|
|
2499
|
+
}
|
|
2500
|
+
function xe(t, e) {
|
|
2501
|
+
const { path: n, mode: i, hasExtend: s = !1 } = e, r = T(t);
|
|
2502
|
+
if (r.length === 0) return [];
|
|
2503
|
+
const o = [], a = [], c = /* @__PURE__ */ new Set();
|
|
2504
|
+
for (const h of r) {
|
|
2505
|
+
const l = E(h.inner);
|
|
2506
|
+
if (l.length !== 1) continue;
|
|
2507
|
+
const d = l[0];
|
|
2508
|
+
if (!(d === "endblock" || d.startsWith("block "))) continue;
|
|
2509
|
+
if (i === "child" && !s)
|
|
2510
|
+
throw u({
|
|
2511
|
+
code: "parse_error",
|
|
2512
|
+
path: n,
|
|
2513
|
+
details: { message: "orphan block without extend" }
|
|
2514
|
+
});
|
|
2515
|
+
const g = Ht(d, n);
|
|
2516
|
+
if (g.kind === "endblock") {
|
|
2517
|
+
const m = a.pop();
|
|
2518
|
+
if (!m)
|
|
2519
|
+
throw u({
|
|
2520
|
+
code: "parse_error",
|
|
2521
|
+
path: n,
|
|
2522
|
+
details: { message: "endblock without matching block opener" }
|
|
2523
|
+
});
|
|
2524
|
+
const p = t.slice(m.openerEnd, h.start);
|
|
2525
|
+
o.push({
|
|
2526
|
+
name: m.name,
|
|
2527
|
+
body: p,
|
|
2528
|
+
start: m.start,
|
|
2529
|
+
end: h.end
|
|
2530
|
+
});
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
if (a.length > 0)
|
|
2534
|
+
throw u({
|
|
2535
|
+
code: "parse_error",
|
|
2536
|
+
path: n,
|
|
2537
|
+
details: { message: "nested block structures are not supported" }
|
|
2538
|
+
});
|
|
2539
|
+
if (c.has(g.name))
|
|
2540
|
+
throw u({
|
|
2541
|
+
code: "parse_error",
|
|
2542
|
+
path: n,
|
|
2543
|
+
details: { message: `duplicate block: ${g.name}` }
|
|
2544
|
+
});
|
|
2545
|
+
c.add(g.name), a.push({
|
|
2546
|
+
name: g.name,
|
|
2547
|
+
openerEnd: h.end,
|
|
2548
|
+
start: h.start
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
if (a.length > 0)
|
|
2552
|
+
throw u({
|
|
2553
|
+
code: "parse_error",
|
|
2554
|
+
path: n,
|
|
2555
|
+
details: { message: "missing endblock" }
|
|
2556
|
+
});
|
|
2557
|
+
return o;
|
|
2558
|
+
}
|
|
2559
|
+
function ke(t) {
|
|
2560
|
+
const e = T(t), n = [];
|
|
2561
|
+
for (const i of e) {
|
|
2562
|
+
const s = E(i.inner);
|
|
2563
|
+
if (s.length === 0) continue;
|
|
2564
|
+
const r = oe(s[0]);
|
|
2565
|
+
r && n.push({ path: r.path, start: i.start });
|
|
2566
|
+
}
|
|
2567
|
+
return n;
|
|
2568
|
+
}
|
|
2569
|
+
function Pt(t) {
|
|
2570
|
+
const e = T(t);
|
|
2571
|
+
for (const n of e) {
|
|
2572
|
+
const i = E(n.inner);
|
|
2573
|
+
if (i.length !== 1) continue;
|
|
2574
|
+
const s = i[0];
|
|
2575
|
+
if (s === "endblock" || s.startsWith("block ")) return !0;
|
|
2576
|
+
}
|
|
2577
|
+
return !1;
|
|
2578
|
+
}
|
|
2579
|
+
function K(t) {
|
|
2580
|
+
return t.map((e) => e.body).join("");
|
|
2581
|
+
}
|
|
2582
|
+
function Ft(t, e, n) {
|
|
2583
|
+
const i = [...e].sort((o, a) => o.start - a.start), s = [];
|
|
2584
|
+
let r = 0;
|
|
2585
|
+
for (const o of i)
|
|
2586
|
+
s.push(t.slice(r, o.start)), s.push(n.get(o.name) ?? o.body), r = o.end;
|
|
2587
|
+
return s.push(t.slice(r)), s.reduce((o, a) => D(o, a));
|
|
2588
|
+
}
|
|
2589
|
+
function It(t) {
|
|
2590
|
+
if (t instanceof Error && "code" in t && "details" in t) {
|
|
2591
|
+
const e = t;
|
|
2592
|
+
if (e.code === "file_not_found" && e.details && e.details.via === "include")
|
|
2593
|
+
return e.details.via = "extend", { errorToThrow: e, adjusted: !0 };
|
|
2594
|
+
}
|
|
2595
|
+
return { errorToThrow: t, adjusted: !1 };
|
|
2596
|
+
}
|
|
2597
|
+
async function zt(t, e) {
|
|
2598
|
+
const {
|
|
2599
|
+
path: n,
|
|
2600
|
+
context: i,
|
|
2601
|
+
declarationUpdates: s,
|
|
2602
|
+
loader: r,
|
|
2603
|
+
root: o,
|
|
2604
|
+
constrainToRoot: a,
|
|
2605
|
+
visitStack: c,
|
|
2606
|
+
warnings: h,
|
|
2607
|
+
inComponent: l = !1
|
|
2608
|
+
} = e, d = ke(t);
|
|
2609
|
+
if (d.length === 0) {
|
|
2610
|
+
if (Pt(t))
|
|
2611
|
+
throw u({
|
|
2612
|
+
code: "parse_error",
|
|
2613
|
+
path: n,
|
|
2614
|
+
details: { message: "orphan block without extend" }
|
|
2615
|
+
});
|
|
2616
|
+
return { source: t, context: _(i, s) };
|
|
2617
|
+
}
|
|
2618
|
+
const g = T(t)[0];
|
|
2619
|
+
if (!g)
|
|
2620
|
+
return { source: t, context: _(i, s) };
|
|
2621
|
+
if (!r)
|
|
2622
|
+
throw new Error("loader is required when processing extend directives");
|
|
2623
|
+
const m = E(g.inner);
|
|
2624
|
+
if (!(m.length > 0 ? oe(m[0]) : null))
|
|
2625
|
+
throw u({
|
|
2626
|
+
code: "parse_error",
|
|
2627
|
+
path: n,
|
|
2628
|
+
details: { message: "extend must be the first hyogen block" }
|
|
2629
|
+
});
|
|
2630
|
+
if (d.length > 1)
|
|
2631
|
+
throw u({
|
|
2632
|
+
code: "parse_error",
|
|
2633
|
+
path: n,
|
|
2634
|
+
details: { message: "multiple extend directives are not supported" }
|
|
2635
|
+
});
|
|
2636
|
+
const A = xe(t, {
|
|
2637
|
+
path: n,
|
|
2638
|
+
mode: "child",
|
|
2639
|
+
hasExtend: !0
|
|
2640
|
+
});
|
|
2641
|
+
if (l)
|
|
2642
|
+
return h?.push({
|
|
2643
|
+
code: "extend_in_component",
|
|
2644
|
+
message: O("extend_in_component", { path: n }),
|
|
2645
|
+
path: n,
|
|
2646
|
+
details: { path: n }
|
|
2647
|
+
}), {
|
|
2648
|
+
source: K(A),
|
|
2649
|
+
context: _(i, s)
|
|
2650
|
+
};
|
|
2651
|
+
const L = d[0].path, b = n, v = Y(
|
|
2652
|
+
o,
|
|
2653
|
+
L,
|
|
2654
|
+
n,
|
|
2655
|
+
n,
|
|
2656
|
+
a,
|
|
2657
|
+
!0
|
|
2658
|
+
);
|
|
2659
|
+
b && c.push(b);
|
|
2660
|
+
try {
|
|
2661
|
+
const W = b ? c.check(v) : { circular: !1 };
|
|
2662
|
+
if (W.circular)
|
|
2663
|
+
return h?.push({
|
|
2664
|
+
code: "circular_include",
|
|
2665
|
+
message: O("circular_include", {
|
|
2666
|
+
path: v,
|
|
2667
|
+
from: W.from,
|
|
2668
|
+
via: "extend"
|
|
2669
|
+
}),
|
|
2670
|
+
path: n,
|
|
2671
|
+
details: { path: v, from: W.from, via: "extend" }
|
|
2672
|
+
}), {
|
|
2673
|
+
source: K(A),
|
|
2674
|
+
context: _(i, s)
|
|
2675
|
+
};
|
|
2676
|
+
c.push(v);
|
|
2677
|
+
try {
|
|
2678
|
+
const $ = await r(v);
|
|
2679
|
+
if ($ === void 0)
|
|
2680
|
+
throw new Error("loader returned undefined");
|
|
2681
|
+
const { context: P, body: F } = H(
|
|
2682
|
+
$,
|
|
2683
|
+
v
|
|
2684
|
+
), ce = ke(F);
|
|
2685
|
+
if (ce.length > 0) {
|
|
2686
|
+
const N = ce[0].path, I = Y(
|
|
2687
|
+
o,
|
|
2688
|
+
N,
|
|
2689
|
+
v,
|
|
2690
|
+
v,
|
|
2691
|
+
a,
|
|
2692
|
+
!0
|
|
2693
|
+
), z = c.check(I);
|
|
2694
|
+
if (z.circular)
|
|
2695
|
+
return h?.push({
|
|
2696
|
+
code: "circular_include",
|
|
2697
|
+
message: O("circular_include", {
|
|
2698
|
+
path: I,
|
|
2699
|
+
from: z.from,
|
|
2700
|
+
via: "extend"
|
|
2701
|
+
}),
|
|
2702
|
+
path: n,
|
|
2703
|
+
details: { path: I, from: z.from, via: "extend" }
|
|
2704
|
+
}), {
|
|
2705
|
+
source: K(A),
|
|
2706
|
+
context: _(i, s)
|
|
2707
|
+
};
|
|
2708
|
+
throw u({
|
|
2709
|
+
code: "parse_error",
|
|
2710
|
+
path: v,
|
|
2711
|
+
details: { message: "layout extend is not supported" }
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
const Oe = xe(F, {
|
|
2715
|
+
path: v,
|
|
2716
|
+
mode: "layout"
|
|
2717
|
+
}), De = new Map(
|
|
2718
|
+
A.map((N) => [N.name, N.body])
|
|
2719
|
+
), Be = Ft(
|
|
2720
|
+
F,
|
|
2721
|
+
Oe,
|
|
2722
|
+
De
|
|
2723
|
+
), je = _(
|
|
2724
|
+
i,
|
|
2725
|
+
P,
|
|
2726
|
+
s
|
|
2727
|
+
);
|
|
2728
|
+
return { source: Be, context: je };
|
|
2729
|
+
} finally {
|
|
2730
|
+
c.pop();
|
|
2731
|
+
}
|
|
2732
|
+
} catch (W) {
|
|
2733
|
+
const $ = It(W);
|
|
2734
|
+
throw $.adjusted ? $.errorToThrow : W;
|
|
2735
|
+
} finally {
|
|
2736
|
+
b && c.pop();
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
const Ut = J.warningReasons, Zt = [
|
|
2740
|
+
{
|
|
2741
|
+
reason: "contains_html_script_tag",
|
|
2742
|
+
test: (t) => /<\/?script\b/i.test(t)
|
|
2743
|
+
},
|
|
2744
|
+
{
|
|
2745
|
+
reason: "contains_event_handler",
|
|
2746
|
+
test: (t) => /\bon(?:error|click|load)\s*=/i.test(t)
|
|
2747
|
+
},
|
|
2748
|
+
{
|
|
2749
|
+
reason: "contains_dangerous_scheme",
|
|
2750
|
+
test: (t) => /(?:javascript|vbscript)\s*:/i.test(t)
|
|
2751
|
+
},
|
|
2752
|
+
{
|
|
2753
|
+
reason: "contains_embed_tag",
|
|
2754
|
+
test: (t) => /<(?:iframe|object|embed)\b/i.test(t)
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
reason: "contains_meta_refresh",
|
|
2758
|
+
test: (t) => /<meta\b[^>]*\bhttp-equiv\b/i.test(t)
|
|
2759
|
+
}
|
|
2760
|
+
];
|
|
2761
|
+
function qt(t) {
|
|
2762
|
+
return Ut[t] ?? t;
|
|
2763
|
+
}
|
|
2764
|
+
function G(t, e, n, i) {
|
|
2765
|
+
if (typeof t == "string") {
|
|
2766
|
+
for (const s of Zt)
|
|
2767
|
+
s.test(t) && n.push({
|
|
2768
|
+
code: "suspicious_context_value",
|
|
2769
|
+
message: O("suspicious_context_value", {
|
|
2770
|
+
key: e,
|
|
2771
|
+
reason: qt(s.reason)
|
|
2772
|
+
}),
|
|
2773
|
+
path: i,
|
|
2774
|
+
details: { key: e, reason: s.reason }
|
|
2775
|
+
});
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
if (t != null) {
|
|
2779
|
+
if (Array.isArray(t)) {
|
|
2780
|
+
for (let s = 0; s < t.length; s++)
|
|
2781
|
+
G(t[s], `${e}[${s}]`, n, i);
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
if (typeof t == "object")
|
|
2785
|
+
for (const [s, r] of Object.entries(
|
|
2786
|
+
t
|
|
2787
|
+
)) {
|
|
2788
|
+
const o = e.length > 0 ? `${e}.${s}` : s;
|
|
2789
|
+
G(r, o, n, i);
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
function Vt(t, e, n) {
|
|
2794
|
+
for (const [i, s] of Object.entries(t))
|
|
2795
|
+
G(s, i, e, n);
|
|
2796
|
+
}
|
|
2797
|
+
async function ae(t, e) {
|
|
2798
|
+
const n = e.path, i = e.context, s = e.registry ?? new be(), r = e.warnings ?? [], o = e.visitStack ?? new Le(), {
|
|
2799
|
+
source: a,
|
|
2800
|
+
declarationUpdates: c
|
|
2801
|
+
} = await Wt(t, { path: n, context: { ...i } });
|
|
2802
|
+
Vt(
|
|
2803
|
+
_(i, c ?? {}),
|
|
2804
|
+
r,
|
|
2805
|
+
n
|
|
2806
|
+
);
|
|
2807
|
+
const h = await zt(a, {
|
|
2808
|
+
path: n,
|
|
2809
|
+
context: i,
|
|
2810
|
+
declarationUpdates: c ?? {},
|
|
2811
|
+
loader: e.loader,
|
|
2812
|
+
root: e.root,
|
|
2813
|
+
constrainToRoot: e.constrainToRoot,
|
|
2814
|
+
visitStack: o,
|
|
2815
|
+
warnings: r,
|
|
2816
|
+
inComponent: e.inComponent ?? !1
|
|
2817
|
+
}), { source: l, context: d } = h, { source: f, directives: g } = Dt(l, {
|
|
2818
|
+
path: n,
|
|
2819
|
+
registry: s,
|
|
2820
|
+
context: d
|
|
2821
|
+
}), m = e.loader;
|
|
2822
|
+
if (g.length > 0 && !m)
|
|
2823
|
+
throw new Error("loader is required when processing include directives");
|
|
2824
|
+
let p = f;
|
|
2825
|
+
return g.length > 0 && m && (p = await vt({
|
|
2826
|
+
source: f,
|
|
2827
|
+
directives: g,
|
|
2828
|
+
context: d,
|
|
2829
|
+
loader: m,
|
|
2830
|
+
root: e.root,
|
|
2831
|
+
path: n,
|
|
2832
|
+
preserveFrontMatter: e.preserveFrontMatter,
|
|
2833
|
+
preserveHgComments: e.preserveHgComments,
|
|
2834
|
+
visitStack: o,
|
|
2835
|
+
warnings: r,
|
|
2836
|
+
registry: s,
|
|
2837
|
+
constrainToRoot: e.constrainToRoot
|
|
2838
|
+
})), p = await kt(p, {
|
|
2839
|
+
context: d,
|
|
2840
|
+
path: n,
|
|
2841
|
+
registry: s,
|
|
2842
|
+
loader: m,
|
|
2843
|
+
rootDir: e.root,
|
|
2844
|
+
warnings: r,
|
|
2845
|
+
visitStack: o,
|
|
2846
|
+
parentContext: d,
|
|
2847
|
+
preserveHgComments: e.preserveHgComments,
|
|
2848
|
+
constrainToRoot: e.constrainToRoot
|
|
2849
|
+
}), p = await _e(p, d, {
|
|
2850
|
+
path: n,
|
|
2851
|
+
registry: s,
|
|
2852
|
+
loader: m,
|
|
2853
|
+
rootDir: e.root,
|
|
2854
|
+
warnings: r,
|
|
2855
|
+
visitStack: o,
|
|
2856
|
+
parentContext: d,
|
|
2857
|
+
preserveHgComments: e.preserveHgComments,
|
|
2858
|
+
constrainToRoot: e.constrainToRoot
|
|
2859
|
+
}), p = jt(p, e.preserveHgComments), p;
|
|
2860
|
+
}
|
|
2861
|
+
async function Kt(t, e = {}) {
|
|
2862
|
+
const n = e.path, i = _(e.context), s = e.registry ?? new be(), r = e.warnings ?? [], o = e.visitStack ?? new Le(), { context: a, body: c, rawFrontMatter: h } = H(
|
|
2863
|
+
t,
|
|
2864
|
+
n
|
|
2865
|
+
), l = _(i, a);
|
|
2866
|
+
let d = await ae(c, {
|
|
2867
|
+
...e,
|
|
2868
|
+
context: l,
|
|
2869
|
+
registry: s,
|
|
2870
|
+
warnings: r,
|
|
2871
|
+
visitStack: o
|
|
2872
|
+
});
|
|
2873
|
+
return d = Bt(d, {
|
|
2874
|
+
preserveFrontMatter: e.preserveFrontMatter,
|
|
2875
|
+
rawFrontMatter: h
|
|
2876
|
+
}), {
|
|
2877
|
+
markdown: d,
|
|
2878
|
+
warnings: r
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
async function Yt(t, e) {
|
|
2882
|
+
const n = e.path, { context: i, body: s } = H(t, n), r = _(e.context, i);
|
|
2883
|
+
return ae(s, {
|
|
2884
|
+
...e,
|
|
2885
|
+
context: r,
|
|
2886
|
+
preserveFrontMatter: !1
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
async function Jt(t, e, n) {
|
|
2890
|
+
if (n != null && "serverContext" in n && n.serverContext != null)
|
|
2891
|
+
throw u({
|
|
2892
|
+
code: "server_context_on_client"
|
|
2893
|
+
});
|
|
2894
|
+
const i = n?.loader;
|
|
2895
|
+
if (!i)
|
|
2896
|
+
throw u({
|
|
2897
|
+
code: "parse_error",
|
|
2898
|
+
details: { message: "loader is required for renderClient" }
|
|
2899
|
+
});
|
|
2900
|
+
let s, r;
|
|
2901
|
+
typeof t == "string" ? s = t : (r = t.path, s = await i(t.path));
|
|
2902
|
+
const o = _(e);
|
|
2903
|
+
return Kt(s, {
|
|
2904
|
+
context: o,
|
|
2905
|
+
loader: i,
|
|
2906
|
+
root: n?.root,
|
|
2907
|
+
path: r ?? n?.path,
|
|
2908
|
+
preserveFrontMatter: n?.preserveFrontMatter,
|
|
2909
|
+
preserveHgComments: n?.preserveHgComments,
|
|
2910
|
+
constrainToRoot: n?.constrainToRoot
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
function Xt(t, e) {
|
|
2914
|
+
const n = [`[hyogen:${t}] ${e.code}`], i = {};
|
|
2915
|
+
if (e.details)
|
|
2916
|
+
for (const [s, r] of Object.entries(e.details))
|
|
2917
|
+
r !== void 0 && (i[s] = r);
|
|
2918
|
+
i.path === void 0 && e.path !== void 0 && (i.path = e.path);
|
|
2919
|
+
for (const [s, r] of Object.entries(i))
|
|
2920
|
+
n.push(` ${s}: ${String(r)}`);
|
|
2921
|
+
return n.join(`
|
|
2922
|
+
`);
|
|
2923
|
+
}
|
|
2924
|
+
export {
|
|
2925
|
+
u as createHyogenError,
|
|
2926
|
+
Xt as formatDiagnosticLog,
|
|
2927
|
+
Ue as formatMessage,
|
|
2928
|
+
Jt as renderClient
|
|
2929
|
+
};
|
|
2930
|
+
//# sourceMappingURL=client.js.map
|