@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/a11y.mjs
CHANGED
|
@@ -1,79 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"button",
|
|
5
|
-
"input",
|
|
6
|
-
"select",
|
|
7
|
-
"textarea",
|
|
8
|
-
"summary",
|
|
9
|
-
"details",
|
|
10
|
-
"option",
|
|
11
|
-
"label"
|
|
12
|
-
]);
|
|
13
|
-
var KEY_EVENTS = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
|
|
14
|
-
function attributeNamed(node, name) {
|
|
15
|
-
return node.attributes.find((a) => "name" in a && a.name === name);
|
|
16
|
-
}
|
|
17
|
-
function hasSpread(node) {
|
|
18
|
-
return node.attributes.some((a) => a.kind === "Spread");
|
|
19
|
-
}
|
|
20
|
-
function staticValue(node, name) {
|
|
21
|
-
const attribute = attributeNamed(node, name);
|
|
22
|
-
if (!attribute || attribute.kind !== "Attribute" || !attribute.value) return void 0;
|
|
23
|
-
const value = attribute.value;
|
|
24
|
-
return value.kind === "static" ? value.value : void 0;
|
|
25
|
-
}
|
|
26
|
-
function isPresentational(node) {
|
|
27
|
-
const role = staticValue(node, "role");
|
|
28
|
-
if (role === "presentation" || role === "none") return true;
|
|
29
|
-
return staticValue(node, "aria-hidden") === "true";
|
|
30
|
-
}
|
|
31
|
-
function hasEvent(node, predicate) {
|
|
32
|
-
return node.attributes.some((a) => a.kind === "EventBinding" && predicate(a.name));
|
|
33
|
-
}
|
|
34
|
-
function checkAccessibility(root) {
|
|
35
|
-
const out = [];
|
|
36
|
-
const report = (node, code, message) => {
|
|
37
|
-
out.push({ code, message, severity: "warning", loc: node.loc });
|
|
38
|
-
};
|
|
39
|
-
const visit = (nodes) => {
|
|
40
|
-
for (const node of nodes) {
|
|
41
|
-
if (node.kind === "Element") check(node, report);
|
|
42
|
-
const children = "children" in node ? node.children : void 0;
|
|
43
|
-
if (children) visit(children);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
visit(root.children);
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
function check(node, report) {
|
|
50
|
-
if (hasSpread(node)) return;
|
|
51
|
-
const tag = node.tag.toLowerCase();
|
|
52
|
-
if (tag === "img" && !attributeNamed(node, "alt") && !isPresentational(node)) {
|
|
53
|
-
report(node, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.');
|
|
54
|
-
}
|
|
55
|
-
if (tag === "a" && !attributeNamed(node, "href") && !attributeNamed(node, "role")) {
|
|
56
|
-
report(node, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action.");
|
|
57
|
-
}
|
|
58
|
-
if (tag === "iframe" && !attributeNamed(node, "title")) {
|
|
59
|
-
report(node, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
|
|
60
|
-
}
|
|
61
|
-
const tabindex = staticValue(node, "tabindex") ?? staticValue(node, "tabIndex");
|
|
62
|
-
if (tabindex !== void 0 && Number(tabindex) > 0) {
|
|
63
|
-
report(
|
|
64
|
-
node,
|
|
65
|
-
"a11y-positive-tabindex",
|
|
66
|
-
"A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (!INTERACTIVE.has(tag) && hasEvent(node, (name) => name === "click") && !attributeNamed(node, "role") && !hasEvent(node, (name) => KEY_EVENTS.has(name))) {
|
|
70
|
-
report(
|
|
71
|
-
node,
|
|
72
|
-
"a11y-click-without-keyboard",
|
|
73
|
-
`A click handler on \`${tag}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
checkAccessibility
|
|
3
|
+
} from "./chunk-DK3MEEE6.mjs";
|
|
77
4
|
export {
|
|
78
5
|
checkAccessibility
|
|
79
6
|
};
|
package/dist/ast.d.cts
CHANGED
|
@@ -191,6 +191,8 @@ export interface LoadDirectiveNode extends NodeBase {
|
|
|
191
191
|
strategy: string;
|
|
192
192
|
/** `load:visible="200px"` → `'200px'`. Null for a bare directive. */
|
|
193
193
|
modifier: string | null;
|
|
194
|
+
/** The value was an expression (`load:visible=\${m}`), which a compile-time strategy cannot take. */
|
|
195
|
+
dynamic?: boolean;
|
|
194
196
|
}
|
|
195
197
|
/** `use=${directive}` or `use:tooltip` (optionally `use:tooltip=${opts}`). */
|
|
196
198
|
export interface UseDirectiveNode extends NodeBase {
|
package/dist/ast.d.ts
CHANGED
|
@@ -191,6 +191,8 @@ export interface LoadDirectiveNode extends NodeBase {
|
|
|
191
191
|
strategy: string;
|
|
192
192
|
/** `load:visible="200px"` → `'200px'`. Null for a bare directive. */
|
|
193
193
|
modifier: string | null;
|
|
194
|
+
/** The value was an expression (`load:visible=\${m}`), which a compile-time strategy cannot take. */
|
|
195
|
+
dynamic?: boolean;
|
|
194
196
|
}
|
|
195
197
|
/** `use=${directive}` or `use:tooltip` (optionally `use:tooltip=${opts}`). */
|
|
196
198
|
export interface UseDirectiveNode extends NodeBase {
|
package/dist/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAIlD,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,SAAS,GACT,WAAW,GACX,UAAU,GACV,MAAM,GACN,SAAS,GACT,YAAY,CAAC;AAEjB,MAAM,MAAM,QAAQ,GAChB,WAAW,GACX,iBAAiB,GACjB,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,aAAa,GACb,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,MAAM,CAAC;AAEX,4EAA4E;AAC5E,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,WAAW,GACX,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,cAAc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AC;CACrB;AAED,mFAAmF;AACnF,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAID,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,EAAE,UAAU,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,sBAAsB,GACtB,iBAAiB,GACjB,kBAAkB,GAClB,qBAAqB,GACrB,iBAAiB,GACjB,mBAAmB,GACnB,iBAAiB,GACjB,yBAAyB,GAGzB,cAAc,GACd,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,GACxB,6BAA6B,CAAC;AAElC,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAID,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAQnD;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,CAU7D"}
|
package/dist/ast.mjs
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const kids = childrenOf(node);
|
|
6
|
-
for (const child of kids) visit(child, node);
|
|
7
|
-
};
|
|
8
|
-
visit(root, null);
|
|
9
|
-
return root;
|
|
10
|
-
}
|
|
11
|
-
function childrenOf(node) {
|
|
12
|
-
switch (node.kind) {
|
|
13
|
-
case "Root":
|
|
14
|
-
case "Element":
|
|
15
|
-
case "Component":
|
|
16
|
-
case "Fragment":
|
|
17
|
-
return node.children;
|
|
18
|
-
default:
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
childrenOf,
|
|
3
|
+
setParents
|
|
4
|
+
} from "./chunk-R4NGOY2K.mjs";
|
|
22
5
|
export {
|
|
23
6
|
childrenOf,
|
|
24
7
|
setParents
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/tags.ts
|
|
2
|
+
var SVG_TAGS = /* @__PURE__ */ new Set([
|
|
3
|
+
"svg",
|
|
4
|
+
"g",
|
|
5
|
+
"defs",
|
|
6
|
+
"symbol",
|
|
7
|
+
"use",
|
|
8
|
+
"switch",
|
|
9
|
+
"view",
|
|
10
|
+
"desc",
|
|
11
|
+
"metadata",
|
|
12
|
+
"path",
|
|
13
|
+
"circle",
|
|
14
|
+
"ellipse",
|
|
15
|
+
"line",
|
|
16
|
+
"polygon",
|
|
17
|
+
"polyline",
|
|
18
|
+
"rect",
|
|
19
|
+
"image",
|
|
20
|
+
"text",
|
|
21
|
+
"tspan",
|
|
22
|
+
"textPath",
|
|
23
|
+
"linearGradient",
|
|
24
|
+
"radialGradient",
|
|
25
|
+
"stop",
|
|
26
|
+
"pattern",
|
|
27
|
+
"mask",
|
|
28
|
+
"clipPath",
|
|
29
|
+
"marker",
|
|
30
|
+
"foreignObject",
|
|
31
|
+
"animate",
|
|
32
|
+
"animateMotion",
|
|
33
|
+
"animateTransform",
|
|
34
|
+
"mpath",
|
|
35
|
+
"set",
|
|
36
|
+
"filter",
|
|
37
|
+
"feBlend",
|
|
38
|
+
"feColorMatrix",
|
|
39
|
+
"feComponentTransfer",
|
|
40
|
+
"feComposite",
|
|
41
|
+
"feConvolveMatrix",
|
|
42
|
+
"feDiffuseLighting",
|
|
43
|
+
"feDisplacementMap",
|
|
44
|
+
"feDistantLight",
|
|
45
|
+
"feDropShadow",
|
|
46
|
+
"feFlood",
|
|
47
|
+
"feFuncA",
|
|
48
|
+
"feFuncB",
|
|
49
|
+
"feFuncG",
|
|
50
|
+
"feFuncR",
|
|
51
|
+
"feGaussianBlur",
|
|
52
|
+
"feImage",
|
|
53
|
+
"feMerge",
|
|
54
|
+
"feMergeNode",
|
|
55
|
+
"feMorphology",
|
|
56
|
+
"feOffset",
|
|
57
|
+
"fePointLight",
|
|
58
|
+
"feSpecularLighting",
|
|
59
|
+
"feSpotLight",
|
|
60
|
+
"feTile",
|
|
61
|
+
"feTurbulence"
|
|
62
|
+
]);
|
|
63
|
+
var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
|
|
64
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
65
|
+
"area",
|
|
66
|
+
"base",
|
|
67
|
+
"br",
|
|
68
|
+
"col",
|
|
69
|
+
"embed",
|
|
70
|
+
"hr",
|
|
71
|
+
"img",
|
|
72
|
+
"input",
|
|
73
|
+
"link",
|
|
74
|
+
"meta",
|
|
75
|
+
"param",
|
|
76
|
+
"source",
|
|
77
|
+
"track",
|
|
78
|
+
"wbr"
|
|
79
|
+
]);
|
|
80
|
+
var DELEGATED_EVENTS = /* @__PURE__ */ new Set([
|
|
81
|
+
"click",
|
|
82
|
+
"dblclick",
|
|
83
|
+
"input",
|
|
84
|
+
"change",
|
|
85
|
+
"submit",
|
|
86
|
+
"focus",
|
|
87
|
+
"blur",
|
|
88
|
+
"keydown",
|
|
89
|
+
"keyup",
|
|
90
|
+
"keypress",
|
|
91
|
+
"mousedown",
|
|
92
|
+
"mouseup"
|
|
93
|
+
]);
|
|
94
|
+
function isComponentTag(tag) {
|
|
95
|
+
return tag.length > 0 && (tag[0] !== tag[0].toLowerCase() || tag.includes("."));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
SVG_TAGS,
|
|
100
|
+
RAW_TEXT_ELEMENTS,
|
|
101
|
+
VOID_ELEMENTS,
|
|
102
|
+
DELEGATED_EVENTS,
|
|
103
|
+
isComponentTag
|
|
104
|
+
};
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkAccessibility
|
|
3
|
+
} from "./chunk-DK3MEEE6.mjs";
|
|
4
|
+
import {
|
|
5
|
+
setParents
|
|
6
|
+
} from "./chunk-R4NGOY2K.mjs";
|
|
7
|
+
import {
|
|
8
|
+
CORE_DIRECTIVES,
|
|
9
|
+
resolveAttribute
|
|
10
|
+
} from "./chunk-IP5F3OXX.mjs";
|
|
11
|
+
import {
|
|
12
|
+
Reader
|
|
13
|
+
} from "./chunk-Y6M7YL7A.mjs";
|
|
14
|
+
import {
|
|
15
|
+
RAW_TEXT_ELEMENTS,
|
|
16
|
+
SVG_TAGS,
|
|
17
|
+
VOID_ELEMENTS,
|
|
18
|
+
isComponentTag
|
|
19
|
+
} from "./chunk-6YLLM7OB.mjs";
|
|
20
|
+
|
|
21
|
+
// src/parser.ts
|
|
22
|
+
var NAME_CHAR = /[A-Za-z0-9\-_:@.?]/;
|
|
23
|
+
var Parser = class {
|
|
24
|
+
constructor(pieces, opts) {
|
|
25
|
+
this.diagnostics = [];
|
|
26
|
+
/** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
|
|
27
|
+
/** Tags open around the element being parsed, outermost first. */
|
|
28
|
+
this.open = [];
|
|
29
|
+
this.r = new Reader(pieces);
|
|
30
|
+
this.svg = opts.svg ?? false;
|
|
31
|
+
this.directives = opts.directives ?? CORE_DIRECTIVES;
|
|
32
|
+
this.accessibility = opts.accessibility ?? true;
|
|
33
|
+
}
|
|
34
|
+
parse() {
|
|
35
|
+
const start = this.r.pos();
|
|
36
|
+
const children = [];
|
|
37
|
+
while (!this.r.eof()) {
|
|
38
|
+
children.push(...this.parseChildren());
|
|
39
|
+
if (this.r.eof()) break;
|
|
40
|
+
const s = this.r.pos();
|
|
41
|
+
this.consumeCloseTag();
|
|
42
|
+
this.report("stray-close-tag", "error", "Close tag without a matching open tag", this.r.span(s));
|
|
43
|
+
}
|
|
44
|
+
const root = { kind: "Root", children, loc: this.r.span(start) };
|
|
45
|
+
setParents(root);
|
|
46
|
+
this.validateTree(root);
|
|
47
|
+
if (this.accessibility) {
|
|
48
|
+
this.diagnostics.push(...checkAccessibility(root));
|
|
49
|
+
}
|
|
50
|
+
return { root, diagnostics: this.diagnostics };
|
|
51
|
+
}
|
|
52
|
+
/** Cross-node validation that needs the built tree (sibling relationships). */
|
|
53
|
+
validateTree(root) {
|
|
54
|
+
const visit = (nodes) => {
|
|
55
|
+
let prevBranch = null;
|
|
56
|
+
for (const node of nodes) {
|
|
57
|
+
if (node.kind === "Text" && /^\s*$/.test(node.value)) continue;
|
|
58
|
+
if (node.kind === "Element" || node.kind === "Component") {
|
|
59
|
+
const hasElse = node.attributes.some((a) => a.kind === "ElseDirective");
|
|
60
|
+
if (hasElse) {
|
|
61
|
+
const prevHasIf = prevBranch != null && (prevBranch.kind === "Element" || prevBranch.kind === "Component") && prevBranch.attributes.some((a) => a.kind === "IfDirective");
|
|
62
|
+
if (!prevHasIf) {
|
|
63
|
+
this.report("else-without-if", "error", "`else` must immediately follow an element with `if`", node.loc);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
prevBranch = node;
|
|
67
|
+
} else {
|
|
68
|
+
prevBranch = null;
|
|
69
|
+
}
|
|
70
|
+
if ("children" in node && node.children) visit(node.children);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
visit(root.children);
|
|
74
|
+
}
|
|
75
|
+
// content
|
|
76
|
+
/** Parse sibling nodes until EOF or a `</` close the caller must consume. */
|
|
77
|
+
parseChildren() {
|
|
78
|
+
const out = [];
|
|
79
|
+
while (!this.r.eof()) {
|
|
80
|
+
if (this.r.startsWith("</")) break;
|
|
81
|
+
if (this.r.startsWith("<!--")) {
|
|
82
|
+
out.push(this.parseComment());
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (this.isFragmentStart()) {
|
|
86
|
+
out.push(this.parseFragment());
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (this.isDynamicTagStart()) {
|
|
90
|
+
out.push(this.parseDynamicComponent());
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (this.isTagStart()) {
|
|
94
|
+
out.push(this.parseElement());
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (this.r.atHole()) {
|
|
98
|
+
const h = this.r.takeHole();
|
|
99
|
+
const node = { kind: "Expression", hole: h.index, loc: h.loc };
|
|
100
|
+
out.push(node);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const text = this.readText();
|
|
104
|
+
if (text) out.push(text);
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
isTagStart() {
|
|
109
|
+
return this.r.peek() === "<" && /[A-Za-z]/.test(this.r.peek(1));
|
|
110
|
+
}
|
|
111
|
+
isFragmentStart() {
|
|
112
|
+
return this.r.peek() === "<" && this.r.peek(1) === ">";
|
|
113
|
+
}
|
|
114
|
+
/** `<${Comp} ...>`: a component whose tag is an interpolated expression. */
|
|
115
|
+
isDynamicTagStart() {
|
|
116
|
+
return this.r.peek() === "<" && this.r.holeFollows();
|
|
117
|
+
}
|
|
118
|
+
/** Parse `<${Comp} .../>` or `<${Comp} ...>...</${Comp}>` into a dynamic ComponentNode. */
|
|
119
|
+
parseDynamicComponent() {
|
|
120
|
+
const start = this.r.pos();
|
|
121
|
+
this.r.advance();
|
|
122
|
+
const tagHole = this.r.takeHole().index;
|
|
123
|
+
const attributes = this.parseAttributes(true);
|
|
124
|
+
this.r.skipWhitespace();
|
|
125
|
+
let selfClosing = false;
|
|
126
|
+
let children = [];
|
|
127
|
+
if (this.r.startsWith("/>")) {
|
|
128
|
+
this.r.advance();
|
|
129
|
+
this.r.advance();
|
|
130
|
+
selfClosing = true;
|
|
131
|
+
} else {
|
|
132
|
+
if (this.r.peek() === ">") this.r.advance();
|
|
133
|
+
children = this.parseChildren();
|
|
134
|
+
if (this.r.startsWith("</")) {
|
|
135
|
+
this.r.advance();
|
|
136
|
+
this.r.advance();
|
|
137
|
+
if (this.r.atHole()) this.r.takeHole();
|
|
138
|
+
else this.readName();
|
|
139
|
+
this.r.skipWhitespace();
|
|
140
|
+
if (this.r.peek() === ">") this.r.advance();
|
|
141
|
+
} else {
|
|
142
|
+
this.report("unclosed-tag", "error", "Unclosed dynamic component", this.r.span(start));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { kind: "Component", tag: "", tagHole, attributes, children, selfClosing, loc: this.r.span(start) };
|
|
146
|
+
}
|
|
147
|
+
/** A raw text run (preserved verbatim; whitespace is normalized at lowering). */
|
|
148
|
+
readText() {
|
|
149
|
+
const start = this.r.pos();
|
|
150
|
+
let value = "";
|
|
151
|
+
while (!this.r.eof() && !this.r.atHole()) {
|
|
152
|
+
if (this.r.startsWith("</") || this.r.startsWith("<!--") || this.isTagStart() || this.isFragmentStart() || this.isDynamicTagStart()) break;
|
|
153
|
+
value += this.r.advance();
|
|
154
|
+
}
|
|
155
|
+
if (!value) return null;
|
|
156
|
+
return { kind: "Text", value, raw: false, loc: this.r.span(start) };
|
|
157
|
+
}
|
|
158
|
+
parseComment() {
|
|
159
|
+
const start = this.r.pos();
|
|
160
|
+
this.r.advance();
|
|
161
|
+
this.r.advance();
|
|
162
|
+
this.r.advance();
|
|
163
|
+
this.r.advance();
|
|
164
|
+
let value = "";
|
|
165
|
+
while (!this.r.eof() && !this.r.startsWith("-->")) {
|
|
166
|
+
if (this.r.atHole()) {
|
|
167
|
+
this.r.takeHole();
|
|
168
|
+
value += "\0";
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
value += this.r.advance();
|
|
172
|
+
}
|
|
173
|
+
if (this.r.startsWith("-->")) {
|
|
174
|
+
this.r.advance();
|
|
175
|
+
this.r.advance();
|
|
176
|
+
this.r.advance();
|
|
177
|
+
} else {
|
|
178
|
+
this.report("unclosed-comment", "warning", "Unterminated comment", this.r.span(start));
|
|
179
|
+
}
|
|
180
|
+
return { kind: "Comment", value, loc: this.r.span(start) };
|
|
181
|
+
}
|
|
182
|
+
parseFragment() {
|
|
183
|
+
const start = this.r.pos();
|
|
184
|
+
this.r.advance();
|
|
185
|
+
this.r.advance();
|
|
186
|
+
const children = this.parseChildren();
|
|
187
|
+
if (this.r.startsWith("</")) {
|
|
188
|
+
const name = this.consumeCloseTag();
|
|
189
|
+
if (name) this.report("mismatched-close-tag", "error", `Expected </> to close fragment, got </${name}>`, this.r.span(start));
|
|
190
|
+
} else {
|
|
191
|
+
this.report("unclosed-tag", "error", "Unterminated fragment", this.r.span(start));
|
|
192
|
+
}
|
|
193
|
+
return { kind: "Fragment", children, loc: this.r.span(start) };
|
|
194
|
+
}
|
|
195
|
+
parseElement() {
|
|
196
|
+
const start = this.r.pos();
|
|
197
|
+
this.r.advance();
|
|
198
|
+
const tag = this.readName();
|
|
199
|
+
const component = isComponentTag(tag);
|
|
200
|
+
const attributes = this.parseAttributes(component);
|
|
201
|
+
this.foldEachKey(attributes, start);
|
|
202
|
+
this.r.skipWhitespace();
|
|
203
|
+
const lower = tag.toLowerCase();
|
|
204
|
+
const rawText = !component && RAW_TEXT_ELEMENTS.has(lower);
|
|
205
|
+
const isVoid = !component && VOID_ELEMENTS.has(lower);
|
|
206
|
+
let selfClosing = false;
|
|
207
|
+
let children = [];
|
|
208
|
+
if (this.r.startsWith("/>")) {
|
|
209
|
+
this.r.advance();
|
|
210
|
+
this.r.advance();
|
|
211
|
+
selfClosing = true;
|
|
212
|
+
} else {
|
|
213
|
+
if (this.r.peek() === ">") this.r.advance();
|
|
214
|
+
if (!isVoid) {
|
|
215
|
+
this.open.push(tag);
|
|
216
|
+
children = rawText ? this.parseRawText(tag) : this.parseChildren();
|
|
217
|
+
this.open.pop();
|
|
218
|
+
if (this.r.startsWith("</")) {
|
|
219
|
+
const before = this.r.mark();
|
|
220
|
+
const name = this.consumeCloseTag();
|
|
221
|
+
if (name && name !== tag) {
|
|
222
|
+
if (this.open.includes(name)) {
|
|
223
|
+
this.r.reset(before);
|
|
224
|
+
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
225
|
+
} else {
|
|
226
|
+
this.report("mismatched-close-tag", "error", `Expected </${tag}>, got </${name}>`, this.r.span(start));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const loc = this.r.span(start);
|
|
235
|
+
if (component) {
|
|
236
|
+
return { kind: "Component", tag, tagHole: null, attributes, children, selfClosing, loc };
|
|
237
|
+
}
|
|
238
|
+
const namespace = this.svg || SVG_TAGS.has(tag) ? "svg" : "html";
|
|
239
|
+
return { kind: "Element", tag, namespace, attributes, children, selfClosing, rawText, loc };
|
|
240
|
+
}
|
|
241
|
+
/** Read a raw-text element body: only holes break the text run. */
|
|
242
|
+
parseRawText(tag) {
|
|
243
|
+
const out = [];
|
|
244
|
+
const close = "</" + tag.toLowerCase();
|
|
245
|
+
let text = "";
|
|
246
|
+
let start = this.r.pos();
|
|
247
|
+
const flush = () => {
|
|
248
|
+
if (text) out.push({ kind: "Text", value: text, raw: true, loc: this.r.span(start) });
|
|
249
|
+
text = "";
|
|
250
|
+
};
|
|
251
|
+
while (!this.r.eof()) {
|
|
252
|
+
if (this.startsWithCloseFor(close)) break;
|
|
253
|
+
if (this.r.atHole()) {
|
|
254
|
+
flush();
|
|
255
|
+
const h = this.r.takeHole();
|
|
256
|
+
out.push({ kind: "Expression", hole: h.index, loc: h.loc });
|
|
257
|
+
start = this.r.pos();
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (!text) start = this.r.pos();
|
|
261
|
+
text += this.r.advance();
|
|
262
|
+
}
|
|
263
|
+
flush();
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
startsWithCloseFor(close) {
|
|
267
|
+
let i = 0;
|
|
268
|
+
while (i < close.length) {
|
|
269
|
+
const ch = this.r.peek(i);
|
|
270
|
+
if (ch === "" || ch.toLowerCase() !== close[i]) return false;
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
// attributes
|
|
276
|
+
parseAttributes(component) {
|
|
277
|
+
const props = [];
|
|
278
|
+
while (!this.r.eof()) {
|
|
279
|
+
this.r.skipWhitespace();
|
|
280
|
+
if (this.r.peek() === ">" || this.r.startsWith("/>")) break;
|
|
281
|
+
if (this.r.atHole()) {
|
|
282
|
+
const h = this.r.takeHole();
|
|
283
|
+
props.push({ kind: "Spread", hole: h.index, loc: h.loc });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (this.r.startsWith("...")) {
|
|
287
|
+
const s = this.r.pos();
|
|
288
|
+
this.r.advance();
|
|
289
|
+
this.r.advance();
|
|
290
|
+
this.r.advance();
|
|
291
|
+
if (this.r.atHole()) {
|
|
292
|
+
const h = this.r.takeHole();
|
|
293
|
+
props.push({ kind: "Spread", hole: h.index, loc: this.r.span(s) });
|
|
294
|
+
} else {
|
|
295
|
+
this.report("invalid-binding", "error", "Spread `...` must be followed by ${…}", this.r.span(s));
|
|
296
|
+
}
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const nameStart = this.r.pos();
|
|
300
|
+
const name = this.readName();
|
|
301
|
+
if (!name) {
|
|
302
|
+
this.r.advance();
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const nameLoc = this.r.span(nameStart);
|
|
306
|
+
this.r.skipWhitespace();
|
|
307
|
+
let value = null;
|
|
308
|
+
if (this.r.peek() === "=") {
|
|
309
|
+
this.r.advance();
|
|
310
|
+
this.r.skipWhitespace();
|
|
311
|
+
value = this.parseAttrValue();
|
|
312
|
+
}
|
|
313
|
+
const raw = {
|
|
314
|
+
name,
|
|
315
|
+
nameLoc,
|
|
316
|
+
value,
|
|
317
|
+
loc: this.r.span(nameStart),
|
|
318
|
+
report: (code, message) => this.report(code, "error", message, this.r.span(nameStart))
|
|
319
|
+
};
|
|
320
|
+
props.push(resolveAttribute(raw, this.directives, { component }));
|
|
321
|
+
}
|
|
322
|
+
return props;
|
|
323
|
+
}
|
|
324
|
+
parseAttrValue() {
|
|
325
|
+
if (this.r.atHole()) {
|
|
326
|
+
const h = this.r.takeHole();
|
|
327
|
+
return { kind: "hole", hole: h.index };
|
|
328
|
+
}
|
|
329
|
+
const quote = this.r.peek();
|
|
330
|
+
if (quote === '"' || quote === "'") {
|
|
331
|
+
return this.classifyParts(this.readQuotedParts(quote));
|
|
332
|
+
}
|
|
333
|
+
const value = this.r.readWhile((ch) => !/[\s>]/.test(ch));
|
|
334
|
+
return { kind: "static", value };
|
|
335
|
+
}
|
|
336
|
+
readQuotedParts(quote) {
|
|
337
|
+
this.r.advance();
|
|
338
|
+
const parts = [];
|
|
339
|
+
let text = "";
|
|
340
|
+
while (!this.r.eof() && this.r.peek() !== quote) {
|
|
341
|
+
if (this.r.atHole()) {
|
|
342
|
+
if (text) {
|
|
343
|
+
parts.push({ text });
|
|
344
|
+
text = "";
|
|
345
|
+
}
|
|
346
|
+
parts.push({ hole: this.r.takeHole().index });
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const ch = this.r.advance();
|
|
350
|
+
if (ch === "") break;
|
|
351
|
+
text += ch;
|
|
352
|
+
}
|
|
353
|
+
if (text) parts.push({ text });
|
|
354
|
+
if (this.r.peek() === quote) this.r.advance();
|
|
355
|
+
return parts;
|
|
356
|
+
}
|
|
357
|
+
classifyParts(parts) {
|
|
358
|
+
const holes = parts.filter((p) => "hole" in p);
|
|
359
|
+
if (holes.length === 0) {
|
|
360
|
+
return { kind: "static", value: parts.map((p) => "text" in p ? p.text : "").join("") };
|
|
361
|
+
}
|
|
362
|
+
if (parts.length === 1) return { kind: "hole", hole: holes[0].hole };
|
|
363
|
+
return { kind: "mixed", parts };
|
|
364
|
+
}
|
|
365
|
+
/** Fold `key` into `each`, and validate an element's directive combination. */
|
|
366
|
+
foldEachKey(attrs, elLoc) {
|
|
367
|
+
let each = null;
|
|
368
|
+
let ifCount = 0;
|
|
369
|
+
let eachCount = 0;
|
|
370
|
+
let elseCount = 0;
|
|
371
|
+
let refCount = 0;
|
|
372
|
+
for (const a of attrs) {
|
|
373
|
+
if (a.kind === "EachDirective") {
|
|
374
|
+
each = a;
|
|
375
|
+
eachCount++;
|
|
376
|
+
} else if (a.kind === "IfDirective") ifCount++;
|
|
377
|
+
else if (a.kind === "ElseDirective") elseCount++;
|
|
378
|
+
else if (a.kind === "RefBinding") refCount++;
|
|
379
|
+
}
|
|
380
|
+
const span = this.r.span(elLoc);
|
|
381
|
+
if (eachCount > 1) this.report("duplicate-directive", "error", "Multiple `each` directives on one element", span);
|
|
382
|
+
if (ifCount > 1) this.report("duplicate-directive", "error", "Multiple `if` directives on one element", span);
|
|
383
|
+
if (refCount > 1) this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", span);
|
|
384
|
+
if (ifCount > 0 && elseCount > 0) {
|
|
385
|
+
this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", span);
|
|
386
|
+
}
|
|
387
|
+
const keyIdx = attrs.findIndex((a) => a.kind === "Attribute" && a.name === "key");
|
|
388
|
+
if (!each) {
|
|
389
|
+
if (keyIdx !== -1) this.report("invalid-directive", "error", "`key` requires an `each` directive on the same element", span);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (keyIdx === -1) return;
|
|
393
|
+
const key = attrs[keyIdx];
|
|
394
|
+
if (key.kind === "Attribute" && key.value) {
|
|
395
|
+
if (key.value.kind === "static") each.key = { static: key.value.value };
|
|
396
|
+
else if (key.value.kind === "hole") each.key = { hole: key.value.hole };
|
|
397
|
+
}
|
|
398
|
+
attrs.splice(keyIdx, 1);
|
|
399
|
+
}
|
|
400
|
+
// low level
|
|
401
|
+
readName() {
|
|
402
|
+
return this.r.readWhile((ch) => NAME_CHAR.test(ch));
|
|
403
|
+
}
|
|
404
|
+
consumeCloseTag() {
|
|
405
|
+
this.r.advance();
|
|
406
|
+
this.r.advance();
|
|
407
|
+
const name = this.readName();
|
|
408
|
+
this.r.skipWhitespace();
|
|
409
|
+
if (this.r.peek() === ">") this.r.advance();
|
|
410
|
+
return name;
|
|
411
|
+
}
|
|
412
|
+
report(code, severity, message, loc) {
|
|
413
|
+
this.diagnostics.push({ code, severity, message, loc });
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
function parseTemplate(pieces, opts = {}) {
|
|
417
|
+
return new Parser(pieces, opts).parse();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export {
|
|
421
|
+
parseTemplate
|
|
422
|
+
};
|