@xaendar/compiler 0.3.33 → 0.3.34
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/package.json +3 -3
- package/xaendar-compiler.es.js +349 -358
- package/xaendar-compiler.es.js.map +1 -1
package/xaendar-compiler.es.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Stack as e } from "@xaendar/common";
|
|
2
|
-
import
|
|
1
|
+
import { Stack as e, indent as t } from "@xaendar/common";
|
|
2
|
+
import n from "typescript";
|
|
3
3
|
//#region ../packages/compiler/src/lexer/types/lexer-state.enum.ts
|
|
4
|
-
var
|
|
4
|
+
var r = /* @__PURE__ */ function(e) {
|
|
5
5
|
return e.START = "start", e.TEXT = "text", e.TAG_OPEN_NAME = "tag-open-name", e.TAG_BODY = "tag-body", e.TAG_OPEN_END = "tag-open-end", e.TAG_CLOSE = "tag-close", e.ATTRIBUTE = "attribute", e.EVENT = "event", e.FLOW_CONTROL = "flow-control", e.FLOW_CONTROL_CONDITION = "flow-control-condition", e.CASE_FLOW_CONTROL_CONDITION = "case-flow-control-condition", e.FLOW_CONTROL_BLOCK = "flow-control-block", e.INTERPOLATION = "interpolation", e.INTERPOLATION_EXPRESSION = "interpolation-expression", e.INTERPOLATION_LITERAL = "interpolation-literal", e.CONST_DECLARATION = "const-declaration", e;
|
|
6
|
-
}({}),
|
|
6
|
+
}({}), i = /* @__PURE__ */ function(e) {
|
|
7
7
|
return e[e.TEXT = 0] = "TEXT", e[e.TAG_OPEN_NAME = 1] = "TAG_OPEN_NAME", e[e.TAG_SELF_CLOSE = 2] = "TAG_SELF_CLOSE", e[e.TAG_OPEN_END = 3] = "TAG_OPEN_END", e[e.TAG_CLOSE_NAME = 4] = "TAG_CLOSE_NAME", e[e.ATTRIBUTE = 5] = "ATTRIBUTE", e[e.EVENT = 6] = "EVENT", e[e.INTERPOLATION_LITERAL = 7] = "INTERPOLATION_LITERAL", e[e.INTERPOLATION_EXPRESSION = 8] = "INTERPOLATION_EXPRESSION", e[e.CONST_DECLARATION = 9] = "CONST_DECLARATION", e[e.IF = 10] = "IF", e[e.FOR = 11] = "FOR", e[e.ELSE = 12] = "ELSE", e[e.ELSE_IF = 13] = "ELSE_IF", e[e.SWITCH = 14] = "SWITCH", e[e.CASE = 15] = "CASE", e[e.DEFAULT = 16] = "DEFAULT", e[e.CONDITION = 17] = "CONDITION", e[e.BLOCK_OPEN = 18] = "BLOCK_OPEN", e[e.BLOCK_CLOSE = 19] = "BLOCK_CLOSE", e[e.EOF = 20] = "EOF", e;
|
|
8
8
|
}({});
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region ../packages/compiler/src/lexer/states/attribute.state.ts
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
for (;
|
|
11
|
+
function a(e, t) {
|
|
12
|
+
let n = !0, a = "", o;
|
|
13
|
+
for (; n;) switch (e.peek()) {
|
|
14
14
|
case 32:
|
|
15
15
|
case 47:
|
|
16
16
|
case 62:
|
|
17
17
|
o = {
|
|
18
|
-
state:
|
|
18
|
+
state: r.TAG_BODY,
|
|
19
19
|
tokens: [{
|
|
20
|
-
type:
|
|
20
|
+
type: i.ATTRIBUTE,
|
|
21
21
|
parts: [a]
|
|
22
22
|
}]
|
|
23
|
-
},
|
|
23
|
+
}, n = !1;
|
|
24
24
|
break;
|
|
25
25
|
case 123:
|
|
26
26
|
o = {
|
|
27
|
-
state:
|
|
27
|
+
state: r.INTERPOLATION,
|
|
28
28
|
tokens: [{
|
|
29
|
-
type:
|
|
29
|
+
type: i.ATTRIBUTE,
|
|
30
30
|
parts: [a]
|
|
31
31
|
}],
|
|
32
32
|
pushState: !0
|
|
33
|
-
},
|
|
33
|
+
}, n = !1;
|
|
34
34
|
break;
|
|
35
35
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
36
36
|
}
|
|
@@ -38,63 +38,63 @@ function i(e, t) {
|
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region ../packages/compiler/src/lexer/utils/consume-flow-control-condition.utils.ts
|
|
41
|
-
function
|
|
41
|
+
function o(e, t) {
|
|
42
42
|
if (e.skipSpaces(), e.peek() !== 40) throw Error(`Expected '(' but got '${String.fromCharCode(e.peek())}' at row ${e.position.row}, col ${e.position.column}`);
|
|
43
43
|
e.advance();
|
|
44
44
|
let n = "", r = 1;
|
|
45
45
|
for (; r > 0;) switch (e.peek()) {
|
|
46
46
|
case 40:
|
|
47
|
-
r++, n =
|
|
47
|
+
r++, n = s(e, n);
|
|
48
48
|
break;
|
|
49
49
|
case 41:
|
|
50
50
|
if (r--, !r) {
|
|
51
51
|
e.advance();
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
|
-
n =
|
|
54
|
+
n = s(e, n);
|
|
55
55
|
break;
|
|
56
|
-
default: n =
|
|
56
|
+
default: n = s(e, n);
|
|
57
57
|
}
|
|
58
58
|
return n;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function s(e, t) {
|
|
61
61
|
return e.advance(), `${t}${e.currentChar.value}`;
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region ../packages/compiler/src/lexer/states/case-flow-control-condition.state.ts
|
|
65
|
-
function
|
|
66
|
-
let
|
|
65
|
+
function c(e, t) {
|
|
66
|
+
let n = o(e, t);
|
|
67
67
|
return e.skipSpaces(), {
|
|
68
|
-
state: e.peekMatch("@case") ?
|
|
68
|
+
state: e.peekMatch("@case") ? r.FLOW_CONTROL : r.FLOW_CONTROL_BLOCK,
|
|
69
69
|
tokens: [{
|
|
70
|
-
type:
|
|
71
|
-
parts: [
|
|
70
|
+
type: i.CONDITION,
|
|
71
|
+
parts: [n]
|
|
72
72
|
}],
|
|
73
73
|
popState: !0
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region ../packages/compiler/src/lexer/states/const-declaration.ts
|
|
78
|
-
function
|
|
79
|
-
let
|
|
80
|
-
for (e.skipSpaces();
|
|
78
|
+
function l(e, t) {
|
|
79
|
+
let n = !0, a = "", o = "", s;
|
|
80
|
+
for (e.skipSpaces(); n;) switch (e.peek()) {
|
|
81
81
|
case 32:
|
|
82
|
-
|
|
82
|
+
n = !1;
|
|
83
83
|
break;
|
|
84
84
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
85
85
|
}
|
|
86
86
|
e.skipSpaces();
|
|
87
87
|
let c = e.peek();
|
|
88
88
|
if (c !== 61) throw Error(`Unexpected character ${String.fromCharCode(c)}.\nExpected '=' `);
|
|
89
|
-
for (e.advance(), e.skipSpaces(),
|
|
89
|
+
for (e.advance(), e.skipSpaces(), n = !0; n;) switch (e.peek()) {
|
|
90
90
|
case 59:
|
|
91
91
|
s = {
|
|
92
|
-
state:
|
|
92
|
+
state: r.TEXT,
|
|
93
93
|
tokens: [{
|
|
94
|
-
type:
|
|
94
|
+
type: i.CONST_DECLARATION,
|
|
95
95
|
parts: [a, o]
|
|
96
96
|
}]
|
|
97
|
-
},
|
|
97
|
+
}, n = !1;
|
|
98
98
|
break;
|
|
99
99
|
default: e.advance(), o = `${o}${e.currentChar.value}`;
|
|
100
100
|
}
|
|
@@ -102,19 +102,19 @@ function c(e, t) {
|
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region ../packages/compiler/src/lexer/states/event.state.ts
|
|
105
|
-
function
|
|
106
|
-
let
|
|
107
|
-
for (e.advance();
|
|
105
|
+
function u(e, t) {
|
|
106
|
+
let n = !0, a = "", o;
|
|
107
|
+
for (e.advance(); n;) switch (e.peek()) {
|
|
108
108
|
case 32:
|
|
109
109
|
case 47:
|
|
110
110
|
case 62:
|
|
111
111
|
a.includes("=") || (a = `${a}=on${a[0].toUpperCase()}${a.slice(1)}($event)`), o = {
|
|
112
|
-
state:
|
|
112
|
+
state: r.TAG_BODY,
|
|
113
113
|
tokens: [{
|
|
114
|
-
type:
|
|
114
|
+
type: i.EVENT,
|
|
115
115
|
parts: [a]
|
|
116
116
|
}]
|
|
117
|
-
},
|
|
117
|
+
}, n = !1;
|
|
118
118
|
break;
|
|
119
119
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
120
120
|
}
|
|
@@ -122,117 +122,117 @@ function l(e, t) {
|
|
|
122
122
|
}
|
|
123
123
|
//#endregion
|
|
124
124
|
//#region ../packages/compiler/src/lexer/states/flow-control-block.state.ts
|
|
125
|
-
function
|
|
125
|
+
function d(e, t) {
|
|
126
126
|
if (e.skipSpaces(), e.peek() !== 123) throw Error(`Expected '{' but got '${String.fromCharCode(e.peek())}' at row ${e.position.row}, col ${e.position.column}`);
|
|
127
127
|
return e.advance(), {
|
|
128
|
-
state:
|
|
129
|
-
tokens: [{ type:
|
|
128
|
+
state: r.TEXT,
|
|
129
|
+
tokens: [{ type: i.BLOCK_OPEN }],
|
|
130
130
|
pushState: !0
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
//#endregion
|
|
134
134
|
//#region ../packages/compiler/src/lexer/states/default-flow-control-condition.state.ts
|
|
135
|
-
function
|
|
135
|
+
function f(e, t) {
|
|
136
136
|
return {
|
|
137
|
-
state:
|
|
137
|
+
state: r.FLOW_CONTROL_BLOCK,
|
|
138
138
|
tokens: [{
|
|
139
|
-
type:
|
|
140
|
-
parts: [
|
|
139
|
+
type: i.CONDITION,
|
|
140
|
+
parts: [o(e, t)]
|
|
141
141
|
}],
|
|
142
142
|
popState: !0
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region ../packages/compiler/src/lexer/states/flow-control.ts
|
|
147
|
-
function
|
|
148
|
-
let
|
|
149
|
-
return e.advance(), e.peekMatch("for ") ? (e.advance(4),
|
|
150
|
-
state:
|
|
151
|
-
tokens: [{ type:
|
|
147
|
+
function p(e, t) {
|
|
148
|
+
let n;
|
|
149
|
+
return e.advance(), e.peekMatch("for ") ? (e.advance(4), n = {
|
|
150
|
+
state: r.FLOW_CONTROL_CONDITION,
|
|
151
|
+
tokens: [{ type: i.FOR }],
|
|
152
152
|
pushState: !0
|
|
153
|
-
}) : e.peekMatch("if ") ? (e.advance(2),
|
|
154
|
-
state:
|
|
155
|
-
tokens: [{ type:
|
|
153
|
+
}) : e.peekMatch("if ") ? (e.advance(2), n = {
|
|
154
|
+
state: r.FLOW_CONTROL_CONDITION,
|
|
155
|
+
tokens: [{ type: i.IF }],
|
|
156
156
|
pushState: !0
|
|
157
|
-
}) : e.peekMatch("else if ") ? (e.advance(8),
|
|
158
|
-
state:
|
|
159
|
-
tokens: [{ type:
|
|
157
|
+
}) : e.peekMatch("else if ") ? (e.advance(8), n = {
|
|
158
|
+
state: r.FLOW_CONTROL_CONDITION,
|
|
159
|
+
tokens: [{ type: i.ELSE_IF }],
|
|
160
160
|
pushState: !0
|
|
161
|
-
}) : e.peekMatch("else ") ? (e.advance(5),
|
|
162
|
-
state:
|
|
163
|
-
tokens: [{ type:
|
|
164
|
-
}) : e.peekMatch("switch ") ? (e.advance(7),
|
|
165
|
-
state:
|
|
166
|
-
tokens: [{ type:
|
|
161
|
+
}) : e.peekMatch("else ") ? (e.advance(5), n = {
|
|
162
|
+
state: r.FLOW_CONTROL_BLOCK,
|
|
163
|
+
tokens: [{ type: i.ELSE }]
|
|
164
|
+
}) : e.peekMatch("switch ") ? (e.advance(7), n = {
|
|
165
|
+
state: r.FLOW_CONTROL_CONDITION,
|
|
166
|
+
tokens: [{ type: i.SWITCH }],
|
|
167
167
|
pushState: !0
|
|
168
|
-
}) : e.peekMatch("case ") ? (e.advance(5),
|
|
169
|
-
state:
|
|
170
|
-
tokens: [{ type:
|
|
168
|
+
}) : e.peekMatch("case ") ? (e.advance(5), n = {
|
|
169
|
+
state: r.CASE_FLOW_CONTROL_CONDITION,
|
|
170
|
+
tokens: [{ type: i.CASE }],
|
|
171
171
|
pushState: !0
|
|
172
|
-
}) : e.peekMatch("default ") ? (e.advance(8),
|
|
173
|
-
state:
|
|
174
|
-
tokens: [{ type:
|
|
175
|
-
}) : e.peekMatch("const ") && (e.advance(6),
|
|
172
|
+
}) : e.peekMatch("default ") ? (e.advance(8), n = {
|
|
173
|
+
state: r.FLOW_CONTROL_BLOCK,
|
|
174
|
+
tokens: [{ type: i.DEFAULT }]
|
|
175
|
+
}) : e.peekMatch("const ") && (e.advance(6), n = { state: r.CONST_DECLARATION }), n;
|
|
176
176
|
}
|
|
177
177
|
//#endregion
|
|
178
178
|
//#region ../packages/compiler/src/lexer/states/interpolation-expression.state.ts
|
|
179
|
-
function
|
|
180
|
-
let
|
|
181
|
-
for (;
|
|
179
|
+
function m(e, t) {
|
|
180
|
+
let n = !0, a = "", o = 1, s;
|
|
181
|
+
for (; n;) switch (e.peek()) {
|
|
182
182
|
case 123:
|
|
183
|
-
o++, a =
|
|
183
|
+
o++, a = h(e, a);
|
|
184
184
|
break;
|
|
185
185
|
case 125:
|
|
186
186
|
if (o--, o === 0) {
|
|
187
187
|
e.advance();
|
|
188
188
|
let o = t.history.pop(), c;
|
|
189
189
|
switch (o) {
|
|
190
|
-
case
|
|
190
|
+
case r.ATTRIBUTE:
|
|
191
191
|
let e = t.tokens[t.tokens.length - 1];
|
|
192
|
-
e?.type ===
|
|
192
|
+
e?.type === i.ATTRIBUTE && !e.parts[0] && (e.parts[0] = `${a}=`), c = r.TAG_BODY;
|
|
193
193
|
break;
|
|
194
|
-
case
|
|
194
|
+
case r.TEXT: c = r.TEXT;
|
|
195
195
|
}
|
|
196
196
|
s = {
|
|
197
197
|
state: c,
|
|
198
198
|
tokens: [{
|
|
199
|
-
type:
|
|
199
|
+
type: i.INTERPOLATION_EXPRESSION,
|
|
200
200
|
parts: [a]
|
|
201
201
|
}],
|
|
202
202
|
popState: !0
|
|
203
|
-
},
|
|
204
|
-
} else a =
|
|
203
|
+
}, n = !1;
|
|
204
|
+
} else a = h(e, a);
|
|
205
205
|
break;
|
|
206
|
-
default: a =
|
|
206
|
+
default: a = h(e, a);
|
|
207
207
|
}
|
|
208
208
|
return s;
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function h(e, t) {
|
|
211
211
|
return e.advance(1), `${t}${e.currentChar.value}`;
|
|
212
212
|
}
|
|
213
213
|
//#endregion
|
|
214
214
|
//#region ../packages/compiler/src/lexer/states/interpolation-literal.state.ts
|
|
215
|
-
function
|
|
216
|
-
let
|
|
217
|
-
for (e.advance();
|
|
215
|
+
function ee(e, t) {
|
|
216
|
+
let n = !0, a = "`", o;
|
|
217
|
+
for (e.advance(); n;) switch (e.peek()) {
|
|
218
218
|
case 96:
|
|
219
219
|
if (a = g(e, a), e.peek() === 125) {
|
|
220
220
|
e.advance();
|
|
221
221
|
let s = t.history.pop(), c;
|
|
222
222
|
switch (s) {
|
|
223
|
-
case
|
|
224
|
-
c =
|
|
223
|
+
case r.ATTRIBUTE:
|
|
224
|
+
c = r.TAG_BODY;
|
|
225
225
|
break;
|
|
226
|
-
case
|
|
226
|
+
case r.TEXT: c = r.TEXT;
|
|
227
227
|
}
|
|
228
228
|
o = {
|
|
229
229
|
state: c,
|
|
230
230
|
tokens: [{
|
|
231
|
-
type:
|
|
231
|
+
type: i.INTERPOLATION_LITERAL,
|
|
232
232
|
parts: [a]
|
|
233
233
|
}],
|
|
234
234
|
popState: !0
|
|
235
|
-
},
|
|
235
|
+
}, n = !1;
|
|
236
236
|
} else a = `${a}${e.currentChar.value}`;
|
|
237
237
|
break;
|
|
238
238
|
default: a = g(e, a);
|
|
@@ -244,55 +244,55 @@ function g(e, t) {
|
|
|
244
244
|
}
|
|
245
245
|
//#endregion
|
|
246
246
|
//#region ../packages/compiler/src/utils/chars.utils.ts
|
|
247
|
-
function
|
|
247
|
+
function te(e) {
|
|
248
248
|
return /\S/.test(e);
|
|
249
249
|
}
|
|
250
|
-
function
|
|
250
|
+
function ne(e) {
|
|
251
251
|
return e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 36 || e === 95;
|
|
252
252
|
}
|
|
253
253
|
//#endregion
|
|
254
254
|
//#region ../packages/compiler/src/lexer/states/interpolation.state.ts
|
|
255
|
-
function
|
|
256
|
-
let
|
|
255
|
+
function _(e, t) {
|
|
256
|
+
let n;
|
|
257
257
|
e.advance(), e.skipSpaces();
|
|
258
258
|
let i = e.peek();
|
|
259
|
-
if (i === 96)
|
|
260
|
-
else if (
|
|
259
|
+
if (i === 96) n = { state: r.INTERPOLATION_LITERAL };
|
|
260
|
+
else if (ne(i)) n = { state: r.INTERPOLATION_EXPRESSION };
|
|
261
261
|
else throw Error(`Unrecognized First Character ${String.fromCharCode(i)} in interpolation`);
|
|
262
|
-
return
|
|
262
|
+
return n;
|
|
263
263
|
}
|
|
264
264
|
//#endregion
|
|
265
265
|
//#region ../packages/compiler/src/lexer/states/tag-body.state.ts
|
|
266
|
-
function
|
|
267
|
-
let
|
|
268
|
-
for (;
|
|
266
|
+
function v(e, t) {
|
|
267
|
+
let n = !0, i;
|
|
268
|
+
for (; n;) switch (e.peek()) {
|
|
269
269
|
case 64:
|
|
270
|
-
i = { state:
|
|
270
|
+
i = { state: r.EVENT }, n = !1;
|
|
271
271
|
break;
|
|
272
272
|
case 32:
|
|
273
273
|
e.skipSpaces();
|
|
274
274
|
break;
|
|
275
275
|
case 62:
|
|
276
276
|
case 47:
|
|
277
|
-
i = { state:
|
|
277
|
+
i = { state: r.TAG_OPEN_END }, n = !1;
|
|
278
278
|
break;
|
|
279
|
-
default: i = { state:
|
|
279
|
+
default: i = { state: r.ATTRIBUTE }, n = !1;
|
|
280
280
|
}
|
|
281
281
|
return i;
|
|
282
282
|
}
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region ../packages/compiler/src/lexer/states/tag-close.state.ts
|
|
285
|
-
function
|
|
286
|
-
let
|
|
287
|
-
for (e.advance(2), e.skipSpaces();
|
|
285
|
+
function y(e, t) {
|
|
286
|
+
let n = !0, a = "", o;
|
|
287
|
+
for (e.advance(2), e.skipSpaces(); n;) switch (e.peek()) {
|
|
288
288
|
case 62:
|
|
289
289
|
e.advance(), o = {
|
|
290
|
-
state:
|
|
290
|
+
state: r.TEXT,
|
|
291
291
|
tokens: [{
|
|
292
|
-
type:
|
|
292
|
+
type: i.TAG_CLOSE_NAME,
|
|
293
293
|
parts: [a]
|
|
294
294
|
}]
|
|
295
|
-
},
|
|
295
|
+
}, n = !1;
|
|
296
296
|
break;
|
|
297
297
|
case 32: throw Error("Tag Close Name cannot contains spaces");
|
|
298
298
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
@@ -301,44 +301,44 @@ function ee(e, t) {
|
|
|
301
301
|
}
|
|
302
302
|
//#endregion
|
|
303
303
|
//#region ../packages/compiler/src/lexer/states/tag-open-end.state.ts
|
|
304
|
-
function
|
|
305
|
-
let
|
|
306
|
-
if (e.peek() === 62) e.advance(),
|
|
307
|
-
state:
|
|
304
|
+
function b(e, t) {
|
|
305
|
+
let n;
|
|
306
|
+
if (e.peek() === 62) e.advance(), n = {
|
|
307
|
+
state: r.TEXT,
|
|
308
308
|
tokens: [{
|
|
309
|
-
type:
|
|
309
|
+
type: i.TAG_OPEN_END,
|
|
310
310
|
parts: []
|
|
311
311
|
}]
|
|
312
312
|
};
|
|
313
313
|
else {
|
|
314
314
|
e.advance();
|
|
315
315
|
let t = e.peek();
|
|
316
|
-
if (t === 62) e.advance(),
|
|
317
|
-
state:
|
|
316
|
+
if (t === 62) e.advance(), n = {
|
|
317
|
+
state: r.TEXT,
|
|
318
318
|
tokens: [{
|
|
319
|
-
type:
|
|
319
|
+
type: i.TAG_SELF_CLOSE,
|
|
320
320
|
parts: []
|
|
321
321
|
}]
|
|
322
322
|
};
|
|
323
323
|
else throw Error(`Unexpected character ${t} for closing tag.\nExpected />\nRead of /${String.fromCharCode(t)}\nAt line ${e.position.row + 1} col ${e.position.column + 1}`);
|
|
324
324
|
}
|
|
325
|
-
return
|
|
325
|
+
return n;
|
|
326
326
|
}
|
|
327
327
|
//#endregion
|
|
328
328
|
//#region ../packages/compiler/src/lexer/states/tag-open-name.state.ts
|
|
329
|
-
function
|
|
330
|
-
let
|
|
331
|
-
for (e.advance(), e.skipSpaces();
|
|
329
|
+
function x(e, t) {
|
|
330
|
+
let n = !0, a = "", o;
|
|
331
|
+
for (e.advance(), e.skipSpaces(); n;) switch (e.peek()) {
|
|
332
332
|
case 32:
|
|
333
333
|
case 47:
|
|
334
334
|
case 62:
|
|
335
335
|
o = {
|
|
336
|
-
state:
|
|
336
|
+
state: r.TAG_BODY,
|
|
337
337
|
tokens: [{
|
|
338
|
-
type:
|
|
338
|
+
type: i.TAG_OPEN_NAME,
|
|
339
339
|
parts: [a]
|
|
340
340
|
}]
|
|
341
|
-
},
|
|
341
|
+
}, n = !1;
|
|
342
342
|
break;
|
|
343
343
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
344
344
|
}
|
|
@@ -346,27 +346,27 @@ function ne(e, t) {
|
|
|
346
346
|
}
|
|
347
347
|
//#endregion
|
|
348
348
|
//#region ../packages/compiler/src/lexer/states/text.state.ts
|
|
349
|
-
function
|
|
350
|
-
let
|
|
351
|
-
for (;
|
|
349
|
+
function S(e, t) {
|
|
350
|
+
let n = !0, a = "", o;
|
|
351
|
+
for (; n;) switch (e.peek()) {
|
|
352
352
|
case 60:
|
|
353
|
-
o = { state: e.peek(1, { offset: 1 }) === 47 ?
|
|
353
|
+
o = { state: e.peek(1, { offset: 1 }) === 47 ? r.TAG_CLOSE : r.TAG_OPEN_NAME }, n = !1;
|
|
354
354
|
break;
|
|
355
355
|
case 123:
|
|
356
356
|
o = {
|
|
357
|
-
state:
|
|
357
|
+
state: r.INTERPOLATION,
|
|
358
358
|
pushState: !0
|
|
359
|
-
},
|
|
359
|
+
}, n = !1;
|
|
360
360
|
break;
|
|
361
361
|
case 64:
|
|
362
|
-
o = { state:
|
|
362
|
+
o = { state: r.FLOW_CONTROL }, n = !1;
|
|
363
363
|
break;
|
|
364
364
|
case 125:
|
|
365
|
-
t.history[t.history.length - 1] ===
|
|
366
|
-
state:
|
|
367
|
-
tokens: [{ type:
|
|
365
|
+
t.history[t.history.length - 1] === r.FLOW_CONTROL_BLOCK ? (e.advance(), o = {
|
|
366
|
+
state: r.TEXT,
|
|
367
|
+
tokens: [{ type: i.BLOCK_CLOSE }],
|
|
368
368
|
popState: !0
|
|
369
|
-
},
|
|
369
|
+
}, n = !1) : (e.advance(), a = `${a}${e.currentChar.value}`);
|
|
370
370
|
break;
|
|
371
371
|
case 10:
|
|
372
372
|
case 13:
|
|
@@ -374,8 +374,8 @@ function x(e, t) {
|
|
|
374
374
|
break;
|
|
375
375
|
default: e.advance(), a = `${a}${e.currentChar.value}`;
|
|
376
376
|
}
|
|
377
|
-
return o.tokens ??=
|
|
378
|
-
type:
|
|
377
|
+
return o.tokens ??= te(a) ? [{
|
|
378
|
+
type: i.TEXT,
|
|
379
379
|
parts: [a]
|
|
380
380
|
}] : void 0, o;
|
|
381
381
|
}
|
|
@@ -440,26 +440,26 @@ var re = class {
|
|
|
440
440
|
}, ie = class {
|
|
441
441
|
input;
|
|
442
442
|
_cursor;
|
|
443
|
-
_state =
|
|
443
|
+
_state = r.START;
|
|
444
444
|
_stack = new e();
|
|
445
445
|
_tokens = [];
|
|
446
446
|
_states = {
|
|
447
|
-
[
|
|
448
|
-
[
|
|
449
|
-
[
|
|
450
|
-
[
|
|
451
|
-
[
|
|
452
|
-
[
|
|
453
|
-
[
|
|
454
|
-
[
|
|
455
|
-
[
|
|
456
|
-
[
|
|
457
|
-
[
|
|
458
|
-
[
|
|
459
|
-
[
|
|
460
|
-
[
|
|
461
|
-
[
|
|
462
|
-
[
|
|
447
|
+
[r.START]: S,
|
|
448
|
+
[r.TEXT]: S,
|
|
449
|
+
[r.TAG_OPEN_NAME]: x,
|
|
450
|
+
[r.TAG_BODY]: v,
|
|
451
|
+
[r.TAG_OPEN_END]: b,
|
|
452
|
+
[r.TAG_CLOSE]: y,
|
|
453
|
+
[r.ATTRIBUTE]: a,
|
|
454
|
+
[r.FLOW_CONTROL]: p,
|
|
455
|
+
[r.FLOW_CONTROL_CONDITION]: f,
|
|
456
|
+
[r.CASE_FLOW_CONTROL_CONDITION]: c,
|
|
457
|
+
[r.FLOW_CONTROL_BLOCK]: d,
|
|
458
|
+
[r.EVENT]: u,
|
|
459
|
+
[r.INTERPOLATION]: _,
|
|
460
|
+
[r.INTERPOLATION_EXPRESSION]: m,
|
|
461
|
+
[r.INTERPOLATION_LITERAL]: ee,
|
|
462
|
+
[r.CONST_DECLARATION]: l
|
|
463
463
|
};
|
|
464
464
|
constructor(e) {
|
|
465
465
|
this.input = e, this._cursor = new re(this.input);
|
|
@@ -481,7 +481,7 @@ var re = class {
|
|
|
481
481
|
}, ae = class {
|
|
482
482
|
_tokens;
|
|
483
483
|
_currentToken = {
|
|
484
|
-
value: { type:
|
|
484
|
+
value: { type: i.EOF },
|
|
485
485
|
index: -1
|
|
486
486
|
};
|
|
487
487
|
get currentToken() {
|
|
@@ -493,7 +493,7 @@ var re = class {
|
|
|
493
493
|
advance(e = 1) {
|
|
494
494
|
if (e < 1) throw Error(`${e} is not a valid value. Please enter a number equal or greater than 1`);
|
|
495
495
|
let t = this._currentToken.index + e;
|
|
496
|
-
t >= this._tokens.length ? (this._currentToken.value = { type:
|
|
496
|
+
t >= this._tokens.length ? (this._currentToken.value = { type: i.EOF }, this._currentToken.index = -1) : (this._currentToken.index = t, this._currentToken.value = this._tokens[t]);
|
|
497
497
|
}
|
|
498
498
|
peek(e, t) {
|
|
499
499
|
let n = typeof e == "number" ? e : 1, r = (typeof e == "object" ? e : t)?.offset ?? 0;
|
|
@@ -505,45 +505,45 @@ var re = class {
|
|
|
505
505
|
return t;
|
|
506
506
|
}
|
|
507
507
|
peekOneToken(e) {
|
|
508
|
-
return e < this._tokens.length ? this._tokens[e] : { type:
|
|
508
|
+
return e < this._tokens.length ? this._tokens[e] : { type: i.EOF };
|
|
509
509
|
}
|
|
510
|
-
},
|
|
510
|
+
}, C = /* @__PURE__ */ function(e) {
|
|
511
511
|
return e[e.Element = 0] = "Element", e[e.Text = 1] = "Text", e[e.Interpolation = 2] = "Interpolation", e[e.If = 3] = "If", e[e.Else = 4] = "Else", e[e.ElseIf = 5] = "ElseIf", e[e.For = 6] = "For", e[e.Switch = 7] = "Switch", e[e.Case = 8] = "Case", e[e.ConstDeclaration = 9] = "ConstDeclaration", e;
|
|
512
512
|
}({});
|
|
513
513
|
//#endregion
|
|
514
514
|
//#region ../packages/compiler/src/parser/states/parse-const-declaration.state.ts
|
|
515
515
|
function oe(e, t, n) {
|
|
516
516
|
return e.advance(), {
|
|
517
|
-
type:
|
|
517
|
+
type: C.ConstDeclaration,
|
|
518
518
|
varName: n.parts[0],
|
|
519
519
|
expression: n.parts[1]
|
|
520
520
|
};
|
|
521
521
|
}
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region ../packages/compiler/src/parser/states/parse-interpolation.state.ts
|
|
524
|
-
function
|
|
524
|
+
function w(e, t, n) {
|
|
525
525
|
return e.advance(), {
|
|
526
|
-
type:
|
|
526
|
+
type: C.Interpolation,
|
|
527
527
|
expression: n.parts[0]
|
|
528
528
|
};
|
|
529
529
|
}
|
|
530
530
|
//#endregion
|
|
531
531
|
//#region ../packages/compiler/src/parser/states/parse-attribute.state.ts
|
|
532
|
-
function
|
|
532
|
+
function se(e, t, n) {
|
|
533
533
|
e.advance();
|
|
534
|
-
let
|
|
535
|
-
if (!
|
|
536
|
-
name:
|
|
534
|
+
let r = n.parts[0];
|
|
535
|
+
if (!r.includes("=")) return {
|
|
536
|
+
name: r,
|
|
537
537
|
value: "true"
|
|
538
538
|
};
|
|
539
|
-
let [a, o] =
|
|
540
|
-
if (!a) throw Error(`[Parser] Attribute name missing in: ${
|
|
539
|
+
let [a, o] = r.split("=");
|
|
540
|
+
if (!a) throw Error(`[Parser] Attribute name missing in: ${r}`);
|
|
541
541
|
let s = e.peek();
|
|
542
|
-
if (s.type ===
|
|
542
|
+
if (s.type === i.INTERPOLATION_EXPRESSION || s.type === i.INTERPOLATION_LITERAL) return {
|
|
543
543
|
name: a,
|
|
544
|
-
value:
|
|
544
|
+
value: w(e, t, s)
|
|
545
545
|
};
|
|
546
|
-
if (!o) throw Error(`[Parser] Attribute value missing for ${a} in: ${
|
|
546
|
+
if (!o) throw Error(`[Parser] Attribute value missing for ${a} in: ${r}`);
|
|
547
547
|
return {
|
|
548
548
|
name: a,
|
|
549
549
|
value: o.replace(/^['']|['']$/g, "")
|
|
@@ -551,7 +551,7 @@ function w(e, t, n) {
|
|
|
551
551
|
}
|
|
552
552
|
//#endregion
|
|
553
553
|
//#region ../packages/compiler/src/parser/states/parse-event.state.ts
|
|
554
|
-
function
|
|
554
|
+
function ce(e, t, n) {
|
|
555
555
|
e.advance();
|
|
556
556
|
let r = n.parts[0], [i, a] = r.split("=");
|
|
557
557
|
if (!i || !a) throw Error(`[Parser] Invalid event format: ${r}`);
|
|
@@ -562,137 +562,137 @@ function se(e, t, n) {
|
|
|
562
562
|
}
|
|
563
563
|
//#endregion
|
|
564
564
|
//#region ../packages/compiler/src/parser/states/parse-element.state.ts
|
|
565
|
-
function
|
|
565
|
+
function le(e, t, n) {
|
|
566
566
|
e.advance();
|
|
567
|
-
let
|
|
567
|
+
let r = n.parts[0], a = [], o = [], s = !0;
|
|
568
568
|
for (; s;) {
|
|
569
569
|
let n = e.peek();
|
|
570
570
|
switch (n.type) {
|
|
571
|
-
case
|
|
572
|
-
a.push(
|
|
571
|
+
case i.ATTRIBUTE:
|
|
572
|
+
a.push(se(e, t, n));
|
|
573
573
|
break;
|
|
574
|
-
case
|
|
575
|
-
o.push(
|
|
574
|
+
case i.EVENT:
|
|
575
|
+
o.push(ce(e, t, n));
|
|
576
576
|
break;
|
|
577
577
|
default: s = !1;
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
|
-
if (e.peek().type ===
|
|
581
|
-
type:
|
|
582
|
-
tagName:
|
|
580
|
+
if (e.peek().type === i.TAG_OPEN_END && e.advance(), e.peek().type === i.TAG_SELF_CLOSE) return e.advance(), {
|
|
581
|
+
type: C.Element,
|
|
582
|
+
tagName: r,
|
|
583
583
|
attributes: a,
|
|
584
584
|
events: o,
|
|
585
585
|
children: []
|
|
586
586
|
};
|
|
587
587
|
let c = [];
|
|
588
|
-
for (; !
|
|
588
|
+
for (; !ue(e, r);) {
|
|
589
589
|
let e = t();
|
|
590
590
|
e && c.push(e);
|
|
591
591
|
}
|
|
592
592
|
return e.advance(), {
|
|
593
|
-
type:
|
|
594
|
-
tagName:
|
|
593
|
+
type: C.Element,
|
|
594
|
+
tagName: r,
|
|
595
595
|
attributes: a,
|
|
596
596
|
events: o,
|
|
597
597
|
children: c
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
|
-
function
|
|
600
|
+
function ue(e, t) {
|
|
601
601
|
let n = e.peek();
|
|
602
|
-
return n.type ===
|
|
602
|
+
return n.type === i.TAG_CLOSE_NAME && n.parts[0] === t;
|
|
603
603
|
}
|
|
604
604
|
//#endregion
|
|
605
605
|
//#region ../packages/compiler/src/parser/utils/expression-validator.ts
|
|
606
606
|
function T(e) {
|
|
607
|
-
let
|
|
608
|
-
if (E(
|
|
609
|
-
return { node:
|
|
607
|
+
let t = n.createSourceFile("expression.ts", `const x = ${e}`, n.ScriptTarget.ESNext, !0).statements[0].declarationList.declarations[0].initializer, r = [];
|
|
608
|
+
if (E(t, 10, r), r.length) throw Error(r.reduce((e, t) => `${e}${t.message}\n`, ""));
|
|
609
|
+
return { node: t };
|
|
610
610
|
}
|
|
611
|
-
function E(e,
|
|
611
|
+
function E(e, t, r) {
|
|
612
612
|
if (!D(e)) throw Error(O(e));
|
|
613
|
-
if (
|
|
613
|
+
if (n.forEachChild(e, (e) => E(e, t, r)), r.length) throw Error(r[0].message);
|
|
614
614
|
}
|
|
615
615
|
function D(e) {
|
|
616
616
|
switch (e.kind) {
|
|
617
|
-
case
|
|
618
|
-
case
|
|
619
|
-
case
|
|
620
|
-
case
|
|
621
|
-
case
|
|
622
|
-
case
|
|
623
|
-
case
|
|
624
|
-
case
|
|
625
|
-
case
|
|
626
|
-
case
|
|
627
|
-
case
|
|
628
|
-
case
|
|
629
|
-
case
|
|
630
|
-
case
|
|
631
|
-
case
|
|
632
|
-
case
|
|
633
|
-
case
|
|
634
|
-
case
|
|
635
|
-
case
|
|
636
|
-
case
|
|
637
|
-
case
|
|
638
|
-
case
|
|
639
|
-
case
|
|
640
|
-
case
|
|
641
|
-
case
|
|
642
|
-
case
|
|
643
|
-
case
|
|
644
|
-
case
|
|
645
|
-
case
|
|
646
|
-
case
|
|
647
|
-
case
|
|
648
|
-
case
|
|
649
|
-
case
|
|
650
|
-
case
|
|
651
|
-
case
|
|
652
|
-
case
|
|
653
|
-
case
|
|
654
|
-
case
|
|
655
|
-
case
|
|
656
|
-
case
|
|
657
|
-
case
|
|
658
|
-
case
|
|
659
|
-
case
|
|
660
|
-
case
|
|
661
|
-
case
|
|
662
|
-
case
|
|
663
|
-
case
|
|
664
|
-
case
|
|
665
|
-
case
|
|
666
|
-
case
|
|
667
|
-
case
|
|
668
|
-
case
|
|
669
|
-
case
|
|
670
|
-
case
|
|
671
|
-
case
|
|
672
|
-
case
|
|
617
|
+
case n.SyntaxKind.StringLiteral:
|
|
618
|
+
case n.SyntaxKind.NumericLiteral:
|
|
619
|
+
case n.SyntaxKind.BigIntLiteral:
|
|
620
|
+
case n.SyntaxKind.TrueKeyword:
|
|
621
|
+
case n.SyntaxKind.FalseKeyword:
|
|
622
|
+
case n.SyntaxKind.NullKeyword:
|
|
623
|
+
case n.SyntaxKind.UndefinedKeyword:
|
|
624
|
+
case n.SyntaxKind.Identifier:
|
|
625
|
+
case n.SyntaxKind.PropertyAccessExpression:
|
|
626
|
+
case n.SyntaxKind.ElementAccessExpression:
|
|
627
|
+
case n.SyntaxKind.CallExpression:
|
|
628
|
+
case n.SyntaxKind.BinaryExpression:
|
|
629
|
+
case n.SyntaxKind.EqualsEqualsToken:
|
|
630
|
+
case n.SyntaxKind.EqualsEqualsEqualsToken:
|
|
631
|
+
case n.SyntaxKind.ExclamationEqualsToken:
|
|
632
|
+
case n.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
633
|
+
case n.SyntaxKind.LessThanToken:
|
|
634
|
+
case n.SyntaxKind.LessThanEqualsToken:
|
|
635
|
+
case n.SyntaxKind.GreaterThanToken:
|
|
636
|
+
case n.SyntaxKind.GreaterThanEqualsToken:
|
|
637
|
+
case n.SyntaxKind.PlusToken:
|
|
638
|
+
case n.SyntaxKind.MinusToken:
|
|
639
|
+
case n.SyntaxKind.AsteriskToken:
|
|
640
|
+
case n.SyntaxKind.SlashToken:
|
|
641
|
+
case n.SyntaxKind.PercentToken:
|
|
642
|
+
case n.SyntaxKind.AsteriskAsteriskToken:
|
|
643
|
+
case n.SyntaxKind.AmpersandAmpersandToken:
|
|
644
|
+
case n.SyntaxKind.BarBarToken:
|
|
645
|
+
case n.SyntaxKind.QuestionQuestionToken:
|
|
646
|
+
case n.SyntaxKind.AmpersandToken:
|
|
647
|
+
case n.SyntaxKind.BarToken:
|
|
648
|
+
case n.SyntaxKind.CaretToken:
|
|
649
|
+
case n.SyntaxKind.LessThanLessThanToken:
|
|
650
|
+
case n.SyntaxKind.GreaterThanGreaterThanToken:
|
|
651
|
+
case n.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
|
|
652
|
+
case n.SyntaxKind.InstanceOfKeyword:
|
|
653
|
+
case n.SyntaxKind.InKeyword:
|
|
654
|
+
case n.SyntaxKind.PrefixUnaryExpression:
|
|
655
|
+
case n.SyntaxKind.PostfixUnaryExpression:
|
|
656
|
+
case n.SyntaxKind.TypeOfExpression:
|
|
657
|
+
case n.SyntaxKind.VoidExpression:
|
|
658
|
+
case n.SyntaxKind.ConditionalExpression:
|
|
659
|
+
case n.SyntaxKind.ParenthesizedExpression:
|
|
660
|
+
case n.SyntaxKind.TemplateExpression:
|
|
661
|
+
case n.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
662
|
+
case n.SyntaxKind.TemplateHead:
|
|
663
|
+
case n.SyntaxKind.TemplateMiddle:
|
|
664
|
+
case n.SyntaxKind.TemplateTail:
|
|
665
|
+
case n.SyntaxKind.TemplateSpan:
|
|
666
|
+
case n.SyntaxKind.ArrayLiteralExpression:
|
|
667
|
+
case n.SyntaxKind.ObjectLiteralExpression:
|
|
668
|
+
case n.SyntaxKind.PropertyAssignment:
|
|
669
|
+
case n.SyntaxKind.ShorthandPropertyAssignment:
|
|
670
|
+
case n.SyntaxKind.SpreadAssignment:
|
|
671
|
+
case n.SyntaxKind.SpreadElement:
|
|
672
|
+
case n.SyntaxKind.SyntaxList: return !0;
|
|
673
673
|
default: return !1;
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
function O(e) {
|
|
677
677
|
switch (e.kind) {
|
|
678
|
-
case
|
|
679
|
-
case
|
|
680
|
-
case
|
|
681
|
-
case
|
|
682
|
-
case
|
|
683
|
-
case
|
|
684
|
-
case
|
|
685
|
-
default: return `'${
|
|
678
|
+
case n.SyntaxKind.AwaitExpression: return "'await' is not allowed inside template expressions.";
|
|
679
|
+
case n.SyntaxKind.YieldExpression: return "'yield' is not allowed inside template expressions.";
|
|
680
|
+
case n.SyntaxKind.NewExpression: return "'new' is not allowed inside template expressions.";
|
|
681
|
+
case n.SyntaxKind.ArrowFunction:
|
|
682
|
+
case n.SyntaxKind.FunctionExpression: return "Function expressions are not allowed inside template expressions.";
|
|
683
|
+
case n.SyntaxKind.TaggedTemplateExpression: return "Tagged template expressions are not allowed inside template expressions.";
|
|
684
|
+
case n.SyntaxKind.BinaryExpression: return k(e.operatorToken.kind) ? "Assignments are not allowed inside template expressions. Use @const to declare local template variables instead." : `'${n.SyntaxKind[e.kind]}' is not allowed inside template expressions.`;
|
|
685
|
+
default: return `'${n.SyntaxKind[e.kind]}' is not allowed inside template expressions.`;
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
688
|
function k(e) {
|
|
689
|
-
return e >=
|
|
689
|
+
return e >= n.SyntaxKind.FirstAssignment && e <= n.SyntaxKind.LastAssignment;
|
|
690
690
|
}
|
|
691
691
|
//#endregion
|
|
692
692
|
//#region ../packages/compiler/src/parser/states/parse-block-children.state.ts
|
|
693
693
|
function A(e, t) {
|
|
694
694
|
let n = [];
|
|
695
|
-
for (; e.peek().type !==
|
|
695
|
+
for (; e.peek().type !== i.BLOCK_CLOSE;) {
|
|
696
696
|
let e = t();
|
|
697
697
|
e && n.push(e);
|
|
698
698
|
}
|
|
@@ -702,13 +702,13 @@ function A(e, t) {
|
|
|
702
702
|
//#region ../packages/compiler/src/parser/states/parse-for.state.ts
|
|
703
703
|
function j(e, t, n) {
|
|
704
704
|
e.advance();
|
|
705
|
-
let
|
|
706
|
-
if (
|
|
707
|
-
let a = M(
|
|
705
|
+
let r = e.peek();
|
|
706
|
+
if (r.type !== i.CONDITION) throw Error(`[Parser] Expected CONDITION after FOR, got ${i[r.type]}`);
|
|
707
|
+
let a = M(r.parts[0], 0);
|
|
708
708
|
e.advance(2);
|
|
709
709
|
let o = A(e, t);
|
|
710
710
|
return {
|
|
711
|
-
type:
|
|
711
|
+
type: C.For,
|
|
712
712
|
...a,
|
|
713
713
|
children: o
|
|
714
714
|
};
|
|
@@ -783,8 +783,8 @@ function P(e) {
|
|
|
783
783
|
}
|
|
784
784
|
function F(e) {
|
|
785
785
|
if (!e.length) return !1;
|
|
786
|
-
let
|
|
787
|
-
return !!
|
|
786
|
+
let t = n.createSourceFile("__id.ts", e, n.ScriptTarget.ESNext, !1).statements[0];
|
|
787
|
+
return !!t && n.isExpressionStatement(t) && n.isIdentifier(t.expression) && t.expression.text === e;
|
|
788
788
|
}
|
|
789
789
|
//#endregion
|
|
790
790
|
//#region ../packages/compiler/src/parser/states/parse-if.state.ts
|
|
@@ -793,25 +793,25 @@ function I(e, t, n) {
|
|
|
793
793
|
}
|
|
794
794
|
function L(e, t, n) {
|
|
795
795
|
switch (n.type) {
|
|
796
|
-
case
|
|
797
|
-
case
|
|
796
|
+
case i.IF:
|
|
797
|
+
case i.ELSE_IF:
|
|
798
798
|
e.advance();
|
|
799
|
-
let
|
|
800
|
-
if (
|
|
799
|
+
let r = e.peek();
|
|
800
|
+
if (r.type !== i.CONDITION) throw Error(`[Parser] Expected CONDITION after ${i[n.type]}, got ${i[r.type]}`);
|
|
801
801
|
e.advance(2);
|
|
802
|
-
let a =
|
|
802
|
+
let a = r.parts[0], o = T(a), s = A(e, t);
|
|
803
803
|
return {
|
|
804
|
-
type: n.type ===
|
|
804
|
+
type: n.type === i.IF ? C.If : C.ElseIf,
|
|
805
805
|
condition: a,
|
|
806
806
|
conditionNode: o.node,
|
|
807
807
|
consequent: s,
|
|
808
808
|
alternate: L(e, t, e.peek())
|
|
809
809
|
};
|
|
810
|
-
case
|
|
810
|
+
case i.ELSE:
|
|
811
811
|
e.advance(2);
|
|
812
812
|
let c = A(e, t);
|
|
813
813
|
return {
|
|
814
|
-
type:
|
|
814
|
+
type: C.Else,
|
|
815
815
|
consequent: c
|
|
816
816
|
};
|
|
817
817
|
}
|
|
@@ -820,36 +820,36 @@ function L(e, t, n) {
|
|
|
820
820
|
//#region ../packages/compiler/src/parser/states/parse-switch.state.ts
|
|
821
821
|
function R(e, t, n) {
|
|
822
822
|
e.advance();
|
|
823
|
-
let
|
|
824
|
-
if (
|
|
825
|
-
let a =
|
|
823
|
+
let r = e.peek();
|
|
824
|
+
if (r.type !== i.CONDITION) throw Error(`[Parser] Expected CONDITION after SWITCH, got ${i[r.type]}`);
|
|
825
|
+
let a = r.parts[0];
|
|
826
826
|
e.advance(2);
|
|
827
827
|
let o = [];
|
|
828
|
-
for (; e.peek().type !==
|
|
829
|
-
case
|
|
828
|
+
for (; e.peek().type !== i.BLOCK_CLOSE;) switch (e.peek().type) {
|
|
829
|
+
case i.CASE:
|
|
830
830
|
let n = [];
|
|
831
831
|
do {
|
|
832
832
|
e.advance();
|
|
833
833
|
let t = e.peek();
|
|
834
|
-
if (t.type !==
|
|
834
|
+
if (t.type !== i.CONDITION) throw Error("[Parser] Expected CONDITION after CASE");
|
|
835
835
|
n.push(t.parts[0]), e.advance();
|
|
836
|
-
} while (e.peek().type !==
|
|
836
|
+
} while (e.peek().type !== i.BLOCK_OPEN);
|
|
837
837
|
e.advance(), o.push({
|
|
838
|
-
type:
|
|
838
|
+
type: C.Case,
|
|
839
839
|
condition: n,
|
|
840
840
|
children: A(e, t)
|
|
841
841
|
});
|
|
842
842
|
break;
|
|
843
|
-
case
|
|
843
|
+
case i.DEFAULT:
|
|
844
844
|
e.advance(2), o.push({
|
|
845
|
-
type:
|
|
845
|
+
type: C.Case,
|
|
846
846
|
condition: null,
|
|
847
847
|
children: A(e, t)
|
|
848
848
|
});
|
|
849
849
|
break;
|
|
850
850
|
}
|
|
851
851
|
return e.advance(), {
|
|
852
|
-
type:
|
|
852
|
+
type: C.Switch,
|
|
853
853
|
expression: a,
|
|
854
854
|
cases: o
|
|
855
855
|
};
|
|
@@ -858,7 +858,7 @@ function R(e, t, n) {
|
|
|
858
858
|
//#region ../packages/compiler/src/parser/states/parse-text.state.ts
|
|
859
859
|
function z(e, t, n) {
|
|
860
860
|
return e.advance(), {
|
|
861
|
-
type:
|
|
861
|
+
type: C.Text,
|
|
862
862
|
value: n.parts[0]
|
|
863
863
|
};
|
|
864
864
|
}
|
|
@@ -868,21 +868,21 @@ var B = class {
|
|
|
868
868
|
tokens;
|
|
869
869
|
_cursor;
|
|
870
870
|
_states = {
|
|
871
|
-
[
|
|
872
|
-
[
|
|
873
|
-
[
|
|
874
|
-
[
|
|
875
|
-
[
|
|
876
|
-
[
|
|
877
|
-
[
|
|
878
|
-
[
|
|
871
|
+
[i.TEXT]: z,
|
|
872
|
+
[i.INTERPOLATION_EXPRESSION]: w,
|
|
873
|
+
[i.INTERPOLATION_LITERAL]: w,
|
|
874
|
+
[i.TAG_OPEN_NAME]: le,
|
|
875
|
+
[i.IF]: I,
|
|
876
|
+
[i.FOR]: j,
|
|
877
|
+
[i.SWITCH]: R,
|
|
878
|
+
[i.CONST_DECLARATION]: oe
|
|
879
879
|
};
|
|
880
880
|
constructor(e) {
|
|
881
881
|
this.tokens = e, this._cursor = new ae(this.tokens);
|
|
882
882
|
}
|
|
883
883
|
parse() {
|
|
884
884
|
let e = [];
|
|
885
|
-
for (; this._cursor.peek().type !==
|
|
885
|
+
for (; this._cursor.peek().type !== i.EOF;) {
|
|
886
886
|
let t = this.parseNode();
|
|
887
887
|
t && e.push(t);
|
|
888
888
|
}
|
|
@@ -890,9 +890,9 @@ var B = class {
|
|
|
890
890
|
}
|
|
891
891
|
parseNode() {
|
|
892
892
|
let e = this._cursor.peek();
|
|
893
|
-
if (e.type ===
|
|
893
|
+
if (e.type === i.EOF) return;
|
|
894
894
|
let t = this._states[e.type];
|
|
895
|
-
if (!t) throw Error(`[Parser] No transition function for token type ${
|
|
895
|
+
if (!t) throw Error(`[Parser] No transition function for token type ${i[e.type]}`);
|
|
896
896
|
return t(this._cursor, this.parseNode.bind(this), e);
|
|
897
897
|
}
|
|
898
898
|
}, V = class {
|
|
@@ -908,30 +908,27 @@ var B = class {
|
|
|
908
908
|
getIdentifier(e) {
|
|
909
909
|
return this._identifiers.includes(e) ? e : this._parent?.getIdentifier(e);
|
|
910
910
|
}
|
|
911
|
-
},
|
|
912
|
-
function
|
|
913
|
-
return typeof e == "string" ? t.getIdentifier(e) ?? `this.${e}` :
|
|
911
|
+
}, H = new Set(/* @__PURE__ */ "undefined.NaN.Infinity.globalThis.eval.isFinite.isNaN.parseFloat.parseInt.decodeURI.decodeURIComponent.encodeURI.encodeURIComponent.escape.unescape.Object.Function.Boolean.Symbol.Error.AggregateError.EvalError.RangeError.ReferenceError.SyntaxError.TypeError.URIError.SuppressedError.InternalError.Number.BigInt.Math.Date.Temporal.String.RegExp.Array.TypedArray.Int8Array.Uint8Array.Uint8ClampedArray.Int16Array.Uint16Array.Int32Array.Uint32Array.BigInt64Array.BigUint64Array.Float16Array.Float32Array.Float64Array.Map.Set.WeakMap.WeakSet.ArrayBuffer.SharedArrayBuffer.DataView.Atomics.JSON.WeakRef.FinalizationRegistry.Iterator.AsyncIterator.Promise.GeneratorFunction.AsyncGeneratorFunction.Generator.AsyncGenerator.AsyncFunction.DisposableStack.AsyncDisposableStack.Reflect.Proxy.Intl.WebAssembly.window.document.navigator.location.history.screen.console.performance.crypto.fetch.alert.confirm.prompt.setTimeout.setInterval.clearTimeout.clearInterval.requestAnimationFrame.cancelAnimationFrame.queueMicrotask.structuredClone.URL.URLSearchParams.FormData.Headers.Request.Response.AbortController.AbortSignal.CustomEvent.Event.EventTarget.MutationObserver.IntersectionObserver.ResizeObserver.PerformanceObserver.Worker.SharedWorker.ServiceWorker.Blob.File.FileReader.ReadableStream.WritableStream.TransformStream.TextEncoder.TextDecoder.ImageData.Canvas.Storage.localStorage.sessionStorage.indexedDB.WebSocket.XMLHttpRequest.HTMLElement.HTMLInputElement.HTMLButtonElement.HTMLFormElement.HTMLAnchorElement.HTMLImageElement.HTMLVideoElement.HTMLAudioElement.HTMLCanvasElement.HTMLSelectElement.HTMLTextAreaElement.HTMLDivElement.HTMLSpanElement.HTMLParagraphElement.HTMLHeadingElement.HTMLTableElement.HTMLTableRowElement.HTMLTableCellElement.HTMLUListElement.HTMLOListElement.HTMLLIElement.HTMLLabelElement.HTMLDialogElement.HTMLDetailsElement.HTMLSlotElement.HTMLTemplateElement.SVGElement.SVGSVGElement.Element.Node.NodeList.DocumentFragment.ShadowRoot.Document.Window".split(".")), U = "this._root";
|
|
912
|
+
function W(e, t) {
|
|
913
|
+
return typeof e == "string" ? t.getIdentifier(e) ?? `this.${e}` : G(e, e, t);
|
|
914
914
|
}
|
|
915
|
-
function
|
|
916
|
-
if (
|
|
917
|
-
if (!
|
|
915
|
+
function G(e, t, r) {
|
|
916
|
+
if (n.isIdentifier(e) && q(e, t)) return r.getIdentifier(e.text) ?? `this.${e.text}`;
|
|
917
|
+
if (!K(e, t)) return e.getText();
|
|
918
918
|
let i = e.getSourceFile().text, a = "", o = e.getStart();
|
|
919
|
-
return
|
|
920
|
-
a = `${a}${i.slice(o, t.getStart())}${
|
|
919
|
+
return n.forEachChild(e, (t) => {
|
|
920
|
+
a = `${a}${i.slice(o, t.getStart())}${G(t, e, r)}`, o = t.getEnd();
|
|
921
921
|
}), `${a}${i.slice(o, e.getEnd())}`;
|
|
922
922
|
}
|
|
923
|
-
function
|
|
924
|
-
if (
|
|
923
|
+
function K(e, t) {
|
|
924
|
+
if (n.isIdentifier(e) && q(e, t)) return !0;
|
|
925
925
|
let r = !1;
|
|
926
|
-
return
|
|
927
|
-
r ||=
|
|
926
|
+
return n.forEachChild(e, (t) => {
|
|
927
|
+
r ||= K(t, e);
|
|
928
928
|
}), r;
|
|
929
929
|
}
|
|
930
|
-
function
|
|
931
|
-
return !(
|
|
932
|
-
}
|
|
933
|
-
function q(...e) {
|
|
934
|
-
return e.map((e) => ` ${e}`);
|
|
930
|
+
function q(e, t) {
|
|
931
|
+
return !(n.isPropertyAccessExpression(t) && t.name === e || H.has(e.text));
|
|
935
932
|
}
|
|
936
933
|
function de(e, t, n) {
|
|
937
934
|
return t === "this._root" ? `${e.tagName}${n}` : `${t}_${e.tagName}${n}`;
|
|
@@ -942,17 +939,17 @@ function J(e, t, n = "text") {
|
|
|
942
939
|
//#endregion
|
|
943
940
|
//#region ../packages/compiler/src/render-generator/states/process-const-declaration.state.ts
|
|
944
941
|
function fe(e, t, n, r) {
|
|
945
|
-
return r.addIdentifier(e.varName), [`const ${e.varName} = ${
|
|
942
|
+
return r.addIdentifier(e.varName), [`const ${e.varName} = ${W(e.expression, r)};`];
|
|
946
943
|
}
|
|
947
944
|
//#endregion
|
|
948
945
|
//#region ../packages/compiler/src/render-generator/states/process-element.state.ts
|
|
949
|
-
function
|
|
946
|
+
function pe(e, t, n, r) {
|
|
950
947
|
let i = new V([], r);
|
|
951
948
|
return [
|
|
952
949
|
`const ${t} = document.createElement("${e.tagName}");`,
|
|
953
950
|
...e.attributes?.map((e) => {
|
|
954
951
|
let n = e.value;
|
|
955
|
-
return typeof n == "string" ? `${t}.setAttribute('${e.name}', ${n});` : `effect(() => ${t}.setAttribute('${e.name}', ${
|
|
952
|
+
return typeof n == "string" ? `${t}.setAttribute('${e.name}', ${n});` : `effect(() => ${t}.setAttribute('${e.name}', ${W(n.expression, r)}));`;
|
|
956
953
|
}) || [],
|
|
957
954
|
...e.events?.map((e) => `${t}.addEventListener("${e.name}", ($event) => this.${e.handler});`) || [],
|
|
958
955
|
`${n}.appendChild(${t});`,
|
|
@@ -961,66 +958,60 @@ function Y(e, t, n, r) {
|
|
|
961
958
|
}
|
|
962
959
|
//#endregion
|
|
963
960
|
//#region ../packages/compiler/src/render-generator/states/process-for.state.ts
|
|
964
|
-
function
|
|
965
|
-
let
|
|
961
|
+
function me(e, n, r, i) {
|
|
962
|
+
let a = e.iterableSource, o = i.getIdentifier(a) ?? `this.${a}`, s = J(r, n, "items"), c = J(r, n, "i"), l = Y(e, "$index"), u = Y(e, "$first"), d = Y(e, "$last"), f = Y(e, "$even"), p = Y(e, "$odd"), m = new V([
|
|
966
963
|
e.itemAlias,
|
|
967
|
-
c,
|
|
968
964
|
l,
|
|
969
965
|
u,
|
|
970
966
|
d,
|
|
971
|
-
f
|
|
972
|
-
|
|
967
|
+
f,
|
|
968
|
+
p
|
|
969
|
+
], i);
|
|
973
970
|
return [
|
|
974
|
-
`const ${
|
|
975
|
-
`for (let ${
|
|
976
|
-
...
|
|
977
|
-
...
|
|
978
|
-
...q(`const ${l} = ${s} === 0;`),
|
|
979
|
-
...q(`const ${u} = ${s} === ${o}.length - 1;`),
|
|
980
|
-
...q(`const ${d} = ${s} % 2 === 0;`),
|
|
981
|
-
...q(`const ${f} = ${s} % 2 !== 0;`),
|
|
982
|
-
...q(""),
|
|
983
|
-
...e.children.flatMap((e, r) => q(...$(e, `${t}_${r}`, n, p))),
|
|
971
|
+
`const ${s} = ${o};`,
|
|
972
|
+
`for (let ${c} = 0; ${c} < ${s}.length; ${c}++) {`,
|
|
973
|
+
...t(`const ${e.itemAlias} = ${s}[${c}];`, `const ${l} = ${c};`, `const ${u} = ${c} === 0;`, `const ${d} = ${c} === ${s}.length - 1;`, `const ${f} = ${c} % 2 === 0;`, `const ${p} = ${c} % 2 !== 0;`),
|
|
974
|
+
...e.children.flatMap((e, i) => t(...$(e, `${n}_${i}`, r, m))),
|
|
984
975
|
"}"
|
|
985
976
|
];
|
|
986
977
|
}
|
|
987
|
-
function
|
|
978
|
+
function Y(e, t) {
|
|
988
979
|
return e.implicitAliases.get(t) ?? t;
|
|
989
980
|
}
|
|
990
981
|
//#endregion
|
|
991
982
|
//#region ../packages/compiler/src/render-generator/states/process-if.state.ts
|
|
992
|
-
function
|
|
983
|
+
function he(e, t, n, r) {
|
|
993
984
|
let i = new V([], r), a = [
|
|
994
|
-
`if (${
|
|
995
|
-
...
|
|
985
|
+
`if (${W(e.conditionNode, r)}) {`,
|
|
986
|
+
...X(e, t, n, i),
|
|
996
987
|
"}"
|
|
997
988
|
], o = e.alternate;
|
|
998
|
-
for (; o?.type ===
|
|
989
|
+
for (; o?.type === C.ElseIf;) {
|
|
999
990
|
let e = new V([], r);
|
|
1000
|
-
a[a.length - 1] += ` else if (${
|
|
991
|
+
a[a.length - 1] += ` else if (${W(o.conditionNode, r)}) {`, a.push(...X(o, t, n, e), "}"), o = o.alternate;
|
|
1001
992
|
}
|
|
1002
993
|
if (o) {
|
|
1003
994
|
let e = new V([], r);
|
|
1004
|
-
a[a.length - 1] += " else {", a.push(...
|
|
995
|
+
a[a.length - 1] += " else {", a.push(...X(o, t, n, e), "}");
|
|
1005
996
|
}
|
|
1006
997
|
return a;
|
|
1007
998
|
}
|
|
1008
|
-
function
|
|
1009
|
-
return e.consequent.map((e,
|
|
999
|
+
function X(e, n, r, i) {
|
|
1000
|
+
return e.consequent.map((e, a) => t(...$(e, `${n}_${a}`, r, i))).flat();
|
|
1010
1001
|
}
|
|
1011
1002
|
//#endregion
|
|
1012
1003
|
//#region ../packages/compiler/src/render-generator/states/process-switch.state.ts
|
|
1013
|
-
function
|
|
1004
|
+
function Z(e, n, r, i) {
|
|
1014
1005
|
return [
|
|
1015
|
-
`switch (${
|
|
1016
|
-
...e.cases.map((e) => [...
|
|
1006
|
+
`switch (${W(e.expression, i)}) {`,
|
|
1007
|
+
...e.cases.map((e) => [...t(...e.condition ? e.condition.map((e, t, n) => `case ${e}:${t === n.length - 1 ? " {" : ""}`) : ["default: {"], ...e.children.map((e, a) => t(...$(e, `${n}_${a}_${a}`, r, new V([], i)))).flat(), `${t("break;")}`, "}")]).flat(),
|
|
1017
1008
|
"}"
|
|
1018
1009
|
];
|
|
1019
1010
|
}
|
|
1020
1011
|
//#endregion
|
|
1021
1012
|
//#region ../packages/compiler/src/render-generator/states/process-text-and-interpolation.state.ts
|
|
1022
1013
|
function ge(e, t, n, r) {
|
|
1023
|
-
let i = e.type ===
|
|
1014
|
+
let i = e.type === C.Text ? JSON.stringify(e.value) : W(e.expression, r);
|
|
1024
1015
|
return [
|
|
1025
1016
|
`const ${t} = document.createTextNode(${i});`,
|
|
1026
1017
|
`${n}.appendChild(${t});`,
|
|
@@ -1030,34 +1021,34 @@ function ge(e, t, n, r) {
|
|
|
1030
1021
|
//#endregion
|
|
1031
1022
|
//#region ../packages/compiler/src/render-generator/render-generator.ts
|
|
1032
1023
|
var Q = /* @__PURE__ */ new Map();
|
|
1033
|
-
function _e(e,
|
|
1024
|
+
function _e(e, n) {
|
|
1034
1025
|
Q.clear();
|
|
1035
|
-
let
|
|
1026
|
+
let r = new V(), i = [
|
|
1036
1027
|
"_render() {",
|
|
1037
|
-
...
|
|
1028
|
+
...t(`this._root.adoptedStyleSheets = [${n}];`, ...e.map((e, t) => [...$(e, t.toString(), U, r)]).flat()),
|
|
1038
1029
|
"}"
|
|
1039
1030
|
];
|
|
1040
1031
|
for (; Q.size > 0;) {
|
|
1041
|
-
let [e,
|
|
1042
|
-
|
|
1032
|
+
let [e, n] = Q.entries().next().value;
|
|
1033
|
+
i.push(`${e} {`, ...t(...n()), "}"), Q.delete(e);
|
|
1043
1034
|
}
|
|
1044
|
-
return
|
|
1035
|
+
return i.join("\n");
|
|
1045
1036
|
}
|
|
1046
1037
|
function $(e, t, n, r) {
|
|
1047
1038
|
switch (e.type) {
|
|
1048
|
-
case
|
|
1049
|
-
case
|
|
1050
|
-
case
|
|
1051
|
-
case
|
|
1052
|
-
let i = `
|
|
1053
|
-
return Q.set(i, () =>
|
|
1054
|
-
case
|
|
1055
|
-
let a = `
|
|
1056
|
-
return Q.set(a, () =>
|
|
1057
|
-
case
|
|
1058
|
-
let o = `
|
|
1059
|
-
return Q.set(o, () =>
|
|
1060
|
-
case
|
|
1039
|
+
case C.Text:
|
|
1040
|
+
case C.Interpolation: return ge(e, J(n, t), n, r);
|
|
1041
|
+
case C.Element: return pe(e, de(e, n, t), n, r);
|
|
1042
|
+
case C.If:
|
|
1043
|
+
let i = `if_${t}()`;
|
|
1044
|
+
return Q.set(i, () => he(e, t, n, r)), [`this.${i};`];
|
|
1045
|
+
case C.For:
|
|
1046
|
+
let a = `for_${t}()`;
|
|
1047
|
+
return Q.set(a, () => me(e, t, n, r)), [`this.${a};`];
|
|
1048
|
+
case C.Switch:
|
|
1049
|
+
let o = `switch_${t}()`;
|
|
1050
|
+
return Q.set(o, () => Z(e, t, n, r)), [`this.${o};`];
|
|
1051
|
+
case C.ConstDeclaration: return fe(e, t, n, r);
|
|
1061
1052
|
default: return [];
|
|
1062
1053
|
}
|
|
1063
1054
|
}
|