mutorjs 1.5.0 → 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/cli.cjs +19 -20
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +12 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -5
- package/dist/index.d.ts +191 -5
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/mutor.global.js +12 -13
- package/dist/mutor.global.js.map +1 -1
- package/dist/server.cjs +13 -14
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +191 -5
- package/dist/server.d.ts +191 -5
- package/dist/server.js +13 -14
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.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
|
-
|
|
39
|
-
|
|
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;
|
|
@@ -82,7 +267,8 @@ declare class Mutor extends MutorBase {
|
|
|
82
267
|
renderAsync(template: string, context: any): Promise<string>;
|
|
83
268
|
private __renderComponent;
|
|
84
269
|
renderComponent(identifier: string, context: any): string;
|
|
270
|
+
renderAsyncComponent(identifier: string, context: any): Promise<string>;
|
|
85
271
|
registerComponent(identifier: string, template: string): void;
|
|
86
272
|
}
|
|
87
273
|
|
|
88
|
-
export { Mutor as default };
|
|
274
|
+
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, Mutor as default };
|
package/dist/index.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
|
-
|
|
39
|
-
|
|
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;
|
|
@@ -82,7 +267,8 @@ declare class Mutor extends MutorBase {
|
|
|
82
267
|
renderAsync(template: string, context: any): Promise<string>;
|
|
83
268
|
private __renderComponent;
|
|
84
269
|
renderComponent(identifier: string, context: any): string;
|
|
270
|
+
renderAsyncComponent(identifier: string, context: any): Promise<string>;
|
|
85
271
|
registerComponent(identifier: string, template: string): void;
|
|
86
272
|
}
|
|
87
273
|
|
|
88
|
-
export { Mutor as default };
|
|
274
|
+
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, Mutor as default };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
function
|
|
1
|
+
function N(e,r=""){return{context:e,renderedPath:r,includeStack:new Set([r&&r])}}function J(e,r){return`${" ".repeat(e+r)}^`}var i=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},R=class e extends i{constructor(t,n,s,o,a){let h=n.toString().length+2,p=`${t}
|
|
2
2
|
|
|
3
|
-
`;
|
|
4
|
-
`,
|
|
5
|
-
`),
|
|
6
|
-
`,
|
|
7
|
-
Access to this computed property '${e}' is forbidden.`);return e}var
|
|
8
|
-
`).length,
|
|
9
|
-
`,r-1)+1;return[s
|
|
10
|
-
`,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function
|
|
11
|
-
Expected an operator or the end of the expression.`};return
|
|
12
|
-
|
|
13
|
-
${r.
|
|
14
|
-
${Array.from(r.includeStack).join(" -> ")} -> ${t}`);let o=r.renderedPath;r.includeStack.add(t),r.renderedPath=t;try{return this.__renderComponent(t,s??r.context,r)}catch(c){return this.handleError(c,o,t,void 0)}finally{r.includeStack.delete(t),r.renderedPath=o}}}render(r,t){let s=$(t,"anonymous");return this.__setupIncludeForRuntime(s),this.__renderWithRuntime(r,s)}renderAsync(r,t){return new Promise(s=>{s(this.render(r,t))})}__renderComponent(r,t,s){if(!this.__compiledTemplatesMap.has(r))throw new g(`No template exists with the identifier '${r}'`);let o=this.__compiledTemplatesMap.get(r),c=s.context,u=s.renderedPath;s.context=t??c,s.renderedPath=r;try{return o.fn(W(s.context),this.__createNamespacesWithRuntime(s),this.__config.allowedProps,this.__config.forbiddenProps,L,U)}finally{s.context=c,s.renderedPath=u}}renderComponent(r,t){return this.__renderComponent(r,t,$(t,r))}registerComponent(r,t){return this.register(r,t)}};var At=K;export{At as default};
|
|
3
|
+
`;p+=`at ${a}:${n}:${o+1}
|
|
4
|
+
`,n>1&&(p+=`${(n-1).toString().padStart(h-2)} | ...
|
|
5
|
+
`),p+=`${n} | ${s}
|
|
6
|
+
`,p+=J(o,h+1);super(p);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ae=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),C=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var pe=new Set(["==","!="]),V=new Set([">","<",">=","<="]);var ue=new Set(["+","-"]),le=new Set(["*","/","%"]),fe=new Set([".","?.","[","::"]),me=new Set(["-","+","!"]),ge={"&":"&","<":"<",">":">",'"':""","'":"'"},g={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}},de={JSON:{stringify(e,r){try{return JSON.stringify(e,null,r)}catch{throw new i("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new i("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new i("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new i("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new i("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new i("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new i("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new i("Object::fromEntries expects an array");return Object.fromEntries(e)},pick(e,r){if(!e||typeof e!="object")throw new i("Object::pick expects an object");if(!Array.isArray(r))throw new i("Object::pick expects an array of keys");let t={};for(let n of r)Object.hasOwn(e,n)&&(t[n]=e[n]);return t},omit(e,r){if(!e||typeof e!="object")throw new i("Object::omit expects an object");if(!Array.isArray(r))throw new i("Object::omit expects an array of keys");let t={...e};for(let n of r)delete t[n];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 i("Array::unique expects an array");return[...new Set(e)]},compact(e){if(!Array.isArray(e))throw new i("Array::compact expects an array");return e.filter(Boolean)},chunk(e,r){if(!Array.isArray(e))throw new i("Array::chunk expects an array");if(!Number.isInteger(r)||r<=0)throw new i("Array::chunk expects a positive integer size");let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t},range(e,r,t=1){if(!Number.isFinite(e)||!Number.isFinite(r)||!Number.isFinite(t))throw new i("Array::range expects finite numbers");if(t===0)throw new i("Array::range step cannot be 0");let n=[];if(e<=r)for(let s=e;s<=r;s+=t)n.push(s);else for(let s=e;s>=r;s-=Math.abs(t))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,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 i("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 i("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 i("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 i("RegExp::test expects a pattern string");if(typeof r!="string")throw new i("RegExp::test expects a value string");return new RegExp(e,t).test(r)},match(e,r,t=""){if(typeof e!="string")throw new i("RegExp::match expects a pattern string");if(typeof r!="string")throw new i("RegExp::match expects a value string");return r.match(new RegExp(e,t))}},URL:{encode(e){if(typeof e!="string")throw new i("URL::encode expects a string");return encodeURIComponent(e)},decode(e){if(typeof e!="string")throw new i("URL::decode expects a string");return decodeURIComponent(e)}}},he=(async()=>{}).constructor;function I(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>ge[r]):e}function $(e,r,t){if(t.has(e)&&!r.has(e))throw new i(`Forbidden property access.
|
|
7
|
+
Access to this computed property '${e}' is forbidden.`);return e}var F="object",ye=Symbol("__mutor_safe_context");function Te(e){return e&&(typeof e===F||typeof e=="function")&&typeof e.then=="function"}function k(e,r="",t=new Set){if(!e||typeof e!==F||Te(e)||t.has(e))return e;if(t.add(e),e instanceof Map){for(let[o,a]of e.entries())typeof o===F&&k(o,`${r}.mapKey`,t),e.set(o,k(a,`${r}.mapValue`,t));return e}if(e instanceof Set){let o=new Set;for(let a of e.values())o.add(k(a,r,t));e.clear();for(let a of o)e.add(a);return e}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==Array.prototype)throw new i(`Unsafe prototype detected at ${r||"root"} in context.`);if(Array.isArray(e)){for(let o=0;o<e.length;o++)e[o]=k(e[o],`${r}[${o}]`,t);return e}let s=Object.getOwnPropertyDescriptors(e);for(let o of Object.keys(s)){let a=s[o];if(a.get||a.set)throw new i(`Getter/setter not allowed at '${r}.${o}' in context.`);e[o]=k(e[o],`${r}.${o}`,t)}return e}function M(e){if(!e||typeof e!==F||ye in e)return e;let r=k(e);return r&&typeof r===F&&Object.defineProperty(r,ye,{value:!0,enumerable:!1,writable:!1,configurable:!1}),r}var Y=(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))(Y||{}),Z=(c=>(c[c.BINARY=0]="BINARY",c[c.TERNARY=1]="TERNARY",c[c.UNARY=2]="UNARY",c[c.CALL=3]="CALL",c[c.STRING=4]="STRING",c[c.NUMBER=5]="NUMBER",c[c.NAMESPACE=6]="NAMESPACE",c[c.IDENT=7]="IDENT",c[c.PROP_ACCESS=8]="PROP_ACCESS",c[c.GROUP=9]="GROUP",c[c.BOOLEAN=10]="BOOLEAN",c[c.UNDEFINED=11]="UNDEFINED",c[c.NULL=12]="NULL",c[c.FOR=13]="FOR",c[c.IF=14]="IF",c[c.ELSE_IF=15]="ELSE_IF",c[c.ELSE=16]="ELSE",c[c.END=17]="END",c))(Z||{}),H=(t=>(t[t.OF=0]="OF",t[t.IN=1]="IN",t))(H||{}),Ee=(t=>(t[t.LOOP=0]="LOOP",t[t.NON_LOOP=1]="NON_LOOP",t))(Ee||{});function A(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function v(e,r){let n=e.slice(0,r).split(`
|
|
8
|
+
`).length,s=e.lastIndexOf(`
|
|
9
|
+
`,r-1)+1;return[n,s]}function D(e,r){let t=e.indexOf(`
|
|
10
|
+
`,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function Ce(e,r){return e.scope.includes(r)?r:`ctx.${r}`}function Ie(e){if(e.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:e.pos};let r=e.left.value,t=e.right.value;return`namespaces.${r}.${t}`}function $e(e,r){let t=d(e,r.left),n=r.optional?"?.":"";if(r.bracketNotation){let o=d(e,r.right);return r.right.type===4||r.right.type===5?`${t}${n}[${o}]`:`${t}${n}[validateComputedProps(${o}, ${e.allowedProps}, ${e.forbiddenProps})]`}let s=r.right.value;if(e.forbiddenProps.has(s)&&!e.allowedProps.has(s))throw{message:"Forbidden property access.",pos:r.right.pos};return`${t}${n}.${s}`}function Fe(e,r){let t=d(e,r.expr),n=r.optional?"?.":"",s=r.args.map(o=>d(e,o)).join(", ");return`${t}${n}(${s})`}function Me(e,r){let{iterable:t,loopType:n,variable:s}=r,o=n===1?"in":"of";return`for(const ${s} ${o} ${T(t,e.context)}){`}function ve(e,r){let{condition:t}=r;return`if(${T(t,e.context)}){`}function De(e,r){let{condition:t}=r;return`}else if(${T(t,e.context)}){`}function d(e,r){let{type:t}=r;if(t===5)return r.value;if(t===12)return"null";if(t===11)return"undefined";if(t===10)return r.true?"true":"false";switch(t){case 17:return"}";case 4:return`\`${/\$\\/.test(r.value)?A(r.value):r.value}\``;case 7:return Ce(e,r.value);case 9:return`(${d(e,r.expr)})`;case 2:{let{operator:n,expr:s}=r;return`${n}${d(e,s)}`}case 0:{let{left:n,operator:s,right:o}=r;return`${d(e,n)} ${s} ${d(e,o)}`}case 1:{let{condition:n,left:s,right:o}=r;return`${d(e,n)} ? ${d(e,s)} : ${d(e,o)}`}case 8:return $e(e,r);case 3:return Fe(e,r);case 6:return Ie(r);case 13:return Me(e,r);case 16:return"} else {";case 14:return ve(e,r);case 15:return De(e,r);default:throw new i(`Unsupported expression type '${t}'`)}}function T(e,r){let t={scope:r.scope,forbiddenProps:r.forbiddenProps,allowedProps:r.allowedProps,context:r},n=d(t,e);return n.includes("namespaces.Mutor.await")?n.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):n}function B(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function O(e,r,t){let n=e.tokens[e.cursor],s=e.tokens[e.tokens.length-1];if(!n)throw{message:`Unexpected end of expression. Expected ${t?`'${t}'`:`${r===0?"an":"a"} ${B(r)}`}.`,pos:s.pos+s.value.length-1};if(n.type!==r)throw{message:`Unexpected token type. Expected ${t?`'${t}'`:B(r)} but got ${B(n.type)} instead.`,pos:n.pos};if(t!==void 0&&n.value!==t)throw{message:`Unexpected token '${n.value}'. Expected ${r===0?"an":"a"} ${B(r)} instead.`,pos:n.pos};return e.tokens[e.cursor++]}function Be(e){let r=e.tokens[e.cursor-1].pos,t=O(e,0).value,n;try{n=O(e,1,"in")}catch{n=O(e,1,"of")}let s=n.value==="in"?1:0,o=w(e);return{type:13,loopType:s,iterable:o,variable:t,pos:r}}function Re(e){let r=w(e);return{condition:r,pos:r.pos,type:14}}function Le(e){let r=e.tokens[e.cursor-1].pos;try{return O(e,1,"if"),{...Re(e),type:15,pos:r}}catch{return{type:16,pos:r}}}function we(e){let r=[];if(e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===")")return r;for(r.push(w(e));e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===",";)e.cursor++,r.push(w(e));return r}function G(e){let r=e.tokens[e.cursor++];if(!r)throw{message:"Unexpected end of expression.",pos:e.tokens[e.tokens.length-1].pos};if(r.type===2)return{type:5,value:r.value,pos:r.pos};if(r.type===3)return{type:4,value:r.value,pos:r.pos};if(r.type===1){if(r.value==="for"&&e.cursor===1)return Be(e);if(r.value==="true")return{type:10,true:!0,pos:r.pos};if(r.value==="false")return{type:10,true:!1,pos:r.pos};if(r.value==="undefined")return{type:11,pos:r.pos};if(r.value==="null")return{type:12,pos:r.pos};if(r.value==="end"&&e.tokens.length===1)return{type:17,pos:r.pos};if(r.value==="if"&&e.cursor===1)return Re(e);if(r.value==="else"&&e.cursor===1)return Le(e)}if(r.type===0)return{type:7,value:r.value,pos:r.pos};if(r.type===4&&r.value==="("){let t=w(e);return O(e,4,")"),{type:9,expr:t,pos:r.pos}}if(r.type===4&&me.has(r.value)){let t=w(e);return{type:2,operator:r.value,expr:t,pos:r.pos}}throw{message:`Unexpected token '${r.value}'.`,pos:r.pos}}function Ue(e){let r=G(e);for(;e.tokens[e.cursor];){let t=e.tokens[e.cursor];if(t?.type===4&&t?.value==="("){if(e.cursor++,!e.generatingNamespace&&!e.config.allowFnCalls)throw{message:"Function calls are not allowed.",pos:t.pos};let n=we(e);O(e,4,")"),r={type:3,expr:r,args:n,pos:e.tokens[e.cursor-1].pos}}else if(t?.type===4&&t?.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:t.pos};let n=we(e);O(e,4,")"),r={type:3,expr:r,args:n,optional:!0,pos:e.tokens[e.cursor-1].pos}}else if(t?.type===4&&fe.has(t?.value)){let n=t.value==="::",s=t.value==="[",o=t.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 a=G(e);r={type:6,left:r,right:a,pos:e.tokens[e.cursor-1].pos}}else if(s){let a=w(e);O(e,4,"]"),r={type:8,left:r,right:a,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 a=w(e);O(e,4,"]"),r={type:8,left:r,right:a,bracketNotation:!0,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let a=G(e);r={type:8,left:r,right:a,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let a=G(e);r={type:8,left:r,right:a,pos:e.tokens[e.cursor-1].pos}}}else break}return e.generatingNamespace=!1,r}function L(e,r,t){let n=r(e);for(;e.tokens[e.cursor]?.type===4&&t.has(e.tokens[e.cursor]?.value);){let s=e.tokens[e.cursor++].value,o=r(e);n={type:0,left:n,right:o,operator:s,pos:e.tokens[e.cursor-1].pos}}return n}function je(e){return L(e,Ue,le)}function We(e){return L(e,je,ue)}function ze(e){return L(e,We,V)}function Ye(e){return L(e,ze,V)}function Oe(e){return L(e,Ye,pe)}function xe(e){let r=Oe(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="&&";){e.cursor++;let t=Oe(e);r={type:0,left:r,right:t,operator:"&&",pos:e.tokens[e.cursor-1].pos}}return r}function be(e){let r=xe(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="||";){e.cursor++;let t=xe(e);r={type:0,left:r,right:t,operator:"||",pos:e.tokens[e.cursor-1].pos}}return r}function Ge(e){let r=be(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="??";){e.cursor++;let t=be(e);r={type:0,left:r,right:t,operator:"??",pos:e.tokens[e.cursor-1].pos}}return r}function w(e){let r=Ge(e);if(e.tokens[e.cursor]?.type!==4||e.tokens[e.cursor]?.value!=="?")return r;e.cursor++;let t=w(e);O(e,4,":");let n=w(e);return{type:1,condition:r,left:t,right:n,pos:e.tokens[e.cursor-1].pos}}function Q(e,r){let t={cursor:0,tokens:e,config:r,generatingNamespace:!1},n=w(t);if(t.cursor!==t.tokens.length)throw{pos:t.tokens[t.cursor].pos,message:`Expected token '${t.tokens[t.cursor].value}'.
|
|
11
|
+
Expected an operator or the end of the expression.`};return n}function X(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,n=`${r.whitespaceTrim}${r.closingTag}`,s=e.startsWith(t),o=e.endsWith(n),a=s?t.length:r.openingTag.length,h=o?n.length:r.closingTag.length,p=e.slice(a,e.length-h),u=p.trim(),l=u.startsWith(r.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 qe=/[a-zA-Z$_]/,Ke=/[a-zA-Z$_0-9]/,Je=/[0-9]/,Ve=/[0-9.oxe]/,Ze=/[a-zA-Z$_0-9\s\t\r\n'"`]/;function ee(e){let r=0,t="",n=[];function s(){let p="";if(qe.test(t)){let u=r;for(;Ke.test(e[u])&&u<e.length;)p+=e[u],u++;n.push({type:ae.has(p)?1:0,value:p,pos:r}),r=u,t=e[r]}}function o(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let p=t,u=r,l=r+1,y="";for(;l<e.length;){let E=e[l];if(E==="\\"){if(l+1>=e.length)throw{pos:l,message:"Unexpected end of string after escape character."};y+=E,y+=e[l+1],l+=2;continue}if(E===p)break;y+=E,l++}if(l>=e.length||e[l]!==p)throw{pos:u,message:`String literal missing closing ${p}.`};n.push({type:3,value:y,pos:u}),r=l}function a(){if(Je.test(t)){let p=r,u="";for(;Ve.test(e[p])&&p<e.length;)u+=e[p],p++;let l=Number(u);if(Number.isNaN(l))throw{pos:r,message:"Found invalid number literal."};n.push({type:2,value:`${l}`,pos:r}),r=p-1,t=e[r]}}function h(){let p=`${t}${e[r+1]}`;if(C.has(p)){n.push({type:4,value:p,pos:r}),r++;return}if(C.has(t)){n.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],a(),s(),o(),h(),!Ze.test(t)&&!C.has(t)&&!C.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return n.length?n:[{type:3,value:"",pos:0}]}function re(e,r,t){let n=[],s=[],{delimiters:o,keepOpeningTagEscapeDelimiter:a,allowFnCalls:h,allowedProps:p,forbiddenProps:u,autoEscape:l}=r,y="sync",E=!1,S=0,x='let acc="";';for(;S<e.length;){let W=function(){let f=m,b=0;for(;f>=o.openingTagEscape.length&&e.slice(f-o.openingTagEscape.length,f)===o.openingTagEscape;)b++,f-=o.openingTagEscape.length;return b%2===1};var He=W;let m=e.indexOf(o.openingTag,S);if(m===-1){let f=e.slice(S);E&&(f=f.trimStart()),f&&(x+=`acc+=\`${A(f)}\`;`);break}if(W()){let f=e.slice(S,a?m+o.openingTagEscape.length+1:m-o.openingTag.length+1);E&&(f=f.trimStart(),E=!1),x+=`acc+=\`${A(f)}\`;`,a||(x+=`acc+=\`${o.openingTag}\`;`),S=m+o.openingTag.length;continue}let c=e.indexOf(o.closingTag,m);if(c===-1){let[f,b]=v(e,m),P=D(e,b);throw new R("No closing tag found.",f,P,m,t.path)}let q=e.slice(m,c+o.closingTag.length),{inner:Pe,leftTrim:te,rightTrim:Se,isBlock:K,isBlockEnd:ne,hasContext:oe,requiresBlockClose:se,isComment:_e,usesAwait:Ne}=X(q,{delimiters:o});Ne&&y!=="async"&&(y="async");let _=e.slice(S,m);_&&(E&&(_=_.trimStart()),te&&(_=_.trimEnd()),_&&(x+=`acc+=\`${A(_)}\`;`)),E=!1,S=c+o.closingTag.length;try{if(!_e){let f=ee(Pe),b=Q(f,{allowFnCalls:h});if(K&&se&&oe?(n.push(b.variable),s.push({type:0,pos:m})):K&&se&&!oe&&s.push({type:1,pos:m}),ne){let z=s.pop();if(z?.type===0&&n.pop(),z===void 0)throw{message:"Unexpected end of block",pos:m}}let P=T(b,{allowedProps:p,forbiddenProps:u,scope:n});K||ne?x+=P:x+=l&&!P.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${P});`:`acc+=${P};`}Se&&(E=!0)}catch(f){let{message:b,pos:P}=f,z=te?o.whitespaceTrim.length+o.openingTag.length:o.openingTag.length,ie=m+P+z,[Ae,ce]=v(e,ie),ke=D(e,ce);throw new R(b,Ae,ke,ie-ce,t.path)}}if(s.length){let m=s.pop()?.pos,[W,c]=v(e,m),q=D(e,c);throw new R("Unclosed block detected.",W,q,m-c,t.path)}return x+="return acc;",y==="async"?new he("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",x):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",x)}var U=class{constructor(r={}){this.__cacheSize=0;this.__config={...g};this.__compiledTemplatesMap=new Map;this.__namespaces={...de,Mutor:{await:async r=>await r}};this.addConfig(r)}addConfig(r){let{autoEscape:t,delimiters:n,allowedProps:s,forbiddenProps:o,keepOpeningTagEscapeDelimiter:a,allowFnCalls:h,cache:p,build:u,onIncludeFail:l,onIncludeError:y}=r;return this.__config={build:{include:new Set([...u?.include||g.build.include]),exclude:new Set([...g.build.exclude,...u?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:s||g.allowedProps,allowFnCalls:!!h,onIncludeFail:l||g.onIncludeFail,onIncludeError:y||g.onIncludeError,cache:{...g.cache,...p||{}},forbiddenProps:new Set([...g.forbiddenProps,...o||[]]),keepOpeningTagEscapeDelimiter:a===!0?!0:a!==!1,delimiters:{...g.delimiters,...n||{}}},this.__config}restoreDefaultConfig(){this.__config={...g}}compile(r,t){return re(r,this.__config,{path:t?.renderedPath||"anonymous"})}renderAsync(r,t){return new Promise(n=>{n(this.render(r,t))})}render(r,t){let n=N(t,"anonymous");return this.__renderWithRuntime(r,n)}__renderWithRuntime(r,t){return this.compile(r,t)(M(t.context),this.__createNamespacesWithRuntime(t),this.__config.allowedProps,this.__config.forbiddenProps,I,$)}__createNamespacesWithRuntime(r){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:r.context}}}handleError(r,t,n,s){if(this.__config.onIncludeFail==="throw")throw r instanceof R?r:new i(r.message);let o={from:t,path:n,absolutePath:s};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(r instanceof R?console.log(r):console.log(`[Mutor.js]
|
|
12
|
+
${r.message}`)),this.__config.onIncludeError?.(o,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[n,s]=t;this.__compiledTemplatesMap.delete(n),this.__cacheSize-=s.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 n=t.length*2+500;if(this.__cacheSize+n>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(n))throw new i(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let s=N(null,r);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t,s),size:n})}reset(){this.__config={...g},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var j=class extends U{constructor(r={}){super(r)}__setupIncludeForRuntime(r){this.__namespaces.Mutor.include=(t,n)=>{if(r.includeStack.has(t))throw new i(`Circular include detected.
|
|
13
|
+
${Array.from(r.includeStack).join(" -> ")} -> ${t}`);let s=r.renderedPath;r.includeStack.add(t),r.renderedPath=t;try{return this.__renderComponent(t,n??r.context,r)}catch(o){return this.handleError(o,s,t,void 0)}finally{r.includeStack.delete(t),r.renderedPath=s}}}render(r,t){let n=N(t,"anonymous");return this.__setupIncludeForRuntime(n),this.__renderWithRuntime(r,n)}renderAsync(r,t){return new Promise(n=>{n(this.render(r,t))})}__renderComponent(r,t,n){if(!this.__compiledTemplatesMap.has(r))throw new i(`No template exists with the identifier '${r}'`);let s=this.__compiledTemplatesMap.get(r),o=n.context,a=n.renderedPath;n.context=t??o,n.renderedPath=r;try{return s.fn(M(n.context),this.__createNamespacesWithRuntime(n),this.__config.allowedProps,this.__config.forbiddenProps,I,$)}finally{n.context=o,n.renderedPath=a}}renderComponent(r,t){return this.__renderComponent(r,t,N(t,r))}renderAsyncComponent(r,t){return new Promise(n=>{n(this.renderComponent(r,t))})}registerComponent(r,t){return this.register(r,t)}};var rt=j;export{Ee as BlockType,Z as ExprType,H as LoopType,Y as TokenType,rt as default};
|
|
15
14
|
//# sourceMappingURL=index.js.map
|