mutorjs 1.5.2 → 1.5.3

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/dist/server.d.cts CHANGED
@@ -1,3 +1,161 @@
1
+ declare enum TokenType {
2
+ IDENT = 0,
3
+ KEYWORD = 1,
4
+ NUMBER = 2,
5
+ STRING = 3,
6
+ OPERATOR = 4
7
+ }
8
+ declare enum ExprType {
9
+ BINARY = 0,
10
+ TERNARY = 1,
11
+ UNARY = 2,
12
+ CALL = 3,
13
+ STRING = 4,
14
+ NUMBER = 5,
15
+ NAMESPACE = 6,
16
+ IDENT = 7,
17
+ PROP_ACCESS = 8,
18
+ GROUP = 9,
19
+ BOOLEAN = 10,
20
+ UNDEFINED = 11,
21
+ NULL = 12,
22
+ FOR = 13,
23
+ IF = 14,
24
+ ELSE_IF = 15,
25
+ ELSE = 16,
26
+ END = 17
27
+ }
28
+ declare enum LoopType {
29
+ OF = 0,
30
+ IN = 1
31
+ }
32
+ declare enum BlockType {
33
+ LOOP = 0,
34
+ NON_LOOP = 1
35
+ }
36
+
37
+ type BaseToken = {
38
+ type: TokenType;
39
+ value: string;
40
+ pos: number;
41
+ };
42
+ type KeywordToken = BaseToken & {
43
+ type: TokenType.KEYWORD;
44
+ };
45
+ type IdentToken = BaseToken & {
46
+ type: TokenType.IDENT;
47
+ };
48
+ type StringToken = BaseToken & {
49
+ type: TokenType.STRING;
50
+ };
51
+ type NumberToken = BaseToken & {
52
+ type: TokenType.NUMBER;
53
+ };
54
+ type OperatorToken = BaseToken & {
55
+ type: TokenType.OPERATOR;
56
+ };
57
+ type Token = BaseToken | KeywordToken | IdentToken | StringToken | NumberToken | OperatorToken;
58
+ type EndExpr = {
59
+ type: ExprType.END;
60
+ pos: number;
61
+ };
62
+ type ForExpr = {
63
+ pos: number;
64
+ type: ExprType.FOR;
65
+ variable: string;
66
+ iterable: Expr;
67
+ loopType: LoopType;
68
+ };
69
+ type IfExpr = {
70
+ pos: number;
71
+ type: ExprType.IF;
72
+ condition: Expr;
73
+ };
74
+ type ElseExpr = {
75
+ pos: number;
76
+ type: ExprType.ELSE;
77
+ };
78
+ type ElseIfExpr = {
79
+ pos: number;
80
+ type: ExprType.ELSE_IF;
81
+ condition: Expr;
82
+ };
83
+ type BooleanExpr = {
84
+ pos: number;
85
+ type: ExprType.BOOLEAN;
86
+ true: boolean;
87
+ };
88
+ type UndefinedExpr = {
89
+ pos: number;
90
+ type: ExprType.UNDEFINED;
91
+ };
92
+ type NullExpr = {
93
+ pos: number;
94
+ type: ExprType.NULL;
95
+ };
96
+ type PropAccessExpr = {
97
+ pos: number;
98
+ type: ExprType.PROP_ACCESS;
99
+ left: Expr;
100
+ right: Expr;
101
+ bracketNotation?: boolean;
102
+ optional?: boolean;
103
+ };
104
+ type BinaryExpr = {
105
+ pos: number;
106
+ type: ExprType.BINARY;
107
+ left: Expr;
108
+ right: Expr;
109
+ operator: string;
110
+ };
111
+ type UnaryExpr = {
112
+ pos: number;
113
+ type: ExprType.UNARY;
114
+ operator: string;
115
+ expr: Expr;
116
+ isPostfix?: boolean;
117
+ };
118
+ type TernaryExpr = {
119
+ pos: number;
120
+ type: ExprType.TERNARY;
121
+ condition: Expr;
122
+ left: Expr;
123
+ right: Expr;
124
+ };
125
+ type CallExpr = {
126
+ pos: number;
127
+ type: ExprType.CALL;
128
+ expr: Expr;
129
+ args: Expr[];
130
+ optional?: boolean;
131
+ };
132
+ type IdentExpr = {
133
+ pos: number;
134
+ type: ExprType.IDENT;
135
+ value: string;
136
+ };
137
+ type GroupExpr = {
138
+ pos: number;
139
+ type: ExprType.GROUP;
140
+ expr: Expr;
141
+ };
142
+ type StringExpr = {
143
+ pos: number;
144
+ type: ExprType.STRING;
145
+ value: string;
146
+ };
147
+ type NumberExpr = {
148
+ pos: number;
149
+ type: ExprType.NUMBER;
150
+ value: string;
151
+ };
152
+ type NamespaceExpr = {
153
+ pos: number;
154
+ type: ExprType.NAMESPACE;
155
+ left: Expr;
156
+ right: Expr;
157
+ };
158
+ type Expr = ForExpr | IfExpr | ElseIfExpr | ElseExpr | EndExpr | BooleanExpr | NullExpr | UndefinedExpr | PropAccessExpr | IdentExpr | BinaryExpr | UnaryExpr | TernaryExpr | CallExpr | GroupExpr | StringExpr | NumberExpr | NamespaceExpr;
1
159
  interface MutorConfig {
2
160
  cache: {
3
161
  active: boolean;
@@ -34,15 +192,42 @@ type PartialMutorConfig = Partial<Omit<MutorConfig, "delimiters">> & {
34
192
  exclude?: Set<string>;
35
193
  };
36
194
  };
37
- /**
38
- * RuntimeFrame encapsulates all execution-local state for a single render operation.
39
- * This allows async operations to work correctly by avoiding shared mutable state.
40
- */
195
+ type BuildContext = {
196
+ scope: string[];
197
+ forbiddenProps: Set<string>;
198
+ allowedProps: Set<string>;
199
+ };
200
+ type CompileMetadata = {
201
+ path: string;
202
+ };
203
+ type CommandStruct = {
204
+ command: string;
205
+ commandData: string;
206
+ "--out"?: string;
207
+ "--data"?: string;
208
+ "--config"?: string;
209
+ };
210
+ type CleanupFn = () => void;
211
+ type ExitCode = 0 | 1 | 2;
41
212
  interface RuntimeFrame {
42
213
  context: any;
43
214
  renderedPath: string;
44
215
  includeStack: Set<string>;
45
216
  }
217
+ interface ParseState {
218
+ cursor: number;
219
+ tokens: Token[];
220
+ config: {
221
+ allowFnCalls: boolean;
222
+ };
223
+ generatingNamespace: boolean;
224
+ }
225
+ interface BuildState {
226
+ scope: string[];
227
+ forbiddenProps: Set<string>;
228
+ allowedProps: Set<string>;
229
+ context: BuildContext;
230
+ }
46
231
 
47
232
  declare class MutorBase {
48
233
  protected __cacheSize: number;
@@ -91,4 +276,4 @@ declare class MutorServer extends MutorBase {
91
276
  compileDir(src: string): Promise<void>;
92
277
  }
93
278
 
94
- export { MutorServer as default };
279
+ export { type BaseToken, type BinaryExpr, BlockType, type BooleanExpr, type BuildContext, type BuildState, type CallExpr, type CleanupFn, type CommandStruct, type CompileMetadata, type ElseExpr, type ElseIfExpr, type EndExpr, type ExitCode, type Expr, ExprType, type ForExpr, type GroupExpr, type IdentExpr, type IdentToken, type IfExpr, type KeywordToken, LoopType, type MutorConfig, type NamespaceExpr, type NullExpr, type NumberExpr, type NumberToken, type OperatorToken, type ParseState, type PartialMutorConfig, type PropAccessExpr, type RuntimeFrame, type StringExpr, type StringToken, type TernaryExpr, type Token, TokenType, type UnaryExpr, type UndefinedExpr, MutorServer as default };
package/dist/server.d.ts CHANGED
@@ -1,3 +1,161 @@
1
+ declare enum TokenType {
2
+ IDENT = 0,
3
+ KEYWORD = 1,
4
+ NUMBER = 2,
5
+ STRING = 3,
6
+ OPERATOR = 4
7
+ }
8
+ declare enum ExprType {
9
+ BINARY = 0,
10
+ TERNARY = 1,
11
+ UNARY = 2,
12
+ CALL = 3,
13
+ STRING = 4,
14
+ NUMBER = 5,
15
+ NAMESPACE = 6,
16
+ IDENT = 7,
17
+ PROP_ACCESS = 8,
18
+ GROUP = 9,
19
+ BOOLEAN = 10,
20
+ UNDEFINED = 11,
21
+ NULL = 12,
22
+ FOR = 13,
23
+ IF = 14,
24
+ ELSE_IF = 15,
25
+ ELSE = 16,
26
+ END = 17
27
+ }
28
+ declare enum LoopType {
29
+ OF = 0,
30
+ IN = 1
31
+ }
32
+ declare enum BlockType {
33
+ LOOP = 0,
34
+ NON_LOOP = 1
35
+ }
36
+
37
+ type BaseToken = {
38
+ type: TokenType;
39
+ value: string;
40
+ pos: number;
41
+ };
42
+ type KeywordToken = BaseToken & {
43
+ type: TokenType.KEYWORD;
44
+ };
45
+ type IdentToken = BaseToken & {
46
+ type: TokenType.IDENT;
47
+ };
48
+ type StringToken = BaseToken & {
49
+ type: TokenType.STRING;
50
+ };
51
+ type NumberToken = BaseToken & {
52
+ type: TokenType.NUMBER;
53
+ };
54
+ type OperatorToken = BaseToken & {
55
+ type: TokenType.OPERATOR;
56
+ };
57
+ type Token = BaseToken | KeywordToken | IdentToken | StringToken | NumberToken | OperatorToken;
58
+ type EndExpr = {
59
+ type: ExprType.END;
60
+ pos: number;
61
+ };
62
+ type ForExpr = {
63
+ pos: number;
64
+ type: ExprType.FOR;
65
+ variable: string;
66
+ iterable: Expr;
67
+ loopType: LoopType;
68
+ };
69
+ type IfExpr = {
70
+ pos: number;
71
+ type: ExprType.IF;
72
+ condition: Expr;
73
+ };
74
+ type ElseExpr = {
75
+ pos: number;
76
+ type: ExprType.ELSE;
77
+ };
78
+ type ElseIfExpr = {
79
+ pos: number;
80
+ type: ExprType.ELSE_IF;
81
+ condition: Expr;
82
+ };
83
+ type BooleanExpr = {
84
+ pos: number;
85
+ type: ExprType.BOOLEAN;
86
+ true: boolean;
87
+ };
88
+ type UndefinedExpr = {
89
+ pos: number;
90
+ type: ExprType.UNDEFINED;
91
+ };
92
+ type NullExpr = {
93
+ pos: number;
94
+ type: ExprType.NULL;
95
+ };
96
+ type PropAccessExpr = {
97
+ pos: number;
98
+ type: ExprType.PROP_ACCESS;
99
+ left: Expr;
100
+ right: Expr;
101
+ bracketNotation?: boolean;
102
+ optional?: boolean;
103
+ };
104
+ type BinaryExpr = {
105
+ pos: number;
106
+ type: ExprType.BINARY;
107
+ left: Expr;
108
+ right: Expr;
109
+ operator: string;
110
+ };
111
+ type UnaryExpr = {
112
+ pos: number;
113
+ type: ExprType.UNARY;
114
+ operator: string;
115
+ expr: Expr;
116
+ isPostfix?: boolean;
117
+ };
118
+ type TernaryExpr = {
119
+ pos: number;
120
+ type: ExprType.TERNARY;
121
+ condition: Expr;
122
+ left: Expr;
123
+ right: Expr;
124
+ };
125
+ type CallExpr = {
126
+ pos: number;
127
+ type: ExprType.CALL;
128
+ expr: Expr;
129
+ args: Expr[];
130
+ optional?: boolean;
131
+ };
132
+ type IdentExpr = {
133
+ pos: number;
134
+ type: ExprType.IDENT;
135
+ value: string;
136
+ };
137
+ type GroupExpr = {
138
+ pos: number;
139
+ type: ExprType.GROUP;
140
+ expr: Expr;
141
+ };
142
+ type StringExpr = {
143
+ pos: number;
144
+ type: ExprType.STRING;
145
+ value: string;
146
+ };
147
+ type NumberExpr = {
148
+ pos: number;
149
+ type: ExprType.NUMBER;
150
+ value: string;
151
+ };
152
+ type NamespaceExpr = {
153
+ pos: number;
154
+ type: ExprType.NAMESPACE;
155
+ left: Expr;
156
+ right: Expr;
157
+ };
158
+ type Expr = ForExpr | IfExpr | ElseIfExpr | ElseExpr | EndExpr | BooleanExpr | NullExpr | UndefinedExpr | PropAccessExpr | IdentExpr | BinaryExpr | UnaryExpr | TernaryExpr | CallExpr | GroupExpr | StringExpr | NumberExpr | NamespaceExpr;
1
159
  interface MutorConfig {
2
160
  cache: {
3
161
  active: boolean;
@@ -34,15 +192,42 @@ type PartialMutorConfig = Partial<Omit<MutorConfig, "delimiters">> & {
34
192
  exclude?: Set<string>;
35
193
  };
36
194
  };
37
- /**
38
- * RuntimeFrame encapsulates all execution-local state for a single render operation.
39
- * This allows async operations to work correctly by avoiding shared mutable state.
40
- */
195
+ type BuildContext = {
196
+ scope: string[];
197
+ forbiddenProps: Set<string>;
198
+ allowedProps: Set<string>;
199
+ };
200
+ type CompileMetadata = {
201
+ path: string;
202
+ };
203
+ type CommandStruct = {
204
+ command: string;
205
+ commandData: string;
206
+ "--out"?: string;
207
+ "--data"?: string;
208
+ "--config"?: string;
209
+ };
210
+ type CleanupFn = () => void;
211
+ type ExitCode = 0 | 1 | 2;
41
212
  interface RuntimeFrame {
42
213
  context: any;
43
214
  renderedPath: string;
44
215
  includeStack: Set<string>;
45
216
  }
217
+ interface ParseState {
218
+ cursor: number;
219
+ tokens: Token[];
220
+ config: {
221
+ allowFnCalls: boolean;
222
+ };
223
+ generatingNamespace: boolean;
224
+ }
225
+ interface BuildState {
226
+ scope: string[];
227
+ forbiddenProps: Set<string>;
228
+ allowedProps: Set<string>;
229
+ context: BuildContext;
230
+ }
46
231
 
47
232
  declare class MutorBase {
48
233
  protected __cacheSize: number;
@@ -91,4 +276,4 @@ declare class MutorServer extends MutorBase {
91
276
  compileDir(src: string): Promise<void>;
92
277
  }
93
278
 
94
- export { MutorServer as default };
279
+ export { type BaseToken, type BinaryExpr, BlockType, type BooleanExpr, type BuildContext, type BuildState, type CallExpr, type CleanupFn, type CommandStruct, type CompileMetadata, type ElseExpr, type ElseIfExpr, type EndExpr, type ExitCode, type Expr, ExprType, type ForExpr, type GroupExpr, type IdentExpr, type IdentToken, type IfExpr, type KeywordToken, LoopType, type MutorConfig, type NamespaceExpr, type NullExpr, type NumberExpr, type NumberToken, type OperatorToken, type ParseState, type PartialMutorConfig, type PropAccessExpr, type RuntimeFrame, type StringExpr, type StringToken, type TernaryExpr, type Token, TokenType, type UnaryExpr, type UndefinedExpr, MutorServer as default };
package/dist/server.js CHANGED
@@ -1,17 +1,16 @@
1
- import{readFileSync as Se}from"fs";import{copyFile as Te,mkdir as Fe,readdir as we,readFile as Ie,writeFile as Ce}from"fs/promises";import{extname as Ee,join as te}from"path";function C(e,r=""){return{context:e,renderedPath:r,includeStack:new Set([r&&r])}}function Z(e,r){return`${" ".repeat(e+r)}^`}var u=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},T=class e extends u{constructor(t,s,o,c,l){let d=s.toString().length+2,a=`${t}
1
+ import{readFileSync as ot}from"fs";import{copyFile as st,mkdir as it,readdir as Ne,readFile as at,writeFile as ct}from"fs/promises";import{extname as Ae,join as ne}from"path";function N(e,t=""){return{context:e,renderedPath:t,includeStack:new Set([t&&t])}}function V(e,t){return`${" ".repeat(e+t)}^`}var a=class e extends Error{constructor(r){super(r);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},_=class e extends a{constructor(r,n,s,o,c){let f=n.toString().length+2,p=`${r}
2
2
 
3
- `;a+=`at ${l}:${s}:${c+1}
4
- `,s>1&&(a+=`${(s-1).toString().padStart(d-2)} | ...
5
- `),a+=`${s} | ${o}
6
- `,a+=Z(c,d+1);super(a);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var se=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),U=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var ie=new Set(["==","!="]),X=new Set([">","<",">=","<="]);var ae=new Set(["+","-"]),ce=new Set(["*","/","%"]),pe=new Set([".","?.","[","::"]),ue=new Set(["-","+","!"]),le={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},A={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,onIncludeFail:"throw",cache:{active:!0,maxSize:50*1024*1024}},fe={JSON:{stringify(e,r){try{return JSON.stringify(e,null,r)}catch{throw new u("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new u("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new u("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new u("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new u("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new u("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new u("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new u("Object::fromEntries expects an array");return Object.fromEntries(e)},pick(e,r){if(!e||typeof e!="object")throw new u("Object::pick expects an object");if(!Array.isArray(r))throw new u("Object::pick expects an array of keys");let t={};for(let s of r)Object.hasOwn(e,s)&&(t[s]=e[s]);return t},omit(e,r){if(!e||typeof e!="object")throw new u("Object::omit expects an object");if(!Array.isArray(r))throw new u("Object::omit expects an array of keys");let t={...e};for(let s of r)delete t[s];return t}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)},of(...e){return Array.of(...e)},unique(e){if(!Array.isArray(e))throw new u("Array::unique expects an array");return[...new Set(e)]},compact(e){if(!Array.isArray(e))throw new u("Array::compact expects an array");return e.filter(Boolean)},chunk(e,r){if(!Array.isArray(e))throw new u("Array::chunk expects an array");if(!Number.isInteger(r)||r<=0)throw new u("Array::chunk expects a positive integer size");let t=[];for(let s=0;s<e.length;s+=r)t.push(e.slice(s,s+r));return t},range(e,r,t=1){if(!Number.isFinite(e)||!Number.isFinite(r)||!Number.isFinite(t))throw new u("Array::range expects finite numbers");if(t===0)throw new u("Array::range step cannot be 0");let s=[];if(e<=r)for(let o=e;o<=r;o+=t)s.push(o);else for(let o=e;o>=r;o-=Math.abs(t))s.push(o);return s}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},isInteger(e){return Number.isInteger(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)},clamp(e,r,t){return Math.min(Math.max(e,r),t)},toFixed(e,r=0){if(typeof e!="number")throw new u("Number::toFixed expects a number");return e.toFixed(r)},random(e=0,r=1){return Math.random()*(r-e)+e}},String:{fromCharCode(...e){return String.fromCharCode(...e)},capitalize(e){if(typeof e!="string")throw new u("String::capitalize expects a string");return e.length?e[0].toUpperCase()+e.slice(1):e}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},trunc(e){return Math.trunc(e)},sign(e){return Math.sign(e)},sqrt(e){return Math.sqrt(e)},pow(e,r){return e**r},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new u("Date::parse expects a string");return Date.parse(e)},new(e){return e===void 0?new Date:new Date(e)},iso(e){return new Date(e??Date.now()).toISOString()},timestamp(e){return new Date(e??Date.now()).getTime()}},Boolean:{valueOf(e){return!!e}},RegExp:{test(e,r,t=""){if(typeof e!="string")throw new u("RegExp::test expects a pattern string");if(typeof r!="string")throw new u("RegExp::test expects a value string");return new RegExp(e,t).test(r)},match(e,r,t=""){if(typeof e!="string")throw new u("RegExp::match expects a pattern string");if(typeof r!="string")throw new u("RegExp::match expects a value string");return r.match(new RegExp(e,t))}},URL:{encode(e){if(typeof e!="string")throw new u("URL::encode expects a string");return encodeURIComponent(e)},decode(e){if(typeof e!="string")throw new u("URL::decode expects a string");return decodeURIComponent(e)}}},me=/('|"|`)use\s+async\1/,he=(async()=>{}).constructor;function L(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>le[r]):e}import{dirname as xe,isAbsolute as Ae,resolve as ge}from"path";function $(e,...r){let t=Ae(e)?e:ge(process.cwd(),e);if(r.length){let s=xe(t);return ge(s,...r)}return t}function j(e,r,t){if(t.has(e)&&!r.has(e))throw new u(`Forbidden property access.
7
- Access to this computed property '${e}' is forbidden.`);return e}var z="object",de=Symbol("__mutor_safe_context");function B(e){if(!e||typeof e!==z||de in e)return e;let r=new WeakSet;function t(o,c=""){if(!o||typeof o!==z||r.has(o))return o;r.add(o);let l=Object.getPrototypeOf(o);if(l&&l!==Object.prototype&&l!==Array.prototype)throw new u(`Unsafe prototype detected at ${c||"root"} in context.`);if(Array.isArray(o)){for(let a=0;a<o.length;a++)o[a]=t(o[a],`${c}[${a}]`);return o}if(o instanceof Map){for(let[a,f]of o.entries())typeof a===z&&t(a,`${c}.mapKey`),o.set(a,t(f,`${c}.mapValue`));return o}if(o instanceof Set){let a=new Set;for(let f of o.values())a.add(t(f,c));o.clear();for(let f of a)o.add(f);return o}let d=Object.getOwnPropertyDescriptors(o);for(let a of Object.keys(d)){let f=d[a];if(f.get||f.set)throw new u(`Getter/setter not allowed at '${c}.${a}' in context.`);let h=o[a];h&&typeof h===z&&(o[a]=t(h,`${c}.${a}`))}return o}let s=t(e);return s&&typeof s===z&&Object.defineProperty(s,de,{value:!0,enumerable:!1,writable:!1,configurable:!1}),s}function M(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function W(e,r){let s=e.slice(0,r).split(`
8
- `).length,o=e.lastIndexOf(`
9
- `,r-1)+1;return[s,o]}function Y(e,r){let t=e.indexOf(`
10
- `,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function D(e,r){let{scope:t,forbiddenProps:s,allowedProps:o}=r;function c(i){return t.includes(i)?i:`ctx.${i}`}function l(i){switch(i.type){case 17:return"}";case 5:return i.value;case 4:return`\`${/\$\\/.test(i.value)?M(i.value):i.value}\``;case 10:return i.true?"true":"false";case 12:return"null";case 11:return"undefined";case 7:return c(i.value);case 9:return`(${l(i.expr)})`;case 2:return`${i.operator}${l(i.expr)}`;case 0:return`${l(i.left)} ${i.operator} ${l(i.right)}`;case 1:return`${l(i.condition)} ? ${l(i.left)} : ${l(i.right)}`;case 8:return a(i);case 3:return f(i);case 6:return d(i);case 13:return h(i);case 16:return"} else {";case 14:return y(i);case 15:return E(i);default:throw new u(`Unsupported expression type '${i.type}'`)}}function d(i){if(i.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:i.pos};return`namespaces.${i.left.value}.${i.right.value}`}function a(i){let b=l(i.left);if(i.bracketNotation){let g=l(i.right),O=i.optional?"?.":"";return i.right.type===4||i.right.type===5?`${b}${O}[${g}]`:`${b}${O}[validateComputedProps(${g}, allowedProps, forbiddenProps)]`}else{let g=i.right.value,O=i.optional?"?.":".";if(s.has(g)&&!o.has(g))throw{message:"Forbidden property access.",pos:i.right.pos};return`${b}${O}${g}`}}function f(i){let b=l(i.expr),g=i.optional?"?.":"",O=i.args.map(P=>l(P)).join(", ");return`${b}${g}(${O})`}function h(i){let{iterable:b,loopType:g,variable:O}=i;return`for(const ${O} ${g===1?"in":"of"} ${D(b,r)}){`}function y(i){let{condition:b}=i;return`if(${D(b,r)}){`}function E(i){let{condition:b}=i;return`}else if(${D(b,r)}){`}let _=l(e);return _.includes("namespaces.Mutor.await")?_.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):_}function G(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function H(e,r){let t=0,s=!1;function o(n,p){let m=e[t],N=e[e.length-1];if(!m)throw{message:`Unexpected end of expression. Expected ${p?`'${p}'`:`${n===0?"an":"a"} ${G(n)}`}.`,pos:N.pos+N.value.length-1};if(m.type!==n)throw{message:`Unexpected token type. Expected ${p?`'${p}'`:G(n)} but got ${G(m.type)} instead.`,pos:m.pos};if(p!==void 0&&m.value!==p)throw{message:`Unexpected token '${m?.value}'. Expected ${n===0?"an":"a"} ${G(n)} instead.`,pos:m.pos};return e[t++]}function c(){let n=e[t-1].pos,p=o(0).value,m;try{m=o(1,"in")}catch{m=o(1,"of")}let N=m.value==="in"?1:0,v=R();return{type:13,loopType:N,iterable:v,variable:p,pos:n}}function l(){let n=R();return{condition:n,pos:n.pos,type:14}}function d(){let n=e[t-1].pos;try{return o(1,"if"),{...l(),type:15,pos:n}}catch{return{type:16,pos:n}}}function a(){let n=[];if(e[t]?.type===4&&e[t]?.value===")")return n;for(n.push(R());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,n.push(R());return n}function f(){let n=e[t++];if(n?.type===2)return{type:5,value:n.value,pos:n.pos};if(n?.type===3)return{type:4,value:n.value,pos:n.pos};if(n?.type===1){if(n.value==="for"&&t===1)return c();if(n.value==="true"||n.value==="false")return{type:10,true:n.value==="true",pos:n.pos};if(n.value==="undefined")return{type:11,pos:n.pos};if(n.value==="null")return{type:12,pos:n.pos};if(n.value==="end"&&e.length===1)return{type:17,pos:n.pos};if(n.value==="if"&&t===1)return l();if(n.value==="else"&&t===1)return d()}if(n?.type===0)return{type:7,value:n.value,pos:n.pos};if(n?.type===4&&n.value==="("){let p=R();return o(4,")"),{type:9,expr:p,pos:n.pos}}if(n?.type===4&&ue.has(n.value)){let p=n.value,m=R();return{type:2,operator:p,expr:m,pos:n.pos}}throw t>e.length?{message:"Unexpected end of expression.",pos:e[e.length-1].pos}:{message:`Unexpected token '${n?.value}'.`,pos:n.pos}}function h(){let n=f();for(;e[t];){let p=e[t];if(p?.type===4&&p?.value==="("){if(t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let m=a();o(4,")"),n={type:3,expr:n,args:m,pos:e[t-1].pos}}else if(p?.type===4&&p?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let m=a();o(4,")"),n={type:3,expr:n,args:m,optional:!0,pos:e[t-1].pos}}else if(p?.type===4&&pe.has(p?.value)){let m=p?.value==="::",N=p?.value==="[",v=p?.value==="?.";if(t++,m&&(e[t-2]?.type!==0||e[t]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e[t-2]?.value}::${e[t]?.value??""}' instead.`,pos:e[t]?.pos??e[t-1].pos};if(m){s=!0;let x=f();n={type:6,left:n,right:x,pos:e[t-1].pos}}else if(N){let x=R();o(4,"]"),n={type:8,right:x,left:n,bracketNotation:!0,pos:e[t-1].pos}}else if(v)if(e[t]?.type===4&&e[t]?.value==="["){t++;let x=R();o(4,"]"),n={type:8,left:n,right:x,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let x=f();n={type:8,left:n,right:x,optional:!0,pos:e[t-1].pos}}else{let x=f();n={type:8,left:n,right:x,pos:e[t-1].pos}}}else break}return s=!1,n}function y(){let n=h();for(;e[t]?.type===4&&ce.has(e[t]?.value);){let p=e[t++].value,m=h();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function E(){let n=y();for(;e[t]?.type===4&&ae.has(e[t]?.value);){let p=e[t++].value,m=y();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function _(){let n=E();for(;e[t]?.type===4&&X.has(e[t]?.value);){let p=e[t++].value,m=E();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function i(){let n=_();for(;e[t]?.type===4&&X.has(e[t]?.value);){let p=e[t++].value,m=_();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function b(){let n=i();for(;e[t]?.type===4&&ie.has(e[t]?.value);){let p=e[t++].value,m=i();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function g(){let n=O();for(;e[t]?.type===4&&e[t]?.value==="||";){let p=e[t++].value,m=O();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function O(){let n=P();for(;e[t]?.type===4&&e[t]?.value==="&&";){let p=e[t++].value,m=P();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function P(){let n=b();for(;e[t]?.type===4&&e[t]?.value==="??";){let p=e[t++].value,m=b();n={type:0,left:n,right:m,operator:p,pos:e[t-1].pos}}return n}function R(){let n=g();if(e[t]?.type!==4||e[t]?.value!=="?")return n;t++;let p=R();o(4,":");let m=R();return{type:1,left:p,right:m,condition:n,pos:e[t-1].pos}}let V=R();if(t!==e.length)throw{pos:e[t].pos,message:`Expected token '${e[t].value}'.
11
- Expected an operator or the end of the expression.`};return V}function Q(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,s=`${r.whitespaceTrim}${r.closingTag}`,o=e.startsWith(t),c=e.endsWith(s),l=e.startsWith(o?t+r.commentTag:r.openingTag+r.commentTag),d=e.slice(o?t.length:r.openingTag.length,e.length-(c?s.length:r.closingTag.length));if(l)return{isComment:l,leftTrim:o,rightTrim:c,async:me.test(d)};let a=d.trim(),f=a.startsWith("for")||a.startsWith("if")||a.startsWith("else"),h=a.startsWith("for")||a.startsWith("if"),y=a==="end",E=a.startsWith("for");return{leftTrim:o,rightTrim:c,inner:d,isBlock:f,isBlockEnd:y,hasContext:E,requiresBlockClose:h,usesAwait:d.includes("Mutor::await")}}function k(e){let r=0,t="",s=[];function o(){let a="";if(/[a-zA-Z$_]/.test(t)){let f=r;for(;/[a-zA-Z$_0-9]/.test(e[f])&&f<e.length;)a+=e[f],f++;s.push({type:se.has(a)?1:0,value:a,pos:r}),r=f,t=e[r]}}function c(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let a=t,f=r,h=r+1,y="";for(;h<e.length;){let E=e[h];if(E==="\\"){if(h+1>=e.length)throw{pos:h,message:"Unexpected end of string after escape character."};y+=E,y+=e[h+1],h+=2;continue}if(E===a)break;y+=E,h++}if(h>=e.length||e[h]!==a)throw{pos:f,message:`String literal missing closing ${a}.`};s.push({type:3,value:y,pos:f}),r=h}function l(){if(/[0-9]/.test(t)){let a=r,f="";for(;/[0-9.oxe]/.test(e[a])&&a<e.length;)f+=e[a],a++;let h=Number(f);if(Number.isNaN(h))throw{pos:r,message:"Found invalid number literal."};s.push({type:2,value:`${h}`,pos:r}),r=a-1,t=e[r]}}function d(){let a=`${t}${e[r+1]}`;if(U.has(a)){s.push({type:4,value:a,pos:r}),r++;return}if(U.has(t)){s.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],l(),o(),c(),d(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!U.has(t)&&!U.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return s.length?s:[{type:3,value:"",pos:0}]}function ee(e,r,t){let s=[],o=[],{delimiters:c,keepOpeningTagEscapeDelimiter:l,allowFnCalls:d,allowedProps:a,forbiddenProps:f,autoEscape:h}=r,y="sync",E=!1,_=0,i='let acc="";';for(;_<e.length;){let O=function(){let w=g,S=0;for(;w>=c.openingTagEscape.length&&e.slice(w-c.openingTagEscape.length,w)===c.openingTagEscape;)S++,w-=c.openingTagEscape.length;return S%2===1};var b=O;let g=e.indexOf(c.openingTag,_);if(g===-1){let w=e.slice(_);E&&(w=w.trimStart()),w&&(i+=`acc+=\`${M(w)}\`;`);break}if(O()){let w=e.slice(_,l?g+c.openingTagEscape.length+1:g-c.openingTag.length+1);E&&(w=w.trimStart(),E=!1),i+=`acc+=\`${M(w)}\`;`,l||(i+=`acc+=\`${c.openingTag}\`;`),_=g+c.openingTag.length;continue}let P=e.indexOf(c.closingTag,g);if(P===-1){let[w,S]=W(e,g),F=Y(e,S);throw new T("No closing tag found.",w,F,g,t.path)}let R=e.slice(g,P+c.closingTag.length),{async:V,inner:n,leftTrim:p,rightTrim:m,isBlock:N,isBlockEnd:v,hasContext:x,requiresBlockClose:re,isComment:Oe,usesAwait:be}=Q(R,{delimiters:c});if(be&&y!=="async")throw{pos:g,message:`Mutor::await() requires async mode.
12
- Add {{# 'use async' }} at the top of the template.`};let I=e.slice(_,g);I&&(E&&(I=I.trimStart()),p&&(I=I.trimEnd()),I&&(i+=`acc+=\`${M(I)}\`;`)),E=!1,_=P+c.closingTag.length;try{if(Oe)V&&(y="async");else{let w=k(n),S=H(w,{allowFnCalls:d});if(N&&re&&x?(s.push(S.variable),o.push({type:0,pos:g})):N&&re&&!x&&o.push({type:1,pos:g}),v){let J=o.pop();if(J?.type===0&&s.pop(),J===void 0)throw{message:"Unexpected end of block",pos:g}}let F=D(S,{allowedProps:a,forbiddenProps:f,scope:s});N||v?i+=F:i+=h&&!F.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${F});`:`acc+=${F};`}m&&(E=!0)}catch(w){let{message:S,pos:F}=w,J=p?c.whitespaceTrim.length+c.openingTag.length:c.openingTag.length,ne=g+F+J,[Re,oe]=W(e,ne),_e=Y(e,oe);throw new T(S,Re,_e,ne-oe,t.path)}}if(o.length){let g=o.pop()?.pos,[O,P]=W(e,g),R=Y(e,P);throw new T("Unclosed block detected.",O,R,g-P,t.path)}return i+="return acc;",y==="async"?new he("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i)}var q=class{constructor(r={}){this.__cacheSize=0;this.__config={...A};this.__compiledTemplatesMap=new Map;this.__namespaces={...fe,Mutor:{await:async r=>await r}};this.addConfig(r)}addConfig(r){let{autoEscape:t,delimiters:s,allowedProps:o,forbiddenProps:c,keepOpeningTagEscapeDelimiter:l,allowFnCalls:d,cache:a,build:f,onIncludeFail:h,onIncludeError:y}=r;return this.__config={build:{include:new Set([...f?.include||A.build.include]),exclude:new Set([...A.build.exclude,...f?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:o||A.allowedProps,allowFnCalls:!!d,onIncludeFail:h||A.onIncludeFail,onIncludeError:y||A.onIncludeError,cache:{...A.cache,...a||{}},forbiddenProps:new Set([...A.forbiddenProps,...c||[]]),keepOpeningTagEscapeDelimiter:l===!0?!0:l!==!1,delimiters:{...A.delimiters,...s||{}}},this.__config}restoreDefaultConfig(){this.__config={...A}}compile(r,t){return ee(r,this.__config,{path:t?.renderedPath||"anonymous"})}renderAsync(r,t){return new Promise(s=>{s(this.render(r,t))})}render(r,t){let s=C(t,"anonymous");return this.__renderWithRuntime(r,s)}__renderWithRuntime(r,t){return this.compile(r,t)(B(t.context),this.__createNamespacesWithRuntime(t),this.__config.allowedProps,this.__config.forbiddenProps,L,j)}__createNamespacesWithRuntime(r){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:r.context}}}handleError(r,t,s,o){if(this.__config.onIncludeFail==="throw")throw r instanceof T?r:new u(r.message);let c={from:t,path:s,absolutePath:o};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(r instanceof T?console.log(r):console.log(`[Mutor.js]
13
- ${r.message}`)),this.__config.onIncludeError?.(c,r)??""}createEntrySpaceForTemplate(r){if(this.__cacheSize+r<this.__config.cache.maxSize)return!0;if(r>this.__config.cache.maxSize)return!1;let t=this.__compiledTemplatesMap.entries().next().value;if(t){let[s,o]=t;this.__compiledTemplatesMap.delete(s),this.__cacheSize-=o.size}return this.createEntrySpaceForTemplate(r)}getDiagnostics(){let r=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:r,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(r/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:r>0?Math.min(100,Math.round(this.__cacheSize/r*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}register(r,t){let s=t.length*2+500;if(this.__cacheSize+s>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(s))throw new u(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let o=C(null,r);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t,o),size:s})}reset(){this.__config={...A},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var K=class extends q{constructor(r={}){super(r)}__setupIncludeForRuntime(r){this.__namespaces.Mutor.include=(t,s)=>{let o=$(r.renderedPath,t);if(r.includeStack.has(o))throw new u(`Circular include detected.
14
- ${Array.from(r.includeStack).join(`
3
+ `;p+=`at ${c}:${n}:${o+1}
4
+ `,n>1&&(p+=`${(n-1).toString().padStart(f-2)} | ...
5
+ `),p+=`${n} | ${s}
6
+ `,p+=V(o,f+1);super(p);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ue=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),I=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var le=new Set(["==","!="]),Z=new Set([">","<",">=","<="]);var fe=new Set(["+","-"]),me=new Set(["*","/","%"]),de=new Set([".","?.","[","::"]),ge=new Set(["-","+","!"]),he={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},h={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,onIncludeFail:"throw",cache:{active:!0,maxSize:50*1024*1024}},ye={JSON:{stringify(e,t){try{return JSON.stringify(e,null,t)}catch{throw new a("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new a("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new a("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new a("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new a("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new a("Object::entries expects an object");return Object.entries(e)},hasOwn(e,t){if(!e||typeof e!="object")throw new a("Object::hasOwn expects an object");return Object.hasOwn(e,t)},fromEntries(e){if(!Array.isArray(e))throw new a("Object::fromEntries expects an array");return Object.fromEntries(e)},pick(e,t){if(!e||typeof e!="object")throw new a("Object::pick expects an object");if(!Array.isArray(t))throw new a("Object::pick expects an array of keys");let r={};for(let n of t)Object.hasOwn(e,n)&&(r[n]=e[n]);return r},omit(e,t){if(!e||typeof e!="object")throw new a("Object::omit expects an object");if(!Array.isArray(t))throw new a("Object::omit expects an array of keys");let r={...e};for(let n of t)delete r[n];return r}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)},of(...e){return Array.of(...e)},unique(e){if(!Array.isArray(e))throw new a("Array::unique expects an array");return[...new Set(e)]},compact(e){if(!Array.isArray(e))throw new a("Array::compact expects an array");return e.filter(Boolean)},chunk(e,t){if(!Array.isArray(e))throw new a("Array::chunk expects an array");if(!Number.isInteger(t)||t<=0)throw new a("Array::chunk expects a positive integer size");let r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r},range(e,t,r=1){if(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r))throw new a("Array::range expects finite numbers");if(r===0)throw new a("Array::range step cannot be 0");let n=[];if(e<=t)for(let s=e;s<=t;s+=r)n.push(s);else for(let s=e;s>=t;s-=Math.abs(r))n.push(s);return n}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},isInteger(e){return Number.isInteger(e)},parseInt(e,t=10){return Number.parseInt(e,t)},parseFloat(e){return Number.parseFloat(e)},clamp(e,t,r){return Math.min(Math.max(e,t),r)},toFixed(e,t=0){if(typeof e!="number")throw new a("Number::toFixed expects a number");return e.toFixed(t)},random(e=0,t=1){return Math.random()*(t-e)+e}},String:{fromCharCode(...e){return String.fromCharCode(...e)},capitalize(e){if(typeof e!="string")throw new a("String::capitalize expects a string");return e.length?e[0].toUpperCase()+e.slice(1):e}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},trunc(e){return Math.trunc(e)},sign(e){return Math.sign(e)},sqrt(e){return Math.sqrt(e)},pow(e,t){return e**t},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new a("Date::parse expects a string");return Date.parse(e)},new(e){return e===void 0?new Date:new Date(e)},iso(e){return new Date(e??Date.now()).toISOString()},timestamp(e){return new Date(e??Date.now()).getTime()}},Boolean:{valueOf(e){return!!e}},RegExp:{test(e,t,r=""){if(typeof e!="string")throw new a("RegExp::test expects a pattern string");if(typeof t!="string")throw new a("RegExp::test expects a value string");return new RegExp(e,r).test(t)},match(e,t,r=""){if(typeof e!="string")throw new a("RegExp::match expects a pattern string");if(typeof t!="string")throw new a("RegExp::match expects a value string");return t.match(new RegExp(e,r))}},URL:{encode(e){if(typeof e!="string")throw new a("URL::encode expects a string");return encodeURIComponent(e)},decode(e){if(typeof e!="string")throw new a("URL::decode expects a string");return decodeURIComponent(e)}}},we=(async()=>{}).constructor;function C(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,t=>he[t]):e}import{dirname as Me,isAbsolute as De,resolve as Ee}from"path";function A(e,...t){let r=De(e)?e:Ee(process.cwd(),e);if(t.length){let n=Me(r);return Ee(n,...t)}return r}function $(e,t,r){if(r.has(e)&&!t.has(e))throw new a(`Forbidden property access.
7
+ Access to this computed property '${e}' is forbidden.`);return e}var M="object",be=Symbol("__mutor_safe_context");function ve(e){return e&&(typeof e===M||typeof e=="function")&&typeof e.then=="function"}function T(e,t="",r=new Set){if(!e||typeof e!==M||ve(e)||r.has(e))return e;if(r.add(e),e instanceof Map){for(let[o,c]of e.entries())typeof o===M&&T(o,`${t}.mapKey`,r),e.set(o,T(c,`${t}.mapValue`,r));return e}if(e instanceof Set){let o=new Set;for(let c of e.values())o.add(T(c,t,r));e.clear();for(let c of o)e.add(c);return e}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==Array.prototype)throw new a(`Unsafe prototype detected at ${t||"root"} in context.`);if(Array.isArray(e)){for(let o=0;o<e.length;o++)e[o]=T(e[o],`${t}[${o}]`,r);return e}let s=Object.getOwnPropertyDescriptors(e);for(let o of Object.keys(s)){let c=s[o];if(c.get||c.set)throw new a(`Getter/setter not allowed at '${t}.${o}' in context.`);e[o]=T(e[o],`${t}.${o}`,r)}return e}function D(e){if(!e||typeof e!==M||be in e)return e;let t=T(e);return t&&typeof t===M&&Object.defineProperty(t,be,{value:!0,enumerable:!1,writable:!1,configurable:!1}),t}var G=(o=>(o[o.IDENT=0]="IDENT",o[o.KEYWORD=1]="KEYWORD",o[o.NUMBER=2]="NUMBER",o[o.STRING=3]="STRING",o[o.OPERATOR=4]="OPERATOR",o))(G||{}),H=(i=>(i[i.BINARY=0]="BINARY",i[i.TERNARY=1]="TERNARY",i[i.UNARY=2]="UNARY",i[i.CALL=3]="CALL",i[i.STRING=4]="STRING",i[i.NUMBER=5]="NUMBER",i[i.NAMESPACE=6]="NAMESPACE",i[i.IDENT=7]="IDENT",i[i.PROP_ACCESS=8]="PROP_ACCESS",i[i.GROUP=9]="GROUP",i[i.BOOLEAN=10]="BOOLEAN",i[i.UNDEFINED=11]="UNDEFINED",i[i.NULL=12]="NULL",i[i.FOR=13]="FOR",i[i.IF=14]="IF",i[i.ELSE_IF=15]="ELSE_IF",i[i.ELSE=16]="ELSE",i[i.END=17]="END",i))(H||{}),Q=(r=>(r[r.OF=0]="OF",r[r.IN=1]="IN",r))(Q||{}),Oe=(r=>(r[r.LOOP=0]="LOOP",r[r.NON_LOOP=1]="NON_LOOP",r))(Oe||{});function k(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function v(e,t){let n=e.slice(0,t).split(`
8
+ `).length,s=e.lastIndexOf(`
9
+ `,t-1)+1;return[n,s]}function B(e,t){let r=e.indexOf(`
10
+ `,t);return e.slice(t,r===-1?void 0:r).replaceAll(" "," ")}function Be(e,t){return e.scope.includes(t)?t:`ctx.${t}`}function Le(e){if(e.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:e.pos};let t=e.left.value,r=e.right.value;return`namespaces.${t}.${r}`}function Ue(e,t){let r=y(e,t.left),n=t.optional?"?.":"";if(t.bracketNotation){let o=y(e,t.right);return t.right.type===4||t.right.type===5?`${r}${n}[${o}]`:`${r}${n}[validateComputedProps(${o}, ${e.allowedProps}, ${e.forbiddenProps})]`}let s=t.right.value;if(e.forbiddenProps.has(s)&&!e.allowedProps.has(s))throw{message:"Forbidden property access.",pos:t.right.pos};return`${r}${n}.${s}`}function je(e,t){let r=y(e,t.expr),n=t.optional?"?.":"",s=t.args.map(o=>y(e,o)).join(", ");return`${r}${n}(${s})`}function ze(e,t){let{iterable:r,loopType:n,variable:s}=t,o=n===1?"in":"of";return`for(const ${s} ${o} ${F(r,e.context)}){`}function We(e,t){let{condition:r}=t;return`if(${F(r,e.context)}){`}function Ye(e,t){let{condition:r}=t;return`}else if(${F(r,e.context)}){`}function y(e,t){let{type:r}=t;if(r===5)return t.value;if(r===12)return"null";if(r===11)return"undefined";if(r===10)return t.true?"true":"false";switch(r){case 17:return"}";case 4:return`\`${/\$\\/.test(t.value)?k(t.value):t.value}\``;case 7:return Be(e,t.value);case 9:return`(${y(e,t.expr)})`;case 2:{let{operator:n,expr:s}=t;return`${n}${y(e,s)}`}case 0:{let{left:n,operator:s,right:o}=t;return`${y(e,n)} ${s} ${y(e,o)}`}case 1:{let{condition:n,left:s,right:o}=t;return`${y(e,n)} ? ${y(e,s)} : ${y(e,o)}`}case 8:return Ue(e,t);case 3:return je(e,t);case 6:return Le(t);case 13:return ze(e,t);case 16:return"} else {";case 14:return We(e,t);case 15:return Ye(e,t);default:throw new a(`Unsupported expression type '${r}'`)}}function F(e,t){let r={scope:t.scope,forbiddenProps:t.forbiddenProps,allowedProps:t.allowedProps,context:t},n=y(r,e);return n.includes("namespaces.Mutor.await")?n.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):n}function L(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function b(e,t,r){let n=e.tokens[e.cursor],s=e.tokens[e.tokens.length-1];if(!n)throw{message:`Unexpected end of expression. Expected ${r?`'${r}'`:`${t===0?"an":"a"} ${L(t)}`}.`,pos:s.pos+s.value.length-1};if(n.type!==t)throw{message:`Unexpected token type. Expected ${r?`'${r}'`:L(t)} but got ${L(n.type)} instead.`,pos:n.pos};if(r!==void 0&&n.value!==r)throw{message:`Unexpected token '${n.value}'. Expected ${t===0?"an":"a"} ${L(t)} instead.`,pos:n.pos};return e.tokens[e.cursor++]}function Ge(e){let t=e.tokens[e.cursor-1].pos,r=b(e,0).value,n;try{n=b(e,1,"in")}catch{n=b(e,1,"of")}let s=n.value==="in"?1:0,o=E(e);return{type:13,loopType:s,iterable:o,variable:r,pos:t}}function Se(e){let t=E(e);return{condition:t,pos:t.pos,type:14}}function qe(e){let t=e.tokens[e.cursor-1].pos;try{return b(e,1,"if"),{...Se(e),type:15,pos:t}}catch{return{type:16,pos:t}}}function xe(e){let t=[];if(e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===")")return t;for(t.push(E(e));e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===",";)e.cursor++,t.push(E(e));return t}function q(e){let t=e.tokens[e.cursor++];if(!t)throw{message:"Unexpected end of expression.",pos:e.tokens[e.tokens.length-1].pos};if(t.type===2)return{type:5,value:t.value,pos:t.pos};if(t.type===3)return{type:4,value:t.value,pos:t.pos};if(t.type===1){if(t.value==="for"&&e.cursor===1)return Ge(e);if(t.value==="true")return{type:10,true:!0,pos:t.pos};if(t.value==="false")return{type:10,true:!1,pos:t.pos};if(t.value==="undefined")return{type:11,pos:t.pos};if(t.value==="null")return{type:12,pos:t.pos};if(t.value==="end"&&e.tokens.length===1)return{type:17,pos:t.pos};if(t.value==="if"&&e.cursor===1)return Se(e);if(t.value==="else"&&e.cursor===1)return qe(e)}if(t.type===0)return{type:7,value:t.value,pos:t.pos};if(t.type===4&&t.value==="("){let r=E(e);return b(e,4,")"),{type:9,expr:r,pos:t.pos}}if(t.type===4&&ge.has(t.value)){let r=E(e);return{type:2,operator:t.value,expr:r,pos:t.pos}}throw{message:`Unexpected token '${t.value}'.`,pos:t.pos}}function Ke(e){let t=q(e);for(;e.tokens[e.cursor];){let r=e.tokens[e.cursor];if(r?.type===4&&r?.value==="("){if(e.cursor++,!e.generatingNamespace&&!e.config.allowFnCalls)throw{message:"Function calls are not allowed.",pos:r.pos};let n=xe(e);b(e,4,")"),t={type:3,expr:t,args:n,pos:e.tokens[e.cursor-1].pos}}else if(r?.type===4&&r?.value==="?."&&e.tokens[e.cursor+1]?.type===4&&e.tokens[e.cursor+1]?.value==="("){if(e.cursor+=2,!e.generatingNamespace&&!e.config.allowFnCalls)throw{message:"Function calls are not allowed.",pos:r.pos};let n=xe(e);b(e,4,")"),t={type:3,expr:t,args:n,optional:!0,pos:e.tokens[e.cursor-1].pos}}else if(r?.type===4&&de.has(r?.value)){let n=r.value==="::",s=r.value==="[",o=r.value==="?.";if(e.cursor++,n&&(e.tokens[e.cursor-2]?.type!==0||e.tokens[e.cursor]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e.tokens[e.cursor-2]?.value}::${e.tokens[e.cursor]?.value??""}' instead.`,pos:e.tokens[e.cursor]?.pos??e.tokens[e.cursor-1].pos};if(n){e.generatingNamespace=!0;let c=q(e);t={type:6,left:t,right:c,pos:e.tokens[e.cursor-1].pos}}else if(s){let c=E(e);b(e,4,"]"),t={type:8,left:t,right:c,bracketNotation:!0,pos:e.tokens[e.cursor-1].pos}}else if(o)if(e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="["){e.cursor++;let c=E(e);b(e,4,"]"),t={type:8,left:t,right:c,bracketNotation:!0,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let c=q(e);t={type:8,left:t,right:c,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let c=q(e);t={type:8,left:t,right:c,pos:e.tokens[e.cursor-1].pos}}}else break}return e.generatingNamespace=!1,t}function U(e,t,r){let n=t(e);for(;e.tokens[e.cursor]?.type===4&&r.has(e.tokens[e.cursor]?.value);){let s=e.tokens[e.cursor++].value,o=t(e);n={type:0,left:n,right:o,operator:s,pos:e.tokens[e.cursor-1].pos}}return n}function Je(e){return U(e,Ke,me)}function Ve(e){return U(e,Je,fe)}function Ze(e){return U(e,Ve,Z)}function He(e){return U(e,Ze,Z)}function _e(e){return U(e,He,le)}function Pe(e){let t=_e(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="&&";){e.cursor++;let r=_e(e);t={type:0,left:t,right:r,operator:"&&",pos:e.tokens[e.cursor-1].pos}}return t}function Re(e){let t=Pe(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="||";){e.cursor++;let r=Pe(e);t={type:0,left:t,right:r,operator:"||",pos:e.tokens[e.cursor-1].pos}}return t}function Qe(e){let t=Re(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="??";){e.cursor++;let r=Re(e);t={type:0,left:t,right:r,operator:"??",pos:e.tokens[e.cursor-1].pos}}return t}function E(e){let t=Qe(e);if(e.tokens[e.cursor]?.type!==4||e.tokens[e.cursor]?.value!=="?")return t;e.cursor++;let r=E(e);b(e,4,":");let n=E(e);return{type:1,condition:t,left:r,right:n,pos:e.tokens[e.cursor-1].pos}}function X(e,t){let r={cursor:0,tokens:e,config:t,generatingNamespace:!1},n=E(r);if(r.cursor!==r.tokens.length)throw{pos:r.tokens[r.cursor].pos,message:`Expected token '${r.tokens[r.cursor].value}'.
11
+ Expected an operator or the end of the expression.`};return n}function ee(e,{delimiters:t}){let r=`${t.openingTag}${t.whitespaceTrim}`,n=`${t.whitespaceTrim}${t.closingTag}`,s=e.startsWith(r),o=e.endsWith(n),c=s?r.length:t.openingTag.length,f=o?n.length:t.closingTag.length,p=e.slice(c,e.length-f),u=p.trim(),l=u.startsWith(t.commentTag);return l?{isComment:l,leftTrim:s,rightTrim:o}:{leftTrim:s,rightTrim:o,inner:p,isBlock:u.startsWith("for")||u.startsWith("if")||u.startsWith("else"),isBlockEnd:u==="end",hasContext:u.startsWith("for"),requiresBlockClose:u.startsWith("for")||u.startsWith("if"),usesAwait:p.includes("Mutor::await")}}var Xe=/[a-zA-Z$_]/,et=/[a-zA-Z$_0-9]/,tt=/[0-9]/,rt=/[0-9.oxe]/,nt=/[a-zA-Z$_0-9\s\t\r\n'"`]/;function te(e){let t=0,r="",n=[];function s(){let p="";if(Xe.test(r)){let u=t;for(;et.test(e[u])&&u<e.length;)p+=e[u],u++;n.push({type:ue.has(p)?1:0,value:p,pos:t}),t=u,r=e[t]}}function o(){if(r!=='"'&&r!=="'"&&r!=="`")return!1;let p=r,u=t,l=t+1,g="";for(;l<e.length;){let w=e[l];if(w==="\\"){if(l+1>=e.length)throw{pos:l,message:"Unexpected end of string after escape character."};g+=w,g+=e[l+1],l+=2;continue}if(w===p)break;g+=w,l++}if(l>=e.length||e[l]!==p)throw{pos:u,message:`String literal missing closing ${p}.`};n.push({type:3,value:g,pos:u}),t=l}function c(){if(tt.test(r)){let p=t,u="";for(;rt.test(e[p])&&p<e.length;)u+=e[p],p++;let l=Number(u);if(Number.isNaN(l))throw{pos:t,message:"Found invalid number literal."};n.push({type:2,value:`${l}`,pos:t}),t=p-1,r=e[t]}}function f(){let p=`${r}${e[t+1]}`;if(I.has(p)){n.push({type:4,value:p,pos:t}),t++;return}if(I.has(r)){n.push({type:4,value:r,pos:t});return}}for(;t<e.length;){if(r=e[t],c(),s(),o(),f(),!nt.test(r)&&!I.has(r)&&!I.has(e[t-1]+r))throw{message:`Unexpected token '${r}' in expression.`,pos:t};t++}return n.length?n:[{type:3,value:"",pos:0}]}function re(e,t,r){let n=[],s=[],{delimiters:o,keepOpeningTagEscapeDelimiter:c,allowFnCalls:f,allowedProps:p,forbiddenProps:u,autoEscape:l}=t,g="sync",w=!1,R=0,O='let acc="";';for(;R<e.length;){let W=function(){let m=d,x=0;for(;m>=o.openingTagEscape.length&&e.slice(m-o.openingTagEscape.length,m)===o.openingTagEscape;)x++,m-=o.openingTagEscape.length;return x%2===1};var pt=W;let d=e.indexOf(o.openingTag,R);if(d===-1){let m=e.slice(R);w&&(m=m.trimStart()),m&&(O+=`acc+=\`${k(m)}\`;`);break}if(W()){let m=e.slice(R,c?d+o.openingTagEscape.length+1:d-o.openingTag.length+1);w&&(m=m.trimStart(),w=!1),O+=`acc+=\`${k(m)}\`;`,c||(O+=`acc+=\`${o.openingTag}\`;`),R=d+o.openingTag.length;continue}let i=e.indexOf(o.closingTag,d);if(i===-1){let[m,x]=v(e,d),P=B(e,x);throw new _("No closing tag found.",m,P,d,r.path)}let K=e.slice(d,i+o.closingTag.length),{inner:ke,leftTrim:oe,rightTrim:Te,isBlock:J,isBlockEnd:se,hasContext:ie,requiresBlockClose:ae,isComment:Fe,usesAwait:Ie}=ee(K,{delimiters:o});Ie&&g!=="async"&&(g="async");let S=e.slice(R,d);S&&(w&&(S=S.trimStart()),oe&&(S=S.trimEnd()),S&&(O+=`acc+=\`${k(S)}\`;`)),w=!1,R=i+o.closingTag.length;try{if(!Fe){let m=te(ke),x=X(m,{allowFnCalls:f});if(J&&ae&&ie?(n.push(x.variable),s.push({type:0,pos:d})):J&&ae&&!ie&&s.push({type:1,pos:d}),se){let Y=s.pop();if(Y?.type===0&&n.pop(),Y===void 0)throw{message:"Unexpected end of block",pos:d}}let P=F(x,{allowedProps:p,forbiddenProps:u,scope:n});J||se?O+=P:O+=l&&!P.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${P});`:`acc+=${P};`}Te&&(w=!0)}catch(m){let{message:x,pos:P}=m,Y=oe?o.whitespaceTrim.length+o.openingTag.length:o.openingTag.length,ce=d+P+Y,[Ce,pe]=v(e,ce),$e=B(e,pe);throw new _(x,Ce,$e,ce-pe,r.path)}}if(s.length){let d=s.pop()?.pos,[W,i]=v(e,d),K=B(e,i);throw new _("Unclosed block detected.",W,K,d-i,r.path)}return O+="return acc;",g==="async"?new we("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",O):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",O)}var j=class{constructor(t={}){this.__cacheSize=0;this.__config={...h};this.__compiledTemplatesMap=new Map;this.__namespaces={...ye,Mutor:{await:async t=>await t}};this.addConfig(t)}addConfig(t){let{autoEscape:r,delimiters:n,allowedProps:s,forbiddenProps:o,keepOpeningTagEscapeDelimiter:c,allowFnCalls:f,cache:p,build:u,onIncludeFail:l,onIncludeError:g}=t;return this.__config={build:{include:new Set([...u?.include||h.build.include]),exclude:new Set([...h.build.exclude,...u?.exclude||[]])},autoEscape:r===!0?!0:r!==!1,allowedProps:s||h.allowedProps,allowFnCalls:!!f,onIncludeFail:l||h.onIncludeFail,onIncludeError:g||h.onIncludeError,cache:{...h.cache,...p||{}},forbiddenProps:new Set([...h.forbiddenProps,...o||[]]),keepOpeningTagEscapeDelimiter:c===!0?!0:c!==!1,delimiters:{...h.delimiters,...n||{}}},this.__config}restoreDefaultConfig(){this.__config={...h}}compile(t,r){return re(t,this.__config,{path:r?.renderedPath||"anonymous"})}renderAsync(t,r){return new Promise(n=>{n(this.render(t,r))})}render(t,r){let n=N(r,"anonymous");return this.__renderWithRuntime(t,n)}__renderWithRuntime(t,r){return this.compile(t,r)(D(r.context),this.__createNamespacesWithRuntime(r),this.__config.allowedProps,this.__config.forbiddenProps,C,$)}__createNamespacesWithRuntime(t){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:t.context}}}handleError(t,r,n,s){if(this.__config.onIncludeFail==="throw")throw t instanceof _?t:new a(t.message);let o={from:r,path:n,absolutePath:s};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(t instanceof _?console.log(t):console.log(`[Mutor.js]
12
+ ${t.message}`)),this.__config.onIncludeError?.(o,t)??""}createEntrySpaceForTemplate(t){if(this.__cacheSize+t<this.__config.cache.maxSize)return!0;if(t>this.__config.cache.maxSize)return!1;let r=this.__compiledTemplatesMap.entries().next().value;if(r){let[n,s]=r;this.__compiledTemplatesMap.delete(n),this.__cacheSize-=s.size}return this.createEntrySpaceForTemplate(t)}getDiagnostics(){let t=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:t,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(t/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:t>0?Math.min(100,Math.round(this.__cacheSize/t*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}register(t,r){let n=r.length*2+500;if(this.__cacheSize+n>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(n))throw new a(`The template for the component '${t}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let s=N(null,t);this.__cacheSize+=r.length*2+500,this.__compiledTemplatesMap.set(t,{fn:this.compile(r,s),size:n})}reset(){this.__config={...h},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var z=class extends j{constructor(t={}){super(t)}__setupIncludeForRuntime(t){this.__namespaces.Mutor.include=(r,n)=>{let s=A(t.renderedPath,r);if(t.includeStack.has(s))throw new a(`Circular include detected.
13
+ ${Array.from(t.includeStack).join(`
15
14
  `)}
16
- ${o}`);let c=r.renderedPath;r.includeStack.add(o),r.renderedPath=o;try{return this.__renderFile(o,s??r.context,r)}catch(l){return this.handleError(l,c,t,o)}finally{r.includeStack.delete(o),r.renderedPath=c}}}render(r,t){let s=C(t,"anonymous");return this.__setupIncludeForRuntime(s),this.__renderWithRuntime(r,s)}renderAsync(r,t){return new Promise(s=>{s(this.render(r,t))})}__renderFile(r,t,s){this.__setupIncludeForRuntime(s);let o=$(r),c,l=s.context,d=s.renderedPath;s.context=t??l,s.renderedPath=o;try{if(this.__config.cache.active&&this.__compiledTemplatesMap.has(o))c=this.__compiledTemplatesMap.get(o).fn;else{let f=Se(o,"utf-8");if(c=this.compile(f,s),this.__config.cache.active){let h=f.length*2+500;this.__cacheSize+h>this.__config.cache.maxSize?this.createEntrySpaceForTemplate(h)&&(this.__compiledTemplatesMap.set(o,{fn:c,size:h}),this.__cacheSize+=h):(this.__compiledTemplatesMap.set(o,{fn:c,size:h}),this.__cacheSize+=h)}}return c(B(s.context),this.__createNamespacesWithRuntime(s),this.__config.allowedProps,this.__config.forbiddenProps,L,j)}finally{s.context=l,s.renderedPath=d}}renderFile(r,t){return this.__renderFile(r,t,C(null,r))}renderFileAsync(r,t){return new Promise(s=>{s(this.renderFile(r,t))})}async buildDir(r,t,s){let o=$(t),c=$(r);await Fe(o,{recursive:!0});let l=await we(c,{withFileTypes:!0});await Promise.all(l.map(async d=>{let a=te(c,d.name),f=te(o,d.name);if(this.__config.build.exclude.has(d.name))return;if(d.isDirectory())return this.buildDir(a,f,s);let h=Ee(a);if(this.__config.build.include.has(h)){let y=this.renderFile(a,s);await Ce(f,y,"utf-8")}else return await Te(a,f)}))}async compileDir(r){let t=$(r),s=await we(t,{withFileTypes:!0});await Promise.all(s.map(async o=>{let c=te(t,o.name);if(this.__config.build.exclude.has(o.name))return;if(o.isDirectory())return this.compileDir(c);let l=Ee(c);if(this.__config.build.include.has(l))try{let d=await Ie(c,"utf-8");this.register(c,d)}catch{}}))}};var Gt=K;export{Gt as default};
15
+ ${s}`);let o=t.renderedPath;t.includeStack.add(s),t.renderedPath=s;try{return this.__renderFile(s,n??t.context,t)}catch(c){return this.handleError(c,o,r,s)}finally{t.includeStack.delete(s),t.renderedPath=o}}}render(t,r){let n=N(r,"anonymous");return this.__setupIncludeForRuntime(n),this.__renderWithRuntime(t,n)}renderAsync(t,r){return new Promise(n=>{n(this.render(t,r))})}__renderFile(t,r,n){this.__setupIncludeForRuntime(n);let s=A(t),o,c=n.context,f=n.renderedPath;n.context=r??c,n.renderedPath=s;try{if(this.__config.cache.active&&this.__compiledTemplatesMap.has(s))o=this.__compiledTemplatesMap.get(s).fn;else{let u=ot(s,"utf-8");if(o=this.compile(u,n),this.__config.cache.active){let l=u.length*2+500;this.__cacheSize+l>this.__config.cache.maxSize?this.createEntrySpaceForTemplate(l)&&(this.__compiledTemplatesMap.set(s,{fn:o,size:l}),this.__cacheSize+=l):(this.__compiledTemplatesMap.set(s,{fn:o,size:l}),this.__cacheSize+=l)}}return o(D(n.context),this.__createNamespacesWithRuntime(n),this.__config.allowedProps,this.__config.forbiddenProps,C,$)}finally{n.context=c,n.renderedPath=f}}renderFile(t,r){return this.__renderFile(t,r,N(null,t))}renderFileAsync(t,r){return new Promise(n=>{n(this.renderFile(t,r))})}async buildDir(t,r,n){let s=A(r),o=A(t);await it(s,{recursive:!0});let c=await Ne(o,{withFileTypes:!0});await Promise.all(c.map(async f=>{let p=ne(o,f.name),u=ne(s,f.name);if(this.__config.build.exclude.has(f.name))return;if(f.isDirectory())return this.buildDir(p,u,n);let l=Ae(p);if(this.__config.build.include.has(l)){let g=this.renderFile(p,n);await ct(u,g,"utf-8")}else return await st(p,u)}))}async compileDir(t){let r=A(t),n=await Ne(r,{withFileTypes:!0});await Promise.all(n.map(async s=>{let o=ne(r,s.name);if(this.__config.build.exclude.has(s.name))return;if(s.isDirectory())return this.compileDir(o);let c=Ae(o);if(this.__config.build.include.has(c))try{let f=await at(o,"utf-8");this.register(o,f)}catch{}}))}};var Er=z;export{Oe as BlockType,H as ExprType,Q as LoopType,G as TokenType,Er as default};
17
16
  //# sourceMappingURL=server.js.map