@hymarkx/compiler 0.0.2
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/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +23 -0
- package/dist/analyze/index.d.ts +75 -0
- package/dist/analyze/index.d.ts.map +1 -0
- package/dist/analyze/index.js +455 -0
- package/dist/analyze/index.js.map +1 -0
- package/dist/components/authored.d.ts +30 -0
- package/dist/components/authored.d.ts.map +1 -0
- package/dist/components/authored.js +293 -0
- package/dist/components/authored.js.map +1 -0
- package/dist/components/builtins.d.ts +6 -0
- package/dist/components/builtins.d.ts.map +1 -0
- package/dist/components/builtins.js +205 -0
- package/dist/components/builtins.js.map +1 -0
- package/dist/components/styles.d.ts +3 -0
- package/dist/components/styles.d.ts.map +1 -0
- package/dist/components/styles.js +99 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/components/types.d.ts +77 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +2 -0
- package/dist/components/types.js.map +1 -0
- package/dist/components/validate.d.ts +14 -0
- package/dist/components/validate.d.ts.map +1 -0
- package/dist/components/validate.js +347 -0
- package/dist/components/validate.js.map +1 -0
- package/dist/diagnostic-origin.d.ts +11 -0
- package/dist/diagnostic-origin.d.ts.map +1 -0
- package/dist/diagnostic-origin.js +12 -0
- package/dist/diagnostic-origin.js.map +1 -0
- package/dist/diagnostics/render.d.ts +13 -0
- package/dist/diagnostics/render.d.ts.map +1 -0
- package/dist/diagnostics/render.js +92 -0
- package/dist/diagnostics/render.js.map +1 -0
- package/dist/emit/backend.d.ts +13 -0
- package/dist/emit/backend.d.ts.map +1 -0
- package/dist/emit/backend.js +2 -0
- package/dist/emit/backend.js.map +1 -0
- package/dist/emit/escape.d.ts +5 -0
- package/dist/emit/escape.d.ts.map +1 -0
- package/dist/emit/escape.js +52 -0
- package/dist/emit/escape.js.map +1 -0
- package/dist/emit/html.d.ts +16 -0
- package/dist/emit/html.d.ts.map +1 -0
- package/dist/emit/html.js +528 -0
- package/dist/emit/html.js.map +1 -0
- package/dist/emit/sanitize.d.ts +19 -0
- package/dist/emit/sanitize.d.ts.map +1 -0
- package/dist/emit/sanitize.js +383 -0
- package/dist/emit/sanitize.js.map +1 -0
- package/dist/events.d.ts +7 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +16 -0
- package/dist/events.js.map +1 -0
- package/dist/expression.d.ts +133 -0
- package/dist/expression.d.ts.map +1 -0
- package/dist/expression.js +1248 -0
- package/dist/expression.js.map +1 -0
- package/dist/frontmatter.d.ts +15 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +196 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/islands.d.ts +23 -0
- package/dist/islands.d.ts.map +1 -0
- package/dist/islands.js +76 -0
- package/dist/islands.js.map +1 -0
- package/dist/runtime.d.ts +14 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +487 -0
- package/dist/runtime.js.map +1 -0
- package/dist/styles.d.ts +33 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +370 -0
- package/dist/styles.js.map +1 -0
- package/dist/suggestions.d.ts +3 -0
- package/dist/suggestions.d.ts.map +1 -0
- package/dist/suggestions.js +29 -0
- package/dist/suggestions.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ContainerDirective, LeafDirective, TextDirective } from '@hymarkx/ast';
|
|
2
|
+
/** Attribute value categories supported by component schemas. */
|
|
3
|
+
export type AttributeType = 'string' | 'number' | 'boolean' | 'enum' | 'url' | 'identifier';
|
|
4
|
+
/** JSON-serializable validation rules for one component attribute. */
|
|
5
|
+
export interface AttributeSchema {
|
|
6
|
+
readonly type: AttributeType;
|
|
7
|
+
/** Required when `type` is `enum`. */
|
|
8
|
+
readonly values?: readonly string[];
|
|
9
|
+
readonly required?: boolean;
|
|
10
|
+
/** Applied when the attribute is absent. Must satisfy this schema. */
|
|
11
|
+
readonly default?: string;
|
|
12
|
+
/** Inclusive lower bound for numbers. */
|
|
13
|
+
readonly min?: number;
|
|
14
|
+
/** Inclusive upper bound for numbers. */
|
|
15
|
+
readonly max?: number;
|
|
16
|
+
/** One sentence used by diagnostics and future editor tooling. */
|
|
17
|
+
readonly description: string;
|
|
18
|
+
}
|
|
19
|
+
/** Directive syntax forms understood by component schemas. */
|
|
20
|
+
export type DirectiveKind = 'container' | 'leaf' | 'text';
|
|
21
|
+
/** Pure-data contract for one registered component. */
|
|
22
|
+
export interface ComponentSchema {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
/** Forms in which the component may be written. */
|
|
25
|
+
readonly kinds: readonly DirectiveKind[];
|
|
26
|
+
readonly attributes: Readonly<Record<string, AttributeSchema>>;
|
|
27
|
+
/** Content accepted between fences or inside a text directive label. */
|
|
28
|
+
readonly children: 'block' | 'phrasing' | 'none';
|
|
29
|
+
readonly label: 'required' | 'optional' | 'forbidden';
|
|
30
|
+
readonly description: string;
|
|
31
|
+
}
|
|
32
|
+
/** A validated component attribute value. */
|
|
33
|
+
export type ResolvedAttribute = string | number | boolean;
|
|
34
|
+
/** Null-prototype, post-validation attributes supplied to renderers. */
|
|
35
|
+
export type ResolvedAttributes = Readonly<Record<string, ResolvedAttribute>>;
|
|
36
|
+
/** One trusted HTML wrapper requested by a component renderer. */
|
|
37
|
+
export interface RenderedElement {
|
|
38
|
+
readonly tag: string;
|
|
39
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
40
|
+
/** Emits an HTML void element without a synthetic closing tag. */
|
|
41
|
+
readonly void?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** One source-attribute reference inside a rendered DOM attribute template. */
|
|
44
|
+
export interface RenderedAttributeReference {
|
|
45
|
+
readonly attribute: string;
|
|
46
|
+
}
|
|
47
|
+
/** Declarative mapping from component attributes to one emitted DOM attribute. */
|
|
48
|
+
export interface RenderedAttributeBinding {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly segments: readonly (string | RenderedAttributeReference)[];
|
|
51
|
+
}
|
|
52
|
+
/** Trusted wrapper structure returned by a component renderer. */
|
|
53
|
+
export interface RenderPlan {
|
|
54
|
+
/** Outermost to innermost. Children are emitted inside the last wrapper. */
|
|
55
|
+
readonly wrappers: readonly RenderedElement[];
|
|
56
|
+
/** Wraps the label before children inside the innermost wrapper. */
|
|
57
|
+
readonly labelWrapper?: RenderedElement;
|
|
58
|
+
/** Templates used to compile reactive source attributes to emitted attributes. */
|
|
59
|
+
readonly attributeBindings?: readonly RenderedAttributeBinding[];
|
|
60
|
+
/** Emits one paragraph child's phrasing content directly inside the innermost wrapper. */
|
|
61
|
+
readonly flattenSingleParagraph?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** A parsed directive node accepted by component renderers. */
|
|
64
|
+
export type DirectiveNode = TextDirective | LeafDirective | ContainerDirective;
|
|
65
|
+
/**
|
|
66
|
+
* Trusted host code that renders already validated attributes.
|
|
67
|
+
*
|
|
68
|
+
* Validation is identical in both trust modes except that `url` attributes use the
|
|
69
|
+
* host-selected mode's URL-scheme policy.
|
|
70
|
+
*/
|
|
71
|
+
export type ComponentRenderer = (node: DirectiveNode, attributes: ResolvedAttributes) => RenderPlan;
|
|
72
|
+
/** Separate schema-data and renderer-code lookups keyed by component name. */
|
|
73
|
+
export interface ComponentRegistry {
|
|
74
|
+
readonly schemas: Readonly<Record<string, ComponentSchema>>;
|
|
75
|
+
readonly renderers: Readonly<Record<string, ComponentRenderer>>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components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8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAA;IAC3D,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAA;CAChE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Attribute, Diagnostic } from '@hymarkx/ast';
|
|
2
|
+
import type { ExpressionEvaluation } from '../expression.js';
|
|
3
|
+
import type { TrustMode } from '../types.js';
|
|
4
|
+
import type { ComponentRenderer, ComponentSchema, DirectiveNode, ResolvedAttributes } from './types.js';
|
|
5
|
+
/** Validated data and trusted renderer associated with one known directive node. */
|
|
6
|
+
export interface AnalyzedComponent {
|
|
7
|
+
readonly schema: ComponentSchema;
|
|
8
|
+
readonly renderer: ComponentRenderer;
|
|
9
|
+
readonly attributes: ResolvedAttributes;
|
|
10
|
+
readonly kindAllowed: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Validates one known directive without exposing raw attribute strings to its renderer. */
|
|
13
|
+
export declare function validateComponent(node: DirectiveNode, schema: ComponentSchema, renderer: ComponentRenderer, trust: TrustMode, expressionValues: ReadonlyMap<Attribute, ExpressionEvaluation>, diagnostics: Diagnostic[], ignoredAttributes?: ReadonlySet<Attribute>): AnalyzedComponent;
|
|
14
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/components/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAQ,MAAM,cAAc,CAAA;AAE/D,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,kBAAkB,CAAA;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAEV,iBAAiB,EACjB,eAAe,EAEf,aAAa,EAEb,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAWnB,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAA;IACvC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC9B;AAgLD,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,SAAS,EAChB,gBAAgB,EAAE,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAC9D,WAAW,EAAE,UAAU,EAAE,EACzB,iBAAiB,GAAE,WAAW,CAAC,SAAS,CAAa,GACpD,iBAAiB,CA4OnB"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { createDiagnostic } from '@hymarkx/ast';
|
|
2
|
+
import { isAllowedDocumentUrl } from '../emit/sanitize.js';
|
|
3
|
+
import { nearestSuggestion } from '../suggestions.js';
|
|
4
|
+
const IDENTIFIER = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
5
|
+
const CLASS_NAMES = /^[A-Za-z0-9_ -]*$/;
|
|
6
|
+
const universalAttributes = {
|
|
7
|
+
id: { type: 'identifier', description: 'A unique HTML identifier.' },
|
|
8
|
+
class: { type: 'string', description: 'Space-separated HTML class names.' },
|
|
9
|
+
title: { type: 'string', description: 'Advisory text for the component.' },
|
|
10
|
+
};
|
|
11
|
+
function suggestion(replacement, span) {
|
|
12
|
+
return replacement === undefined
|
|
13
|
+
? {}
|
|
14
|
+
: {
|
|
15
|
+
suggestion: {
|
|
16
|
+
message: `Replace with "${replacement}".`,
|
|
17
|
+
replacement,
|
|
18
|
+
span,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function kindOf(node) {
|
|
23
|
+
switch (node.type) {
|
|
24
|
+
case 'containerDirective':
|
|
25
|
+
return 'container';
|
|
26
|
+
case 'leafDirective':
|
|
27
|
+
return 'leaf';
|
|
28
|
+
case 'textDirective':
|
|
29
|
+
return 'text';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function labelOf(node) {
|
|
33
|
+
return node.type === 'textDirective' ? node.children : (node.label ?? []);
|
|
34
|
+
}
|
|
35
|
+
function contentOf(node) {
|
|
36
|
+
if (node.type === 'containerDirective' || node.type === 'textDirective') {
|
|
37
|
+
return node.children;
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
function validateValue(value, schema, trust, expression) {
|
|
42
|
+
if (expression) {
|
|
43
|
+
switch (schema.type) {
|
|
44
|
+
case 'string':
|
|
45
|
+
return typeof value === 'string' ? value : undefined;
|
|
46
|
+
case 'number':
|
|
47
|
+
return typeof value === 'number' &&
|
|
48
|
+
Number.isFinite(value) &&
|
|
49
|
+
Number.isInteger(value) &&
|
|
50
|
+
(schema.min === undefined || value >= schema.min) &&
|
|
51
|
+
(schema.max === undefined || value <= schema.max)
|
|
52
|
+
? value
|
|
53
|
+
: undefined;
|
|
54
|
+
case 'boolean':
|
|
55
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
56
|
+
case 'enum':
|
|
57
|
+
return typeof value === 'string' && schema.values?.includes(value) === true
|
|
58
|
+
? value
|
|
59
|
+
: undefined;
|
|
60
|
+
case 'identifier':
|
|
61
|
+
return typeof value === 'string' && IDENTIFIER.test(value) ? value : undefined;
|
|
62
|
+
case 'url':
|
|
63
|
+
return typeof value === 'string' && (trust === 'app' || isAllowedDocumentUrl(value))
|
|
64
|
+
? value
|
|
65
|
+
: undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (value === null) {
|
|
69
|
+
return schema.type === 'boolean' ? true : undefined;
|
|
70
|
+
}
|
|
71
|
+
if (typeof value !== 'string') {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
switch (schema.type) {
|
|
75
|
+
case 'string':
|
|
76
|
+
return value;
|
|
77
|
+
case 'number': {
|
|
78
|
+
const parsed = Number(value);
|
|
79
|
+
return Number.isFinite(parsed) &&
|
|
80
|
+
Number.isInteger(parsed) &&
|
|
81
|
+
(schema.min === undefined || parsed >= schema.min) &&
|
|
82
|
+
(schema.max === undefined || parsed <= schema.max)
|
|
83
|
+
? parsed
|
|
84
|
+
: undefined;
|
|
85
|
+
}
|
|
86
|
+
case 'boolean':
|
|
87
|
+
return value === 'true' ? true : value === 'false' ? false : undefined;
|
|
88
|
+
case 'enum':
|
|
89
|
+
return schema.values?.includes(value) === true ? value : undefined;
|
|
90
|
+
case 'identifier':
|
|
91
|
+
return IDENTIFIER.test(value) ? value : undefined;
|
|
92
|
+
case 'url':
|
|
93
|
+
return trust === 'app' || isAllowedDocumentUrl(value) ? value : undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function shownValue(value, expression) {
|
|
97
|
+
if (!expression) {
|
|
98
|
+
return value === null ? 'bare' : `"${String(value)}"`;
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === 'string') {
|
|
101
|
+
return `"${value}"`;
|
|
102
|
+
}
|
|
103
|
+
if (value === null || typeof value === 'number' || typeof value === 'boolean') {
|
|
104
|
+
return String(value);
|
|
105
|
+
}
|
|
106
|
+
return Array.isArray(value) ? 'an array' : 'an object';
|
|
107
|
+
}
|
|
108
|
+
function invalidValueMessage(name, value, schema, expression) {
|
|
109
|
+
const shown = shownValue(value, expression);
|
|
110
|
+
if (schema.type === 'number') {
|
|
111
|
+
const bounds = [
|
|
112
|
+
...(schema.min === undefined ? [] : [`at least ${schema.min}`]),
|
|
113
|
+
...(schema.max === undefined ? [] : [`at most ${schema.max}`]),
|
|
114
|
+
].join(' and ');
|
|
115
|
+
return `Attribute "${name}" must be a finite integer${bounds === '' ? '' : ` ${bounds}`}; received ${shown}.`;
|
|
116
|
+
}
|
|
117
|
+
if (schema.type === 'boolean') {
|
|
118
|
+
return `Attribute "${name}" must be true, false, or bare; received ${shown}.`;
|
|
119
|
+
}
|
|
120
|
+
if (schema.type === 'identifier') {
|
|
121
|
+
return `Attribute "${name}" must be an identifier beginning with a letter; received ${shown}.`;
|
|
122
|
+
}
|
|
123
|
+
if (schema.type === 'url') {
|
|
124
|
+
return `Attribute "${name}" uses a URL scheme that is not allowed in document mode.`;
|
|
125
|
+
}
|
|
126
|
+
return `Attribute "${name}" must be a ${schema.type} value; received ${shown}.`;
|
|
127
|
+
}
|
|
128
|
+
function attributeInput(attribute, expressions) {
|
|
129
|
+
if (!expressions.has(attribute)) {
|
|
130
|
+
return { value: attribute.value, expression: false };
|
|
131
|
+
}
|
|
132
|
+
const evaluation = expressions.get(attribute);
|
|
133
|
+
return evaluation?.ok === true ? { value: evaluation.value, expression: true } : undefined;
|
|
134
|
+
}
|
|
135
|
+
function validateClass(attribute, input, diagnostics) {
|
|
136
|
+
if (input === undefined) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
if (typeof input.value === 'string' && CLASS_NAMES.test(input.value)) {
|
|
140
|
+
return input.value;
|
|
141
|
+
}
|
|
142
|
+
diagnostics.push(createDiagnostic({
|
|
143
|
+
code: 'HMX2005',
|
|
144
|
+
severity: 'error',
|
|
145
|
+
message: 'Attribute "class" may contain only letters, numbers, spaces, underscores, and hyphens.',
|
|
146
|
+
span: attribute.valueSpan ?? attribute.nameSpan,
|
|
147
|
+
}));
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/** Validates one known directive without exposing raw attribute strings to its renderer. */
|
|
151
|
+
export function validateComponent(node, schema, renderer, trust, expressionValues, diagnostics, ignoredAttributes = new Set()) {
|
|
152
|
+
const resolved = Object.create(null);
|
|
153
|
+
const declaredNames = Object.keys(schema.attributes);
|
|
154
|
+
const knownNames = [...declaredNames, ...Object.keys(universalAttributes)];
|
|
155
|
+
const occurrences = new Map();
|
|
156
|
+
for (const attribute of node.attributes) {
|
|
157
|
+
if (ignoredAttributes.has(attribute)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const attributes = occurrences.get(attribute.name) ?? [];
|
|
161
|
+
attributes.push(attribute);
|
|
162
|
+
occurrences.set(attribute.name, attributes);
|
|
163
|
+
if (!Object.hasOwn(schema.attributes, attribute.name) &&
|
|
164
|
+
!Object.hasOwn(universalAttributes, attribute.name)) {
|
|
165
|
+
const replacement = nearestSuggestion(attribute.name, knownNames);
|
|
166
|
+
diagnostics.push(createDiagnostic({
|
|
167
|
+
code: 'HMX2001',
|
|
168
|
+
severity: 'warning',
|
|
169
|
+
message: `Unknown attribute "${attribute.name}" on component "${schema.name}".`,
|
|
170
|
+
span: attribute.nameSpan,
|
|
171
|
+
...suggestion(replacement, attribute.nameSpan),
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const idAttributes = occurrences.get('id') ?? [];
|
|
176
|
+
for (const duplicate of idAttributes.slice(1)) {
|
|
177
|
+
diagnostics.push(createDiagnostic({
|
|
178
|
+
code: 'HMX2010',
|
|
179
|
+
severity: 'warning',
|
|
180
|
+
message: 'More than one id was supplied; the last value wins.',
|
|
181
|
+
span: duplicate.nameSpan,
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
const classAttributes = occurrences.get('class') ?? [];
|
|
185
|
+
const classes = classAttributes
|
|
186
|
+
.map((attribute) => validateClass(attribute, attributeInput(attribute, expressionValues), diagnostics))
|
|
187
|
+
.filter((value) => value !== undefined);
|
|
188
|
+
if (classes.length > 0) {
|
|
189
|
+
resolved.class = classes.join(' ');
|
|
190
|
+
}
|
|
191
|
+
else if (classAttributes.length === 0) {
|
|
192
|
+
const classSchema = schema.attributes.class;
|
|
193
|
+
if (classSchema?.default !== undefined) {
|
|
194
|
+
const defaultValue = validateValue(classSchema.default, classSchema, trust, false);
|
|
195
|
+
if (typeof defaultValue === 'string' && CLASS_NAMES.test(defaultValue)) {
|
|
196
|
+
resolved.class = defaultValue;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (classSchema?.required === true) {
|
|
200
|
+
diagnostics.push(createDiagnostic({
|
|
201
|
+
code: 'HMX2003',
|
|
202
|
+
severity: 'error',
|
|
203
|
+
message: `Required attribute "class" is missing. ${classSchema.description}`,
|
|
204
|
+
span: node.position,
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const declaredClass = schema.attributes.class;
|
|
209
|
+
if (declaredClass !== undefined && typeof resolved.class === 'string') {
|
|
210
|
+
const value = validateValue(resolved.class, declaredClass, trust, false);
|
|
211
|
+
if (value === undefined) {
|
|
212
|
+
const span = classAttributes.at(-1)?.valueSpan ?? classAttributes.at(-1)?.nameSpan ?? node.position;
|
|
213
|
+
if (declaredClass.type === 'enum') {
|
|
214
|
+
diagnostics.push(createDiagnostic({
|
|
215
|
+
code: 'HMX2004',
|
|
216
|
+
severity: 'error',
|
|
217
|
+
message: `Attribute "class" must be one of: ${(declaredClass.values ?? []).join(', ')}.`,
|
|
218
|
+
span,
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
diagnostics.push(createDiagnostic({
|
|
223
|
+
code: 'HMX2005',
|
|
224
|
+
severity: 'error',
|
|
225
|
+
message: invalidValueMessage('class', resolved.class, declaredClass, false),
|
|
226
|
+
span,
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
delete resolved.class;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const [name, attributeSchema] of Object.entries({
|
|
233
|
+
...universalAttributes,
|
|
234
|
+
...schema.attributes,
|
|
235
|
+
}).filter(([name]) => name !== 'class')) {
|
|
236
|
+
if (attributeSchema === undefined) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const attributes = occurrences.get(name) ?? [];
|
|
240
|
+
if (attributes.length === 0) {
|
|
241
|
+
if (attributeSchema.default !== undefined) {
|
|
242
|
+
const defaultValue = validateValue(attributeSchema.default, attributeSchema, trust, false);
|
|
243
|
+
if (defaultValue !== undefined) {
|
|
244
|
+
resolved[name] = defaultValue;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else if (attributeSchema.required === true) {
|
|
248
|
+
diagnostics.push(createDiagnostic({
|
|
249
|
+
code: 'HMX2003',
|
|
250
|
+
severity: 'error',
|
|
251
|
+
message: `Required attribute "${name}" is missing. ${attributeSchema.description}`,
|
|
252
|
+
span: node.position,
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
for (const [index, attribute] of attributes.entries()) {
|
|
258
|
+
const input = attributeInput(attribute, expressionValues);
|
|
259
|
+
if (input === undefined) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const value = validateValue(input.value, attributeSchema, trust, input.expression);
|
|
263
|
+
if (value === undefined) {
|
|
264
|
+
const span = attribute.valueSpan ?? attribute.nameSpan;
|
|
265
|
+
if (attributeSchema.type === 'enum') {
|
|
266
|
+
const values = attributeSchema.values ?? [];
|
|
267
|
+
const replacement = typeof input.value === 'string' ? nearestSuggestion(input.value, values) : undefined;
|
|
268
|
+
diagnostics.push(createDiagnostic({
|
|
269
|
+
code: 'HMX2004',
|
|
270
|
+
severity: 'error',
|
|
271
|
+
message: `Attribute "${name}" must be one of: ${values.join(', ')}.`,
|
|
272
|
+
span,
|
|
273
|
+
...suggestion(replacement, span),
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
diagnostics.push(createDiagnostic({
|
|
278
|
+
code: 'HMX2005',
|
|
279
|
+
severity: 'error',
|
|
280
|
+
message: invalidValueMessage(name, input.value, attributeSchema, input.expression),
|
|
281
|
+
span,
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else if (index === attributes.length - 1) {
|
|
286
|
+
resolved[name] = value;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
for (const name of ['id', 'title']) {
|
|
291
|
+
const value = resolved[name];
|
|
292
|
+
const universal = universalAttributes[name];
|
|
293
|
+
if (value === undefined ||
|
|
294
|
+
universal === undefined ||
|
|
295
|
+
validateValue(value, universal, trust, true) !== undefined) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const attribute = occurrences.get(name)?.at(-1);
|
|
299
|
+
diagnostics.push(createDiagnostic({
|
|
300
|
+
code: 'HMX2005',
|
|
301
|
+
severity: 'error',
|
|
302
|
+
message: invalidValueMessage(name, value, universal, true),
|
|
303
|
+
span: attribute?.valueSpan ?? attribute?.nameSpan ?? node.position,
|
|
304
|
+
}));
|
|
305
|
+
delete resolved[name];
|
|
306
|
+
}
|
|
307
|
+
const kind = kindOf(node);
|
|
308
|
+
const kindAllowed = schema.kinds.includes(kind);
|
|
309
|
+
if (!kindAllowed) {
|
|
310
|
+
diagnostics.push(createDiagnostic({
|
|
311
|
+
code: 'HMX2008',
|
|
312
|
+
severity: 'error',
|
|
313
|
+
message: `Component "${schema.name}" cannot be written as a ${kind} directive.`,
|
|
314
|
+
span: node.position,
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
const content = contentOf(node);
|
|
318
|
+
if ((schema.children === 'none' && content.length > 0) ||
|
|
319
|
+
(schema.children === 'phrasing' && node.type === 'containerDirective' && content.length > 0)) {
|
|
320
|
+
diagnostics.push(createDiagnostic({
|
|
321
|
+
code: 'HMX2006',
|
|
322
|
+
severity: 'warning',
|
|
323
|
+
message: `Component "${schema.name}" does not permit this content.`,
|
|
324
|
+
span: content[0]?.position ?? node.position,
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
const label = labelOf(node);
|
|
328
|
+
const hasLabel = label.length > 0;
|
|
329
|
+
if ((schema.label === 'required' && !hasLabel) || (schema.label === 'forbidden' && hasLabel)) {
|
|
330
|
+
diagnostics.push(createDiagnostic({
|
|
331
|
+
code: 'HMX2007',
|
|
332
|
+
severity: 'error',
|
|
333
|
+
message: schema.label === 'required'
|
|
334
|
+
? `Component "${schema.name}" requires a label.`
|
|
335
|
+
: `Component "${schema.name}" does not permit a label.`,
|
|
336
|
+
span: hasLabel &&
|
|
337
|
+
label[0] !== undefined &&
|
|
338
|
+
typeof label[0] === 'object' &&
|
|
339
|
+
label[0] !== null &&
|
|
340
|
+
'position' in label[0]
|
|
341
|
+
? label[0].position
|
|
342
|
+
: node.position,
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
return { schema, renderer, attributes: resolved, kindAllowed };
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/components/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAYrD,MAAM,UAAU,GAAG,0BAA0B,CAAA;AAC7C,MAAM,WAAW,GAAG,mBAAmB,CAAA;AAEvC,MAAM,mBAAmB,GAA8C;IACrE,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE;IACpE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mCAAmC,EAAE;IAC3E,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kCAAkC,EAAE;CAC3E,CAAA;AAUD,SAAS,UAAU,CAAC,WAA+B,EAAE,IAAU;IAC7D,OAAO,WAAW,KAAK,SAAS;QAC9B,CAAC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AC,KAAK,QAAQ;gBAC5B,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI;gBACjB,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC;gBACpB,CAAC,CAAE,KAAK,CAAC,CAAC,CAAiC,CAAC,QAAQ;gBACpD,CAAC,CAAC,IAAI,CAAC,QAAQ;SACpB,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Diagnostic } from '@hymarkx/ast';
|
|
2
|
+
/** Source text and optional path associated with a compiler diagnostic. */
|
|
3
|
+
export interface DiagnosticOrigin {
|
|
4
|
+
readonly source: string;
|
|
5
|
+
readonly from?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Associates a diagnostic with its originating source unless it already has an origin. */
|
|
8
|
+
export declare function setDiagnosticOrigin(diagnostic: Diagnostic, source: string, from: string | undefined): void;
|
|
9
|
+
/** Returns the source that produced a diagnostic when the compiler knows it. */
|
|
10
|
+
export declare function diagnosticOrigin(diagnostic: Diagnostic): DiagnosticOrigin | undefined;
|
|
11
|
+
//# sourceMappingURL=diagnostic-origin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic-origin.d.ts","sourceRoot":"","sources":["../src/diagnostic-origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAID,2FAA2F;AAC3F,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CAIN;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAErF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const origins = new WeakMap();
|
|
2
|
+
/** Associates a diagnostic with its originating source unless it already has an origin. */
|
|
3
|
+
export function setDiagnosticOrigin(diagnostic, source, from) {
|
|
4
|
+
if (!origins.has(diagnostic)) {
|
|
5
|
+
origins.set(diagnostic, { source, ...(from === undefined ? {} : { from }) });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Returns the source that produced a diagnostic when the compiler knows it. */
|
|
9
|
+
export function diagnosticOrigin(diagnostic) {
|
|
10
|
+
return origins.get(diagnostic);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=diagnostic-origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic-origin.js","sourceRoot":"","sources":["../src/diagnostic-origin.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,GAAG,IAAI,OAAO,EAAgC,CAAA;AAE3D,2FAA2F;AAC3F,MAAM,UAAU,mBAAmB,CACjC,UAAsB,EACtB,MAAc,EACd,IAAwB;IAExB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IAC9E,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAAC,UAAsB;IACrD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Diagnostic } from '@hymarkx/ast';
|
|
2
|
+
/** Options controlling human-readable diagnostic rendering. */
|
|
3
|
+
export interface RenderDiagnosticOptions {
|
|
4
|
+
/** Enables ANSI colors. Default: `false`. */
|
|
5
|
+
readonly color?: boolean;
|
|
6
|
+
/** File name displayed in source-frame headers. Default: `'<anonymous>'`. */
|
|
7
|
+
readonly from?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Renders one diagnostic with source excerpts and optional ANSI color. */
|
|
10
|
+
export declare function renderDiagnostic(diagnostic: Diagnostic, source: string, options?: RenderDiagnosticOptions): string;
|
|
11
|
+
/** Renders diagnostics in input order separated by a blank line. */
|
|
12
|
+
export declare function renderDiagnostics(diagnostics: readonly Diagnostic[], source: string, options?: RenderDiagnosticOptions): string;
|
|
13
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/diagnostics/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAQ,MAAM,cAAc,CAAA;AAEpD,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AA2FD,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,uBAA4B,GACpC,MAAM,CA8BR;AAED,oEAAoE;AACpE,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAER"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const ANSI_RESET = '\u001b[0m';
|
|
2
|
+
const ANSI_BOLD = '\u001b[1m';
|
|
3
|
+
const ANSI_RED = '\u001b[31m';
|
|
4
|
+
const ANSI_YELLOW = '\u001b[33m';
|
|
5
|
+
const ANSI_CYAN = '\u001b[36m';
|
|
6
|
+
function paint(value, code, enabled) {
|
|
7
|
+
return enabled ? `${code}${value}${ANSI_RESET}` : value;
|
|
8
|
+
}
|
|
9
|
+
function severityColor(severity) {
|
|
10
|
+
switch (severity) {
|
|
11
|
+
case 'error':
|
|
12
|
+
return ANSI_RED;
|
|
13
|
+
case 'warning':
|
|
14
|
+
return ANSI_YELLOW;
|
|
15
|
+
case 'info':
|
|
16
|
+
return ANSI_CYAN;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function expandTabs(value) {
|
|
20
|
+
let output = '';
|
|
21
|
+
for (const character of value) {
|
|
22
|
+
if (character === '\t') {
|
|
23
|
+
const spaces = 4 - (output.length % 4);
|
|
24
|
+
output += ' '.repeat(spaces);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
output += character;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
function visualColumn(line, sourceColumn) {
|
|
33
|
+
return expandTabs(line.slice(0, Math.max(0, sourceColumn - 1))).length + 1;
|
|
34
|
+
}
|
|
35
|
+
function normalizedLine(value) {
|
|
36
|
+
return Number.isInteger(value) && value > 0 ? value : 1;
|
|
37
|
+
}
|
|
38
|
+
function normalizedColumn(value) {
|
|
39
|
+
return Number.isInteger(value) && value > 0 ? value : 1;
|
|
40
|
+
}
|
|
41
|
+
function sourceFrame(span, source, from, annotation, color, markerColor) {
|
|
42
|
+
const lines = source.split('\n');
|
|
43
|
+
const startLine = normalizedLine(span.start.line);
|
|
44
|
+
const requestedEnd = Math.max(startLine, normalizedLine(span.end.line));
|
|
45
|
+
const maximumSourceLine = Math.max(1, lines.length);
|
|
46
|
+
const endLine = startLine > maximumSourceLine ? startLine : Math.min(requestedEnd, maximumSourceLine);
|
|
47
|
+
const gutterWidth = String(endLine).length;
|
|
48
|
+
const output = [` ┌─ ${from}:${startLine}:${normalizedColumn(span.start.column)}`, ' │'];
|
|
49
|
+
for (let lineNumber = startLine; lineNumber <= endLine; lineNumber += 1) {
|
|
50
|
+
const rawLine = lines[lineNumber - 1] ?? '';
|
|
51
|
+
const expandedLine = expandTabs(rawLine);
|
|
52
|
+
const firstColumn = lineNumber === startLine ? normalizedColumn(span.start.column) : 1;
|
|
53
|
+
const visualStart = visualColumn(rawLine, firstColumn);
|
|
54
|
+
const sourceEnd = lineNumber === requestedEnd ? normalizedColumn(span.end.column) : rawLine.length + 1;
|
|
55
|
+
const visualEnd = visualColumn(rawLine, sourceEnd);
|
|
56
|
+
const markerLength = Math.max(1, visualEnd - visualStart);
|
|
57
|
+
const marker = lineNumber === startLine ? '^' : '~';
|
|
58
|
+
const suffix = lineNumber === startLine && annotation.length > 0 ? ` ${annotation}` : '';
|
|
59
|
+
output.push(`${String(lineNumber).padStart(gutterWidth)} │ ${expandedLine}`);
|
|
60
|
+
output.push(`${' '.repeat(gutterWidth)} │ ${' '.repeat(visualStart - 1)}${paint(marker.repeat(markerLength), markerColor, color)}${suffix}`);
|
|
61
|
+
}
|
|
62
|
+
output.push(' │');
|
|
63
|
+
return output.join('\n');
|
|
64
|
+
}
|
|
65
|
+
/** Renders one diagnostic with source excerpts and optional ANSI color. */
|
|
66
|
+
export function renderDiagnostic(diagnostic, source, options = {}) {
|
|
67
|
+
const color = options.color === true;
|
|
68
|
+
const from = options.from ?? '<anonymous>';
|
|
69
|
+
const severity = paint(diagnostic.severity, severityColor(diagnostic.severity), color);
|
|
70
|
+
const code = paint(`[${diagnostic.code}]`, ANSI_BOLD, color);
|
|
71
|
+
const annotation = diagnostic.expected === undefined ? '' : `expected ${diagnostic.expected}`;
|
|
72
|
+
const output = [
|
|
73
|
+
`${severity}${code}: ${diagnostic.message}`,
|
|
74
|
+
sourceFrame(diagnostic.span, source, from, annotation, color, severityColor(diagnostic.severity)),
|
|
75
|
+
];
|
|
76
|
+
for (const related of diagnostic.related ?? []) {
|
|
77
|
+
output.push(`note: ${related.message}`);
|
|
78
|
+
output.push(sourceFrame(related.span, source, from, '', color, ANSI_CYAN));
|
|
79
|
+
}
|
|
80
|
+
if (diagnostic.suggestion !== undefined) {
|
|
81
|
+
output.push(`help: ${diagnostic.suggestion.replacement}`);
|
|
82
|
+
}
|
|
83
|
+
if (diagnostic.url !== undefined) {
|
|
84
|
+
output.push(`docs: ${diagnostic.url}`);
|
|
85
|
+
}
|
|
86
|
+
return output.join('\n');
|
|
87
|
+
}
|
|
88
|
+
/** Renders diagnostics in input order separated by a blank line. */
|
|
89
|
+
export function renderDiagnostics(diagnostics, source, options = {}) {
|
|
90
|
+
return diagnostics.map((diagnostic) => renderDiagnostic(diagnostic, source, options)).join('\n\n');
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/diagnostics/render.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,GAAG,WAAW,CAAA;AAC9B,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,QAAQ,GAAG,YAAY,CAAA;AAC7B,MAAM,WAAW,GAAG,YAAY,CAAA;AAChC,MAAM,SAAS,GAAG,YAAY,CAAA;AAE9B,SAAS,KAAK,CAAC,KAAa,EAAE,IAAY,EAAE,OAAgB;IAC1D,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;AACzD,CAAC;AAED,SAAS,aAAa,CAAC,QAAgC;IACrD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,QAAQ,CAAA;QACjB,KAAK,SAAS;YACZ,OAAO,WAAW,CAAA;QACpB,KAAK,MAAM;YACT,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,MAAM,GAAG,EAA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