@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/parser.cjs
CHANGED
|
@@ -71,6 +71,15 @@ var Reader = class {
|
|
|
71
71
|
eof() {
|
|
72
72
|
return this.pi >= this.pieces.length;
|
|
73
73
|
}
|
|
74
|
+
/** Where the cursor is, to come back to with `reset`. */
|
|
75
|
+
mark() {
|
|
76
|
+
return [this.pi, this.oi];
|
|
77
|
+
}
|
|
78
|
+
/** Back to a position `mark` returned. */
|
|
79
|
+
reset([pi, oi]) {
|
|
80
|
+
this.pi = pi;
|
|
81
|
+
this.oi = oi;
|
|
82
|
+
}
|
|
74
83
|
/** Absolute source offset of the cursor. */
|
|
75
84
|
pos() {
|
|
76
85
|
if (this.eof()) {
|
|
@@ -236,12 +245,18 @@ var CORE_DIRECTIVES = [
|
|
|
236
245
|
{
|
|
237
246
|
id: "load",
|
|
238
247
|
match: (n) => n.startsWith("load:"),
|
|
239
|
-
build: (raw) =>
|
|
240
|
-
kind
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
build: (raw) => {
|
|
249
|
+
if (raw.value && raw.value.kind !== "static") {
|
|
250
|
+
raw.report("invalid-binding", `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
kind: "LoadDirective",
|
|
254
|
+
strategy: raw.name.slice("load:".length),
|
|
255
|
+
modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
|
|
256
|
+
...raw.value && raw.value.kind !== "static" ? { dynamic: true } : {},
|
|
257
|
+
loc: raw.loc
|
|
258
|
+
};
|
|
259
|
+
}
|
|
245
260
|
},
|
|
246
261
|
// Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
|
|
247
262
|
{
|
|
@@ -491,6 +506,9 @@ var NAME_CHAR = /[A-Za-z0-9\-_:@.?]/;
|
|
|
491
506
|
var Parser = class {
|
|
492
507
|
constructor(pieces, opts) {
|
|
493
508
|
this.diagnostics = [];
|
|
509
|
+
/** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
|
|
510
|
+
/** Tags open around the element being parsed, outermost first. */
|
|
511
|
+
this.open = [];
|
|
494
512
|
this.r = new Reader(pieces);
|
|
495
513
|
this.svg = opts.svg ?? false;
|
|
496
514
|
this.directives = opts.directives ?? CORE_DIRECTIVES;
|
|
@@ -677,11 +695,19 @@ var Parser = class {
|
|
|
677
695
|
} else {
|
|
678
696
|
if (this.r.peek() === ">") this.r.advance();
|
|
679
697
|
if (!isVoid) {
|
|
698
|
+
this.open.push(tag);
|
|
680
699
|
children = rawText ? this.parseRawText(tag) : this.parseChildren();
|
|
700
|
+
this.open.pop();
|
|
681
701
|
if (this.r.startsWith("</")) {
|
|
702
|
+
const before = this.r.mark();
|
|
682
703
|
const name = this.consumeCloseTag();
|
|
683
704
|
if (name && name !== tag) {
|
|
684
|
-
|
|
705
|
+
if (this.open.includes(name)) {
|
|
706
|
+
this.r.reset(before);
|
|
707
|
+
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
708
|
+
} else {
|
|
709
|
+
this.report("mismatched-close-tag", "error", `Expected </${tag}>, got </${name}>`, this.r.span(start));
|
|
710
|
+
}
|
|
685
711
|
}
|
|
686
712
|
} else {
|
|
687
713
|
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
@@ -838,9 +864,6 @@ var Parser = class {
|
|
|
838
864
|
if (eachCount > 1) this.report("duplicate-directive", "error", "Multiple `each` directives on one element", span);
|
|
839
865
|
if (ifCount > 1) this.report("duplicate-directive", "error", "Multiple `if` directives on one element", span);
|
|
840
866
|
if (refCount > 1) this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", span);
|
|
841
|
-
if (ifCount > 0 && eachCount > 0) {
|
|
842
|
-
this.report("unsupported-combination", "error", "`if` and `each` cannot both apply to one element — wrap one in another element", span);
|
|
843
|
-
}
|
|
844
867
|
if (ifCount > 0 && elseCount > 0) {
|
|
845
868
|
this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", span);
|
|
846
869
|
}
|
|
@@ -861,7 +884,6 @@ var Parser = class {
|
|
|
861
884
|
readName() {
|
|
862
885
|
return this.r.readWhile((ch) => NAME_CHAR.test(ch));
|
|
863
886
|
}
|
|
864
|
-
/** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
|
|
865
887
|
consumeCloseTag() {
|
|
866
888
|
this.r.advance();
|
|
867
889
|
this.r.advance();
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAYL,KAAK,WAAW,EAQjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAEL,KAAK,mBAAmB,EAGzB,MAAM,iBAAiB,CAAC;AAMzB,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,8EAA8E;IAC9E,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAYL,KAAK,WAAW,EAQjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAEL,KAAK,mBAAmB,EAGzB,MAAM,iBAAiB,CAAC;AAMzB,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,8EAA8E;IAC9E,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAoaD,gFAAgF;AAChF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,EAC/C,IAAI,GAAE,aAAkB,GACvB,WAAW,CAEb"}
|
package/dist/parser.js
CHANGED
|
Binary file
|