@fluixi/template-parser 1.0.0-alpha.108 → 1.0.0-alpha.110
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/a11y.mjs +3 -76
- package/dist/ast.d.cts +2 -0
- package/dist/ast.d.ts +2 -0
- package/dist/ast.d.ts.map +1 -1
- package/dist/ast.mjs +4 -21
- package/dist/chunk-6YLLM7OB.mjs +104 -0
- package/dist/chunk-D6ZSK2S6.mjs +422 -0
- package/dist/chunk-DK3MEEE6.mjs +80 -0
- package/dist/chunk-IP5F3OXX.mjs +192 -0
- package/dist/chunk-R4NGOY2K.mjs +26 -0
- package/dist/chunk-Y6M7YL7A.mjs +111 -0
- package/dist/directives.cjs +12 -6
- package/dist/directives.d.ts.map +1 -1
- package/dist/directives.js +14 -6
- package/dist/directives.mjs +5 -180
- package/dist/index.cjs +34 -12
- package/dist/index.mjs +19 -855
- package/dist/parser.cjs +33 -11
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +0 -0
- package/dist/parser.mjs +8 -853
- package/dist/reader.cjs +9 -0
- package/dist/reader.d.cts +4 -0
- package/dist/reader.d.ts +4 -0
- package/dist/reader.d.ts.map +1 -1
- package/dist/reader.js +9 -0
- package/dist/reader.mjs +3 -98
- package/dist/tags.mjs +7 -96
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/template-parser v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/template-parser v1.0.0-alpha.110 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -80,6 +80,15 @@ var Reader = class {
|
|
|
80
80
|
eof() {
|
|
81
81
|
return this.pi >= this.pieces.length;
|
|
82
82
|
}
|
|
83
|
+
/** Where the cursor is, to come back to with `reset`. */
|
|
84
|
+
mark() {
|
|
85
|
+
return [this.pi, this.oi];
|
|
86
|
+
}
|
|
87
|
+
/** Back to a position `mark` returned. */
|
|
88
|
+
reset([pi, oi]) {
|
|
89
|
+
this.pi = pi;
|
|
90
|
+
this.oi = oi;
|
|
91
|
+
}
|
|
83
92
|
/** Absolute source offset of the cursor. */
|
|
84
93
|
pos() {
|
|
85
94
|
if (this.eof()) {
|
|
@@ -245,12 +254,18 @@ var CORE_DIRECTIVES = [
|
|
|
245
254
|
{
|
|
246
255
|
id: "load",
|
|
247
256
|
match: (n) => n.startsWith("load:"),
|
|
248
|
-
build: (raw) =>
|
|
249
|
-
kind
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
build: (raw) => {
|
|
258
|
+
if (raw.value && raw.value.kind !== "static") {
|
|
259
|
+
raw.report("invalid-binding", `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
kind: "LoadDirective",
|
|
263
|
+
strategy: raw.name.slice("load:".length),
|
|
264
|
+
modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
|
|
265
|
+
...raw.value && raw.value.kind !== "static" ? { dynamic: true } : {},
|
|
266
|
+
loc: raw.loc
|
|
267
|
+
};
|
|
268
|
+
}
|
|
254
269
|
},
|
|
255
270
|
// Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
|
|
256
271
|
{
|
|
@@ -500,6 +515,9 @@ var NAME_CHAR = /[A-Za-z0-9\-_:@.?]/;
|
|
|
500
515
|
var Parser = class {
|
|
501
516
|
constructor(pieces, opts) {
|
|
502
517
|
this.diagnostics = [];
|
|
518
|
+
/** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
|
|
519
|
+
/** Tags open around the element being parsed, outermost first. */
|
|
520
|
+
this.open = [];
|
|
503
521
|
this.r = new Reader(pieces);
|
|
504
522
|
this.svg = opts.svg ?? false;
|
|
505
523
|
this.directives = opts.directives ?? CORE_DIRECTIVES;
|
|
@@ -686,11 +704,19 @@ var Parser = class {
|
|
|
686
704
|
} else {
|
|
687
705
|
if (this.r.peek() === ">") this.r.advance();
|
|
688
706
|
if (!isVoid) {
|
|
707
|
+
this.open.push(tag);
|
|
689
708
|
children = rawText ? this.parseRawText(tag) : this.parseChildren();
|
|
709
|
+
this.open.pop();
|
|
690
710
|
if (this.r.startsWith("</")) {
|
|
711
|
+
const before = this.r.mark();
|
|
691
712
|
const name = this.consumeCloseTag();
|
|
692
713
|
if (name && name !== tag) {
|
|
693
|
-
|
|
714
|
+
if (this.open.includes(name)) {
|
|
715
|
+
this.r.reset(before);
|
|
716
|
+
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
717
|
+
} else {
|
|
718
|
+
this.report("mismatched-close-tag", "error", `Expected </${tag}>, got </${name}>`, this.r.span(start));
|
|
719
|
+
}
|
|
694
720
|
}
|
|
695
721
|
} else {
|
|
696
722
|
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
@@ -847,9 +873,6 @@ var Parser = class {
|
|
|
847
873
|
if (eachCount > 1) this.report("duplicate-directive", "error", "Multiple `each` directives on one element", span);
|
|
848
874
|
if (ifCount > 1) this.report("duplicate-directive", "error", "Multiple `if` directives on one element", span);
|
|
849
875
|
if (refCount > 1) this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", span);
|
|
850
|
-
if (ifCount > 0 && eachCount > 0) {
|
|
851
|
-
this.report("unsupported-combination", "error", "`if` and `each` cannot both apply to one element — wrap one in another element", span);
|
|
852
|
-
}
|
|
853
876
|
if (ifCount > 0 && elseCount > 0) {
|
|
854
877
|
this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", span);
|
|
855
878
|
}
|
|
@@ -870,7 +893,6 @@ var Parser = class {
|
|
|
870
893
|
readName() {
|
|
871
894
|
return this.r.readWhile((ch) => NAME_CHAR.test(ch));
|
|
872
895
|
}
|
|
873
|
-
/** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
|
|
874
896
|
consumeCloseTag() {
|
|
875
897
|
this.r.advance();
|
|
876
898
|
this.r.advance();
|