@xaendar/compiler 0.3.17 → 0.3.19
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.d.ts +1 -1
- package/xaendar-compiler.es.js +109 -106
- package/xaendar-compiler.es.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/compiler",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"description": "A library containing compiler engine",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@xaendar/common": "0.3.
|
|
20
|
-
"@xaendar/types": "0.3.
|
|
19
|
+
"@xaendar/common": "0.3.19",
|
|
20
|
+
"@xaendar/types": "0.3.19",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/xaendar-compiler.es.d.ts
CHANGED
package/xaendar-compiler.es.js
CHANGED
|
@@ -213,10 +213,10 @@ function m(e, t) {
|
|
|
213
213
|
//#endregion
|
|
214
214
|
//#region ../packages/compiler/src/lexer/states/interpolation-literal.state.ts
|
|
215
215
|
function h(e, t) {
|
|
216
|
-
let i = !0, a = "", o;
|
|
216
|
+
let i = !0, a = "`", o;
|
|
217
217
|
for (e.advance(); i;) switch (e.peek()) {
|
|
218
218
|
case 96:
|
|
219
|
-
if (e
|
|
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) {
|
|
@@ -252,7 +252,7 @@ function v(e) {
|
|
|
252
252
|
}
|
|
253
253
|
//#endregion
|
|
254
254
|
//#region ../packages/compiler/src/lexer/states/interpolation.state.ts
|
|
255
|
-
function
|
|
255
|
+
function y(e, t) {
|
|
256
256
|
let r;
|
|
257
257
|
e.advance(), e.skipSpaces();
|
|
258
258
|
let i = e.peek();
|
|
@@ -263,7 +263,7 @@ function ee(e, t) {
|
|
|
263
263
|
}
|
|
264
264
|
//#endregion
|
|
265
265
|
//#region ../packages/compiler/src/lexer/states/tag-body.state.ts
|
|
266
|
-
function
|
|
266
|
+
function b(e, t) {
|
|
267
267
|
let r = !0, i;
|
|
268
268
|
for (; r;) switch (e.peek()) {
|
|
269
269
|
case 64:
|
|
@@ -282,7 +282,7 @@ function y(e, t) {
|
|
|
282
282
|
}
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region ../packages/compiler/src/lexer/states/tag-close.state.ts
|
|
285
|
-
function
|
|
285
|
+
function ee(e, t) {
|
|
286
286
|
let i = !0, a = "", o;
|
|
287
287
|
for (e.advance(2), e.skipSpaces(); i;) switch (e.peek()) {
|
|
288
288
|
case 62:
|
|
@@ -301,7 +301,7 @@ function te(e, t) {
|
|
|
301
301
|
}
|
|
302
302
|
//#endregion
|
|
303
303
|
//#region ../packages/compiler/src/lexer/states/tag-open-end.state.ts
|
|
304
|
-
function
|
|
304
|
+
function te(e, t) {
|
|
305
305
|
let i;
|
|
306
306
|
if (e.peek() === 62) e.advance(), i = {
|
|
307
307
|
state: n.TEXT,
|
|
@@ -326,7 +326,7 @@ function ne(e, t) {
|
|
|
326
326
|
}
|
|
327
327
|
//#endregion
|
|
328
328
|
//#region ../packages/compiler/src/lexer/states/tag-open-name.state.ts
|
|
329
|
-
function
|
|
329
|
+
function ne(e, t) {
|
|
330
330
|
let i = !0, a = "", o;
|
|
331
331
|
for (e.advance(), e.skipSpaces(); i;) switch (e.peek()) {
|
|
332
332
|
case 32:
|
|
@@ -346,7 +346,7 @@ function re(e, t) {
|
|
|
346
346
|
}
|
|
347
347
|
//#endregion
|
|
348
348
|
//#region ../packages/compiler/src/lexer/states/text.state.ts
|
|
349
|
-
function
|
|
349
|
+
function x(e, t) {
|
|
350
350
|
let i = !0, a = "", o;
|
|
351
351
|
for (; i;) switch (e.peek()) {
|
|
352
352
|
case 60:
|
|
@@ -381,7 +381,7 @@ function b(e, t) {
|
|
|
381
381
|
}
|
|
382
382
|
//#endregion
|
|
383
383
|
//#region ../packages/compiler/src/lexer/types/lexer-cursor.model.ts
|
|
384
|
-
var
|
|
384
|
+
var re = class {
|
|
385
385
|
input;
|
|
386
386
|
_currentChar = {
|
|
387
387
|
code: 0,
|
|
@@ -437,32 +437,32 @@ var ie = class {
|
|
|
437
437
|
throwEOFError() {
|
|
438
438
|
throw Error("", { cause: 0 });
|
|
439
439
|
}
|
|
440
|
-
},
|
|
440
|
+
}, ie = class {
|
|
441
441
|
input;
|
|
442
442
|
_cursor;
|
|
443
443
|
_state = n.START;
|
|
444
444
|
_stack = new e();
|
|
445
445
|
_tokens = [];
|
|
446
446
|
_states = {
|
|
447
|
-
[n.START]:
|
|
448
|
-
[n.TEXT]:
|
|
449
|
-
[n.TAG_OPEN_NAME]:
|
|
450
|
-
[n.TAG_BODY]:
|
|
451
|
-
[n.TAG_OPEN_END]:
|
|
452
|
-
[n.TAG_CLOSE]:
|
|
447
|
+
[n.START]: x,
|
|
448
|
+
[n.TEXT]: x,
|
|
449
|
+
[n.TAG_OPEN_NAME]: ne,
|
|
450
|
+
[n.TAG_BODY]: b,
|
|
451
|
+
[n.TAG_OPEN_END]: te,
|
|
452
|
+
[n.TAG_CLOSE]: ee,
|
|
453
453
|
[n.ATTRIBUTE]: i,
|
|
454
454
|
[n.FLOW_CONTROL]: f,
|
|
455
455
|
[n.FLOW_CONTROL_CONDITION]: d,
|
|
456
456
|
[n.CASE_FLOW_CONTROL_CONDITION]: s,
|
|
457
457
|
[n.FLOW_CONTROL_BLOCK]: u,
|
|
458
458
|
[n.EVENT]: l,
|
|
459
|
-
[n.INTERPOLATION]:
|
|
459
|
+
[n.INTERPOLATION]: y,
|
|
460
460
|
[n.INTERPOLATION_EXPRESSION]: p,
|
|
461
461
|
[n.INTERPOLATION_LITERAL]: h,
|
|
462
462
|
[n.CONST_DECLARATION]: c
|
|
463
463
|
};
|
|
464
464
|
constructor(e) {
|
|
465
|
-
this.input = e, this._cursor = new
|
|
465
|
+
this.input = e, this._cursor = new re(this.input);
|
|
466
466
|
}
|
|
467
467
|
tokenize() {
|
|
468
468
|
let e = !1;
|
|
@@ -478,7 +478,7 @@ var ie = class {
|
|
|
478
478
|
}
|
|
479
479
|
return this._tokens;
|
|
480
480
|
}
|
|
481
|
-
},
|
|
481
|
+
}, ae = class {
|
|
482
482
|
_tokens;
|
|
483
483
|
_currentToken = {
|
|
484
484
|
value: { type: r.EOF },
|
|
@@ -507,14 +507,14 @@ var ie = class {
|
|
|
507
507
|
peekOneToken(e) {
|
|
508
508
|
return e < this._tokens.length ? this._tokens[e] : { type: r.EOF };
|
|
509
509
|
}
|
|
510
|
-
},
|
|
510
|
+
}, S = /* @__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
|
-
function
|
|
515
|
+
function oe(e, t, n) {
|
|
516
516
|
return e.advance(), {
|
|
517
|
-
type:
|
|
517
|
+
type: S.ConstDeclaration,
|
|
518
518
|
varName: n.parts[0],
|
|
519
519
|
expression: n.parts[1]
|
|
520
520
|
};
|
|
@@ -523,13 +523,13 @@ function S(e, t, n) {
|
|
|
523
523
|
//#region ../packages/compiler/src/parser/states/parse-interpolation.state.ts
|
|
524
524
|
function C(e, t, n) {
|
|
525
525
|
return e.advance(), {
|
|
526
|
-
type:
|
|
526
|
+
type: S.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 w(e, t, n) {
|
|
533
533
|
e.advance();
|
|
534
534
|
let i = n.parts[0];
|
|
535
535
|
if (!i.includes("=")) return {
|
|
@@ -551,7 +551,7 @@ function se(e, t, n) {
|
|
|
551
551
|
}
|
|
552
552
|
//#endregion
|
|
553
553
|
//#region ../packages/compiler/src/parser/states/parse-event.state.ts
|
|
554
|
-
function
|
|
554
|
+
function se(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,57 +562,57 @@ function ce(e, t, n) {
|
|
|
562
562
|
}
|
|
563
563
|
//#endregion
|
|
564
564
|
//#region ../packages/compiler/src/parser/states/parse-element.state.ts
|
|
565
|
-
function
|
|
565
|
+
function ce(e, t, n) {
|
|
566
566
|
e.advance();
|
|
567
567
|
let i = n.parts[0], a = [], o = [], s = !0;
|
|
568
568
|
for (; s;) {
|
|
569
569
|
let n = e.peek();
|
|
570
570
|
switch (n.type) {
|
|
571
571
|
case r.ATTRIBUTE:
|
|
572
|
-
a.push(
|
|
572
|
+
a.push(w(e, t, n));
|
|
573
573
|
break;
|
|
574
574
|
case r.EVENT:
|
|
575
|
-
o.push(
|
|
575
|
+
o.push(se(e, t, n));
|
|
576
576
|
break;
|
|
577
577
|
default: s = !1;
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
580
|
if (e.peek().type === r.TAG_OPEN_END && e.advance(), e.peek().type === r.TAG_SELF_CLOSE) return e.advance(), {
|
|
581
|
-
type:
|
|
581
|
+
type: S.Element,
|
|
582
582
|
tagName: i,
|
|
583
583
|
attributes: a,
|
|
584
584
|
events: o,
|
|
585
585
|
children: []
|
|
586
586
|
};
|
|
587
587
|
let c = [];
|
|
588
|
-
for (; !
|
|
588
|
+
for (; !le(e, i);) {
|
|
589
589
|
let e = t();
|
|
590
590
|
e && c.push(e);
|
|
591
591
|
}
|
|
592
592
|
return e.advance(), {
|
|
593
|
-
type:
|
|
593
|
+
type: S.Element,
|
|
594
594
|
tagName: i,
|
|
595
595
|
attributes: a,
|
|
596
596
|
events: o,
|
|
597
597
|
children: c
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
|
-
function
|
|
600
|
+
function le(e, t) {
|
|
601
601
|
let n = e.peek();
|
|
602
602
|
return n.type === r.TAG_CLOSE_NAME && n.parts[0] === t;
|
|
603
603
|
}
|
|
604
604
|
//#endregion
|
|
605
605
|
//#region ../packages/compiler/src/parser/utils/expression-validator.ts
|
|
606
|
-
function
|
|
606
|
+
function T(e) {
|
|
607
607
|
let n = t.createSourceFile("expression.ts", `const x = ${e}`, t.ScriptTarget.ESNext, !0).statements[0].declarationList.declarations[0].initializer, r = [];
|
|
608
|
-
if (
|
|
608
|
+
if (E(n, 10, r), r.length) throw Error(r.reduce((e, t) => `${e}${t.message}\n`, ""));
|
|
609
609
|
return { node: n };
|
|
610
610
|
}
|
|
611
|
-
function
|
|
612
|
-
if (!
|
|
613
|
-
if (t.forEachChild(e, (e) =>
|
|
611
|
+
function E(e, n, r) {
|
|
612
|
+
if (!D(e)) throw Error(O(e));
|
|
613
|
+
if (t.forEachChild(e, (e) => E(e, n, r)), r.length) throw Error(r[0].message);
|
|
614
614
|
}
|
|
615
|
-
function
|
|
615
|
+
function D(e) {
|
|
616
616
|
switch (e.kind) {
|
|
617
617
|
case t.SyntaxKind.StringLiteral:
|
|
618
618
|
case t.SyntaxKind.NumericLiteral:
|
|
@@ -673,7 +673,7 @@ function E(e) {
|
|
|
673
673
|
default: return !1;
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
|
-
function
|
|
676
|
+
function O(e) {
|
|
677
677
|
switch (e.kind) {
|
|
678
678
|
case t.SyntaxKind.AwaitExpression: return "'await' is not allowed inside template expressions.";
|
|
679
679
|
case t.SyntaxKind.YieldExpression: return "'yield' is not allowed inside template expressions.";
|
|
@@ -681,16 +681,16 @@ function D(e) {
|
|
|
681
681
|
case t.SyntaxKind.ArrowFunction:
|
|
682
682
|
case t.SyntaxKind.FunctionExpression: return "Function expressions are not allowed inside template expressions.";
|
|
683
683
|
case t.SyntaxKind.TaggedTemplateExpression: return "Tagged template expressions are not allowed inside template expressions.";
|
|
684
|
-
case t.SyntaxKind.BinaryExpression: return
|
|
684
|
+
case t.SyntaxKind.BinaryExpression: return k(e.operatorToken.kind) ? "Assignments are not allowed inside template expressions. Use @const to declare local template variables instead." : `'${t.SyntaxKind[e.kind]}' is not allowed inside template expressions.`;
|
|
685
685
|
default: return `'${t.SyntaxKind[e.kind]}' is not allowed inside template expressions.`;
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function k(e) {
|
|
689
689
|
return e >= t.SyntaxKind.FirstAssignment && e <= t.SyntaxKind.LastAssignment;
|
|
690
690
|
}
|
|
691
691
|
//#endregion
|
|
692
692
|
//#region ../packages/compiler/src/parser/states/parse-block-children.state.ts
|
|
693
|
-
function
|
|
693
|
+
function A(e, t) {
|
|
694
694
|
let n = [];
|
|
695
695
|
for (; e.peek().type !== r.BLOCK_CLOSE;) {
|
|
696
696
|
let e = t();
|
|
@@ -700,30 +700,30 @@ function k(e, t) {
|
|
|
700
700
|
}
|
|
701
701
|
//#endregion
|
|
702
702
|
//#region ../packages/compiler/src/parser/states/parse-for.state.ts
|
|
703
|
-
function
|
|
703
|
+
function j(e, t, n) {
|
|
704
704
|
e.advance();
|
|
705
705
|
let i = e.peek();
|
|
706
706
|
if (i.type !== r.CONDITION) throw Error(`[Parser] Expected CONDITION after FOR, got ${r[i.type]}`);
|
|
707
|
-
let a =
|
|
707
|
+
let a = M(i.parts[0], 0);
|
|
708
708
|
e.advance(2);
|
|
709
|
-
let o =
|
|
709
|
+
let o = A(e, t);
|
|
710
710
|
return {
|
|
711
|
-
type:
|
|
711
|
+
type: S.For,
|
|
712
712
|
...a,
|
|
713
713
|
children: o
|
|
714
714
|
};
|
|
715
715
|
}
|
|
716
|
-
function
|
|
717
|
-
let n =
|
|
716
|
+
function M(e, t) {
|
|
717
|
+
let n = P(e);
|
|
718
718
|
if (n.length < 2) throw Error("[Parser] @for requires at least \"item of iterable; track expr\".");
|
|
719
719
|
let r = n[0].trim(), i = r.indexOf(" of ");
|
|
720
720
|
if (i === -1) throw Error("[Parser] @for expression must be in the form \"item of iterable\".");
|
|
721
721
|
let a = r.slice(0, i).trim(), o = r.slice(i + 4).trim();
|
|
722
|
-
if (!
|
|
723
|
-
let s =
|
|
722
|
+
if (!F(a)) throw Error(`[Parser] '${a}' is not a valid item alias.`);
|
|
723
|
+
let s = T(o), c = n[1].trim();
|
|
724
724
|
if (!c.startsWith("track ")) throw Error("[Parser] Second section of @for must start with \"track\".");
|
|
725
|
-
let l = c.slice(6).trim(), u =
|
|
726
|
-
return n.length >= 3 && n[2] !== void 0 &&
|
|
725
|
+
let l = c.slice(6).trim(), u = T(l), d = /* @__PURE__ */ new Map();
|
|
726
|
+
return n.length >= 3 && n[2] !== void 0 && N(n[2].trim(), t + e.indexOf(n[2]), d), {
|
|
727
727
|
itemAlias: a,
|
|
728
728
|
iterableExpression: s.node,
|
|
729
729
|
iterableSource: o,
|
|
@@ -732,7 +732,7 @@ function j(e, t) {
|
|
|
732
732
|
implicitAliases: d
|
|
733
733
|
};
|
|
734
734
|
}
|
|
735
|
-
function
|
|
735
|
+
function N(e, t, n) {
|
|
736
736
|
let r = e.split(","), i = 0, a = new Set([
|
|
737
737
|
"$index",
|
|
738
738
|
"$last",
|
|
@@ -746,12 +746,12 @@ function M(e, t, n) {
|
|
|
746
746
|
i += e.length + 1;
|
|
747
747
|
let o = t.slice(0, r).trim(), s = t.slice(r + 1).trim();
|
|
748
748
|
if (!((e) => a.has(e))(o)) throw Error(`[Parser] '${o}' is not a known implicit variable. Known variables: ${[...a].join(", ")}.`);
|
|
749
|
-
if (i += e.length + 1, !
|
|
749
|
+
if (i += e.length + 1, !F(s)) throw Error(`[Parser] '${s}' is not a valid alias identifier.`);
|
|
750
750
|
if (i += e.length + 1, n.has(o)) throw Error(`[Parser] '${o}' is already aliased in this @for expression.`);
|
|
751
751
|
n.set(o, s), i += e.length + 1;
|
|
752
752
|
}
|
|
753
753
|
}
|
|
754
|
-
function
|
|
754
|
+
function P(e) {
|
|
755
755
|
let t = [], n = "", r = 0, i;
|
|
756
756
|
for (let a = 0; a < e.length; a++) {
|
|
757
757
|
let o = e[a];
|
|
@@ -781,17 +781,17 @@ function N(e) {
|
|
|
781
781
|
}
|
|
782
782
|
return n.trim().length > 0 && t.push(n), t;
|
|
783
783
|
}
|
|
784
|
-
function
|
|
784
|
+
function F(e) {
|
|
785
785
|
if (!e.length) return !1;
|
|
786
786
|
let n = t.createSourceFile("__id.ts", e, t.ScriptTarget.ESNext, !1).statements[0];
|
|
787
787
|
return !!n && t.isExpressionStatement(n) && t.isIdentifier(n.expression) && n.expression.text === e;
|
|
788
788
|
}
|
|
789
789
|
//#endregion
|
|
790
790
|
//#region ../packages/compiler/src/parser/states/parse-if.state.ts
|
|
791
|
-
function F(e, t, n) {
|
|
792
|
-
return I(e, t, n);
|
|
793
|
-
}
|
|
794
791
|
function I(e, t, n) {
|
|
792
|
+
return L(e, t, n);
|
|
793
|
+
}
|
|
794
|
+
function L(e, t, n) {
|
|
795
795
|
switch (n.type) {
|
|
796
796
|
case r.IF:
|
|
797
797
|
case r.ELSE_IF:
|
|
@@ -799,26 +799,26 @@ function I(e, t, n) {
|
|
|
799
799
|
let i = e.peek();
|
|
800
800
|
if (i.type !== r.CONDITION) throw Error(`[Parser] Expected CONDITION after ${r[n.type]}, got ${r[i.type]}`);
|
|
801
801
|
e.advance(2);
|
|
802
|
-
let a = i.parts[0], o =
|
|
802
|
+
let a = i.parts[0], o = T(a), s = A(e, t);
|
|
803
803
|
return {
|
|
804
|
-
type: n.type === r.IF ?
|
|
804
|
+
type: n.type === r.IF ? S.If : S.ElseIf,
|
|
805
805
|
condition: a,
|
|
806
806
|
conditionNode: o.node,
|
|
807
807
|
consequent: s,
|
|
808
|
-
alternate:
|
|
808
|
+
alternate: L(e, t, e.peek())
|
|
809
809
|
};
|
|
810
810
|
case r.ELSE:
|
|
811
811
|
e.advance(2);
|
|
812
|
-
let c =
|
|
812
|
+
let c = A(e, t);
|
|
813
813
|
return {
|
|
814
|
-
type:
|
|
814
|
+
type: S.Else,
|
|
815
815
|
consequent: c
|
|
816
816
|
};
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
819
|
//#endregion
|
|
820
820
|
//#region ../packages/compiler/src/parser/states/parse-switch.state.ts
|
|
821
|
-
function
|
|
821
|
+
function R(e, t, n) {
|
|
822
822
|
e.advance();
|
|
823
823
|
let i = e.peek();
|
|
824
824
|
if (i.type !== r.CONDITION) throw Error(`[Parser] Expected CONDITION after SWITCH, got ${r[i.type]}`);
|
|
@@ -835,50 +835,50 @@ function L(e, t, n) {
|
|
|
835
835
|
n.push(t.parts[0]), e.advance();
|
|
836
836
|
} while (e.peek().type !== r.BLOCK_OPEN);
|
|
837
837
|
e.advance(), o.push({
|
|
838
|
-
type:
|
|
838
|
+
type: S.Case,
|
|
839
839
|
condition: n,
|
|
840
|
-
children:
|
|
840
|
+
children: A(e, t)
|
|
841
841
|
});
|
|
842
842
|
break;
|
|
843
843
|
case r.DEFAULT:
|
|
844
844
|
e.advance(2), o.push({
|
|
845
|
-
type:
|
|
845
|
+
type: S.Case,
|
|
846
846
|
condition: null,
|
|
847
|
-
children:
|
|
847
|
+
children: A(e, t)
|
|
848
848
|
});
|
|
849
849
|
break;
|
|
850
850
|
}
|
|
851
851
|
return e.advance(), {
|
|
852
|
-
type:
|
|
852
|
+
type: S.Switch,
|
|
853
853
|
expression: a,
|
|
854
854
|
cases: o
|
|
855
855
|
};
|
|
856
856
|
}
|
|
857
857
|
//#endregion
|
|
858
858
|
//#region ../packages/compiler/src/parser/states/parse-text.state.ts
|
|
859
|
-
function
|
|
859
|
+
function z(e, t, n) {
|
|
860
860
|
return e.advance(), {
|
|
861
|
-
type:
|
|
861
|
+
type: S.Text,
|
|
862
862
|
value: n.parts[0]
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
865
|
//#endregion
|
|
866
866
|
//#region ../packages/compiler/src/parser/parser.ts
|
|
867
|
-
var
|
|
867
|
+
var B = class {
|
|
868
868
|
tokens;
|
|
869
869
|
_cursor;
|
|
870
870
|
_states = {
|
|
871
|
-
[r.TEXT]:
|
|
871
|
+
[r.TEXT]: z,
|
|
872
872
|
[r.INTERPOLATION_EXPRESSION]: C,
|
|
873
873
|
[r.INTERPOLATION_LITERAL]: C,
|
|
874
|
-
[r.TAG_OPEN_NAME]:
|
|
875
|
-
[r.IF]:
|
|
876
|
-
[r.FOR]:
|
|
877
|
-
[r.SWITCH]:
|
|
878
|
-
[r.CONST_DECLARATION]:
|
|
874
|
+
[r.TAG_OPEN_NAME]: ce,
|
|
875
|
+
[r.IF]: I,
|
|
876
|
+
[r.FOR]: j,
|
|
877
|
+
[r.SWITCH]: R,
|
|
878
|
+
[r.CONST_DECLARATION]: oe
|
|
879
879
|
};
|
|
880
880
|
constructor(e) {
|
|
881
|
-
this.tokens = e, this._cursor = new
|
|
881
|
+
this.tokens = e, this._cursor = new ae(this.tokens);
|
|
882
882
|
}
|
|
883
883
|
parse() {
|
|
884
884
|
let e = [];
|
|
@@ -895,7 +895,7 @@ var z = class {
|
|
|
895
895
|
if (!t) throw Error(`[Parser] No transition function for token type ${r[e.type]}`);
|
|
896
896
|
return t(this._cursor, this.parseNode.bind(this), e);
|
|
897
897
|
}
|
|
898
|
-
},
|
|
898
|
+
}, V = class {
|
|
899
899
|
_identifiers;
|
|
900
900
|
_parent;
|
|
901
901
|
constructor(e = [], t) {
|
|
@@ -908,7 +908,7 @@ var z = class {
|
|
|
908
908
|
getIdentifier(e) {
|
|
909
909
|
return this._identifiers.includes(e) ? e : this._parent?.getIdentifier(e);
|
|
910
910
|
}
|
|
911
|
-
},
|
|
911
|
+
}, ue = 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(".")), H = "this._root";
|
|
912
912
|
function U(e, t) {
|
|
913
913
|
return typeof e == "string" ? t.getIdentifier(e) ?? `this.${e}` : W(e, e, t);
|
|
914
914
|
}
|
|
@@ -928,7 +928,7 @@ function G(e, n) {
|
|
|
928
928
|
}), r;
|
|
929
929
|
}
|
|
930
930
|
function K(e, n) {
|
|
931
|
-
return !(t.isPropertyAccessExpression(n) && n.name === e ||
|
|
931
|
+
return !(t.isPropertyAccessExpression(n) && n.name === e || ue.has(e.text));
|
|
932
932
|
}
|
|
933
933
|
function q(...e) {
|
|
934
934
|
return e.map((e) => ` ${e}`);
|
|
@@ -947,10 +947,10 @@ function fe(e, t, n, r) {
|
|
|
947
947
|
//#endregion
|
|
948
948
|
//#region ../packages/compiler/src/render-generator/states/process-element.state.ts
|
|
949
949
|
function Y(e, t, n, r) {
|
|
950
|
-
let i = new
|
|
950
|
+
let i = new V([], r);
|
|
951
951
|
return [
|
|
952
952
|
`const ${t} = document.createElement("${e.tagName}");`,
|
|
953
|
-
...e.attributes?.map((e) => `${t}.setAttribute('${e.name}', ${typeof e.value == "string" ? e.value :
|
|
953
|
+
...e.attributes?.map((e) => `${t}.setAttribute('${e.name}', ${typeof e.value == "string" ? e.value : `${U(e.value.expression, r)}`});`) || [],
|
|
954
954
|
...e.events?.map((e) => `${t}.addEventListener("${e.name}", ($event) => this.${e.handler}.bind(this));`) || [],
|
|
955
955
|
`${n}.appendChild(${t});`,
|
|
956
956
|
...e.children.map((e, n) => $(e, n.toString(), t, i)).flat()
|
|
@@ -959,7 +959,7 @@ function Y(e, t, n, r) {
|
|
|
959
959
|
//#endregion
|
|
960
960
|
//#region ../packages/compiler/src/render-generator/states/process-for.state.ts
|
|
961
961
|
function pe(e, t, n, r) {
|
|
962
|
-
let i = e.iterableSource, a = r.getIdentifier(i) ?? `this.${i}`, o = J(n, t, "items"), s = J(n, t, "i"), c = X(e, "$index"), l = X(e, "$first"), u = X(e, "$last"), d = X(e, "$even"), f = X(e, "$odd"), p = new
|
|
962
|
+
let i = e.iterableSource, a = r.getIdentifier(i) ?? `this.${i}`, o = J(n, t, "items"), s = J(n, t, "i"), c = X(e, "$index"), l = X(e, "$first"), u = X(e, "$last"), d = X(e, "$even"), f = X(e, "$odd"), p = new V([
|
|
963
963
|
e.itemAlias,
|
|
964
964
|
c,
|
|
965
965
|
l,
|
|
@@ -987,17 +987,17 @@ function X(e, t) {
|
|
|
987
987
|
//#endregion
|
|
988
988
|
//#region ../packages/compiler/src/render-generator/states/process-if.state.ts
|
|
989
989
|
function me(e, t, n, r) {
|
|
990
|
-
let i = new
|
|
990
|
+
let i = new V([], r), a = [
|
|
991
991
|
`if (${U(e.conditionNode, r)}) {`,
|
|
992
992
|
...Z(e, t, n, i),
|
|
993
993
|
"}"
|
|
994
994
|
], o = e.alternate;
|
|
995
|
-
for (; o?.type ===
|
|
996
|
-
let e = new
|
|
995
|
+
for (; o?.type === S.ElseIf;) {
|
|
996
|
+
let e = new V([], r);
|
|
997
997
|
a[a.length - 1] += ` else if (${U(o.conditionNode, r)}) {`, a.push(...Z(o, t, n, e), "}"), o = o.alternate;
|
|
998
998
|
}
|
|
999
999
|
if (o) {
|
|
1000
|
-
let e = new
|
|
1000
|
+
let e = new V([], r);
|
|
1001
1001
|
a[a.length - 1] += " else {", a.push(...Z(o, t, n, e), "}");
|
|
1002
1002
|
}
|
|
1003
1003
|
return a;
|
|
@@ -1010,53 +1010,56 @@ function Z(e, t, n, r) {
|
|
|
1010
1010
|
function he(e, t, n, r) {
|
|
1011
1011
|
return [
|
|
1012
1012
|
`switch (${U(e.expression, r)}) {`,
|
|
1013
|
-
...e.cases.map((e) => [...q(...e.condition ? e.condition.map((e, t, n) => `case ${e}:${t === n.length - 1 ? " {" : ""}`) : ["default: {"], ...e.children.map((e, i) => q(...$(e, `${t}_${i}_${i}`, n, new
|
|
1013
|
+
...e.cases.map((e) => [...q(...e.condition ? e.condition.map((e, t, n) => `case ${e}:${t === n.length - 1 ? " {" : ""}`) : ["default: {"], ...e.children.map((e, i) => q(...$(e, `${t}_${i}_${i}`, n, new V([], r)))).flat(), `${q("break;")}`, "}")]).flat(),
|
|
1014
1014
|
"}"
|
|
1015
1015
|
];
|
|
1016
1016
|
}
|
|
1017
1017
|
//#endregion
|
|
1018
1018
|
//#region ../packages/compiler/src/render-generator/states/process-text-and-interpolation.state.ts
|
|
1019
1019
|
function ge(e, t, n, r) {
|
|
1020
|
-
return [`const ${t} = document.createTextNode(${e.type ===
|
|
1020
|
+
return [`const ${t} = document.createTextNode(${e.type === S.Text ? JSON.stringify(e.value) : U(e.expression, r)});`, `${n}.appendChild(${t});`];
|
|
1021
1021
|
}
|
|
1022
1022
|
//#endregion
|
|
1023
1023
|
//#region ../packages/compiler/src/render-generator/render-generator.ts
|
|
1024
1024
|
var Q = /* @__PURE__ */ new Map();
|
|
1025
|
-
function _e(e) {
|
|
1025
|
+
function _e(e, t) {
|
|
1026
1026
|
Q.clear();
|
|
1027
|
-
let
|
|
1027
|
+
let n = new V(), r = [
|
|
1028
|
+
"static {",
|
|
1029
|
+
...q("this.__sheet = new CSSStyleSheet;", `this.__sheet.replaceSync(${t});`),
|
|
1030
|
+
"}\n",
|
|
1028
1031
|
"_render() {",
|
|
1029
|
-
...q(...e.map((e,
|
|
1032
|
+
...q(...e.map((e, t) => [...$(e, t.toString(), H, n), ""]).flat()),
|
|
1030
1033
|
"}"
|
|
1031
1034
|
];
|
|
1032
1035
|
for (; Q.size > 0;) {
|
|
1033
1036
|
let [e, t] = Q.entries().next().value;
|
|
1034
|
-
|
|
1037
|
+
r.push("", `${e} {`, ...q(...t()), "}"), Q.delete(e);
|
|
1035
1038
|
}
|
|
1036
|
-
return
|
|
1039
|
+
return r.join("\n");
|
|
1037
1040
|
}
|
|
1038
1041
|
function $(e, t, n, r) {
|
|
1039
1042
|
switch (e.type) {
|
|
1040
|
-
case
|
|
1041
|
-
case
|
|
1042
|
-
case
|
|
1043
|
-
case
|
|
1043
|
+
case S.Text:
|
|
1044
|
+
case S.Interpolation: return ge(e, J(n, t), n, r);
|
|
1045
|
+
case S.Element: return Y(e, de(e, n, t), n, r);
|
|
1046
|
+
case S.If:
|
|
1044
1047
|
let i = `control_flow_if_${t}()`;
|
|
1045
1048
|
return Q.set(i, () => me(e, t, n, r)), [`this.${i};`];
|
|
1046
|
-
case
|
|
1049
|
+
case S.For:
|
|
1047
1050
|
let a = `control_flow_for_${t}()`;
|
|
1048
1051
|
return Q.set(a, () => pe(e, t, n, r)), [`this.${a};`];
|
|
1049
|
-
case
|
|
1052
|
+
case S.Switch:
|
|
1050
1053
|
let o = `control_flow_switch_${t}()`;
|
|
1051
1054
|
return Q.set(o, () => he(e, t, n, r)), [`this.${o};`];
|
|
1052
|
-
case
|
|
1055
|
+
case S.ConstDeclaration: return fe(e, t, n, r);
|
|
1053
1056
|
default: return [];
|
|
1054
1057
|
}
|
|
1055
1058
|
}
|
|
1056
1059
|
//#endregion
|
|
1057
1060
|
//#region ../packages/compiler/src/compile.ts
|
|
1058
|
-
function ve(e) {
|
|
1059
|
-
return _e(new
|
|
1061
|
+
function ve(e, t) {
|
|
1062
|
+
return _e(new B(new ie(e).tokenize()).parse(), t);
|
|
1060
1063
|
}
|
|
1061
1064
|
//#endregion
|
|
1062
1065
|
export { ve as compile };
|