@chikx/compiler 0.1.0 → 0.1.1
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/README.md +5 -5
- package/package.json +3 -3
- package/src/emitter/index.ts +658 -0
- package/src/formatter/index.ts +544 -0
- package/src/host/node.ts +85 -0
- package/src/index.ts +1021 -0
- package/src/ir/factories.ts +85 -0
- package/src/ir/index.ts +28 -0
- package/src/ir/types.ts +145 -0
- package/src/lexer/at-keywords.ts +35 -0
- package/src/lexer/characters.ts +82 -0
- package/src/lexer/comments.ts +27 -0
- package/src/lexer/diagnostics.ts +42 -0
- package/src/lexer/dollar-refs.ts +23 -0
- package/src/lexer/index.ts +37 -0
- package/src/lexer/names.ts +49 -0
- package/src/lexer/numbers.ts +59 -0
- package/src/lexer/scanner.ts +199 -0
- package/src/lexer/strings.ts +52 -0
- package/src/lexer/urls.ts +63 -0
- package/src/lowering/expand-groups.ts +206 -0
- package/src/lowering/group.ts +119 -0
- package/src/lowering/index.ts +43 -0
- package/src/lowering/lower.ts +441 -0
- package/src/lowering/media.ts +314 -0
- package/src/lowering/merge.ts +163 -0
- package/src/lowering/property-families.ts +194 -0
- package/src/lowering/spans.ts +118 -0
- package/src/naming/index.ts +44 -0
- package/src/naming/mapgen.ts +252 -0
- package/src/naming/merge.ts +114 -0
- package/src/naming/rewrite.ts +333 -0
- package/src/naming/scan.ts +267 -0
- package/src/naming/table.ts +153 -0
- package/src/naming/types.ts +100 -0
- package/src/output/import-path.ts +30 -0
- package/src/output/index.ts +213 -0
- package/src/output/manifest.ts +28 -0
- package/src/output/paths.ts +200 -0
- package/src/output/resolve.ts +401 -0
- package/src/output/validate.ts +251 -0
- package/src/parser/cursor.ts +138 -0
- package/src/parser/declaration.ts +247 -0
- package/src/parser/diagnostics.ts +75 -0
- package/src/parser/group.ts +303 -0
- package/src/parser/index.ts +50 -0
- package/src/parser/modifier.ts +60 -0
- package/src/parser/recovery.ts +88 -0
- package/src/parser/rule.ts +370 -0
- package/src/parser/statement.ts +47 -0
- package/src/parser/statements.ts +667 -0
- package/src/parser/value.ts +265 -0
- package/src/resolver/graph.ts +467 -0
- package/src/resolver/groups.ts +177 -0
- package/src/resolver/index.ts +68 -0
- package/src/resolver/keyframes.ts +131 -0
- package/src/resolver/paths.ts +142 -0
- package/src/resolver/rules.ts +54 -0
- package/src/resolver/scopes.ts +342 -0
- package/src/resolver/types.ts +259 -0
- package/src/selectors/flatten.ts +448 -0
- package/src/selectors/index.ts +14 -0
- package/src/selectors/scan.ts +227 -0
- package/src/selectors/specificity.ts +319 -0
- package/src/setup-list.ts +172 -0
- package/src/sourcemaps/index.ts +25 -0
- package/src/sourcemaps/mappings.ts +190 -0
- package/src/sourcemaps/vlq.ts +29 -0
- package/src/types/ast.ts +318 -0
- package/src/types/diagnostics.ts +124 -0
- package/src/types/options.ts +286 -0
- package/src/types/result.ts +121 -0
- package/src/types/span.ts +18 -0
- package/src/types/token.ts +77 -0
- package/src/variables/ast.ts +182 -0
- package/src/variables/expand.ts +319 -0
- package/src/variables/index.ts +38 -0
- package/src/variables/naming.ts +46 -0
- package/src/variables/runtime.ts +336 -0
- package/src/variables/substitute.ts +148 -0
- package/src/variables/walk.ts +147 -0
- package/dist/output/importPath.d.ts +0 -27
- package/dist/output/importPath.d.ts.map +0 -1
- package/dist/output/importPath.js +0 -84
- package/dist/output/importPath.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 VLQ encoding for source-map v3 `mappings` (zero dependencies).
|
|
3
|
+
*
|
|
4
|
+
* Source maps encode every number as a signed variable-length quantity in
|
|
5
|
+
* base64 digits: the low bit of the first digit is the sign, the remaining bits
|
|
6
|
+
* are the magnitude in five-bit groups, and the continuation bit (`0x20`) marks
|
|
7
|
+
* every group but the last. All values here are integers within JavaScript's
|
|
8
|
+
* safe range, which is far beyond the line/column deltas a stylesheet produces.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Standard source-map base64 alphabet (`A`=0 … `9`=61, `+`=62, `/`=63). */
|
|
12
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13
|
+
|
|
14
|
+
/** Encode one signed integer as a base64 VLQ segment value. */
|
|
15
|
+
export function encodeVlq(value: number): string {
|
|
16
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
17
|
+
throw new RangeError(`VLQ values must be finite integers, received ${String(value)}.`);
|
|
18
|
+
}
|
|
19
|
+
// Negative numbers use the low bit as the sign and the magnitude shifted left.
|
|
20
|
+
let remaining = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
21
|
+
let encoded = "";
|
|
22
|
+
do {
|
|
23
|
+
let digit = remaining & 0x1f;
|
|
24
|
+
remaining >>>= 5;
|
|
25
|
+
if (remaining > 0) digit |= 0x20;
|
|
26
|
+
encoded += BASE64.charAt(digit);
|
|
27
|
+
} while (remaining > 0);
|
|
28
|
+
return encoded;
|
|
29
|
+
}
|
package/src/types/ast.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { Span } from "./span.js";
|
|
2
|
+
import type { Token } from "./token.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Abstract syntax tree produced by `parse`.
|
|
6
|
+
*
|
|
7
|
+
* Node shapes mirror SPECIFICATION.md §3.2, refined by
|
|
8
|
+
* ADR-0003 (per-segment `!important`), ADR-0004 (rule-scoped conditional
|
|
9
|
+
* blocks), ADR-0005 (raw value slices plus optional token sequences) and
|
|
10
|
+
* ADR-0017 (inert `@group.<name>` definitions and use sites).
|
|
11
|
+
*
|
|
12
|
+
* Every node is immutable and carries a {@link Span} into the original source,
|
|
13
|
+
* so diagnostics, lowering and source maps keep exact origins. Value-bearing
|
|
14
|
+
* strings are raw source slices exactly as authored: no whitespace trimming,
|
|
15
|
+
* escape decoding or normalization happens here. Lowering produces new IR
|
|
16
|
+
* nodes instead of editing the AST in place.
|
|
17
|
+
*
|
|
18
|
+
* Two structural notes:
|
|
19
|
+
*
|
|
20
|
+
* - A top-level conditional block is invalid (ADR-0004). It is never
|
|
21
|
+
* represented as a node: the parser reports a CHIKX1001-family diagnostic and
|
|
22
|
+
* resumes at the next statement boundary, so {@link Stylesheet.items} only
|
|
23
|
+
* holds valid top-level constructs.
|
|
24
|
+
* - Multiple `@setup` blocks are allowed at the top level and are parsed into
|
|
25
|
+
* multiple {@link SetupBlock} nodes so recovery and diagnostics stay local;
|
|
26
|
+
* the resolver merges them in document order. A duplicate setting key within
|
|
27
|
+
* or across blocks is a CHIKX1001-family diagnostic.
|
|
28
|
+
*/
|
|
29
|
+
export interface Stylesheet {
|
|
30
|
+
readonly kind: "stylesheet";
|
|
31
|
+
/** Workspace-relative POSIX path of the parsed source, equal to `span.file`. */
|
|
32
|
+
readonly file: string;
|
|
33
|
+
/** Top-level constructs in authored order. */
|
|
34
|
+
readonly items: readonly StylesheetItem[];
|
|
35
|
+
/** Covers the whole source file, from offset 0 through the final character. */
|
|
36
|
+
readonly span: Span;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Any construct that may appear at the top level of a file. */
|
|
40
|
+
export type StylesheetItem =
|
|
41
|
+
| SetupBlock
|
|
42
|
+
| UseImport
|
|
43
|
+
| VariablesBlock
|
|
44
|
+
| RuntimeBlock
|
|
45
|
+
| MediaTypesBlock
|
|
46
|
+
| GroupDefinition
|
|
47
|
+
| Rule
|
|
48
|
+
| NativeAtRule;
|
|
49
|
+
|
|
50
|
+
/** A `@setup { ... }` block; one node per authored block. */
|
|
51
|
+
export interface SetupBlock {
|
|
52
|
+
readonly kind: "setup";
|
|
53
|
+
/** Settings in authored order, duplicates preserved for diagnostics. */
|
|
54
|
+
readonly settings: readonly Setting[];
|
|
55
|
+
/** Covers `@setup` through the closing `}`. */
|
|
56
|
+
readonly span: Span;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* One `key: value;` line inside `@setup`.
|
|
61
|
+
*
|
|
62
|
+
* Keys are the kebab-case setup keys of SPECIFICATION.md §9 (`css-dir`,
|
|
63
|
+
* `emit-css`, ...). Values stay raw so the configuration layer owns decoding
|
|
64
|
+
* and validation.
|
|
65
|
+
*/
|
|
66
|
+
export interface Setting {
|
|
67
|
+
readonly kind: "setting";
|
|
68
|
+
/** Kebab-case setup key exactly as authored (for example `css-dir`). */
|
|
69
|
+
readonly key: string;
|
|
70
|
+
/**
|
|
71
|
+
* Raw scalar slice exactly as authored, including quotes for strings
|
|
72
|
+
* (`"ui"`, `true`, `12`). Decoders remove quotes and resolve escapes.
|
|
73
|
+
*/
|
|
74
|
+
readonly value: string;
|
|
75
|
+
/**
|
|
76
|
+
* Covers the raw {@link value} slice only, excluding the key, colon and
|
|
77
|
+
* terminator. List decoders use it to report per-item spans; it is zero-width
|
|
78
|
+
* when the authored value is empty.
|
|
79
|
+
*/
|
|
80
|
+
readonly valueSpan: Span;
|
|
81
|
+
/** Covers the key through the terminating `;`. */
|
|
82
|
+
readonly span: Span;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A top-level `@use "..." [as alias] [styles];` import.
|
|
87
|
+
*
|
|
88
|
+
* Without the `styles` clause the import brings in tokens only
|
|
89
|
+
* (SPECIFICATION.md §6.1). With it, the target's stylesheet rules are merged
|
|
90
|
+
* into the importing build as well (ADR-0014); merged rules keep the imported
|
|
91
|
+
* module's own `@setup` prefix and are emitted before the importing file's own
|
|
92
|
+
* rules.
|
|
93
|
+
*/
|
|
94
|
+
export interface UseImport {
|
|
95
|
+
readonly kind: "use";
|
|
96
|
+
/**
|
|
97
|
+
* Raw text between the quotes of the specifier, exactly as authored. CSS
|
|
98
|
+
* string escapes are not decoded here; the resolver decodes them and resolves
|
|
99
|
+
* relative to the importing file.
|
|
100
|
+
*/
|
|
101
|
+
readonly path: string;
|
|
102
|
+
/** Explicit namespace from an `as` clause, exactly as authored; `undefined` when absent. */
|
|
103
|
+
readonly alias?: string;
|
|
104
|
+
/**
|
|
105
|
+
* `true` when the authored statement carries the `styles` clause, merging the
|
|
106
|
+
* target's rules into this build (ADR-0014). Absent means a token-only import,
|
|
107
|
+
* which emits no rules of its own (SPECIFICATION.md §6.1).
|
|
108
|
+
*/
|
|
109
|
+
readonly styles?: boolean;
|
|
110
|
+
/** Covers `@use` through the terminating `;`. */
|
|
111
|
+
readonly span: Span;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A `@variables { ... }` block holding compile-time token definitions. */
|
|
115
|
+
export interface VariablesBlock {
|
|
116
|
+
readonly kind: "variables";
|
|
117
|
+
/** Token declarations in authored order; duplicates are preserved for diagnostics. */
|
|
118
|
+
readonly tokens: readonly TokenDeclaration[];
|
|
119
|
+
/** Covers `@variables` through the closing `}`. */
|
|
120
|
+
readonly span: Span;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** One compile-time variable definition inside `@variables`. */
|
|
124
|
+
export interface TokenDeclaration {
|
|
125
|
+
readonly kind: "token-declaration";
|
|
126
|
+
/** Local variable name without the `$` sigil, exactly as authored. */
|
|
127
|
+
readonly name: string;
|
|
128
|
+
/**
|
|
129
|
+
* Raw value slice exactly as authored; compile-time variables substitute
|
|
130
|
+
* token sequences, not expressions.
|
|
131
|
+
*/
|
|
132
|
+
readonly value: string;
|
|
133
|
+
/**
|
|
134
|
+
* Parsed value tokens, present only when {@link value} contains a `$`
|
|
135
|
+
* reference (ADR-0005). Literal content stays in `value` as well.
|
|
136
|
+
*/
|
|
137
|
+
readonly tokens?: readonly Token[];
|
|
138
|
+
/** Covers the name through the terminating `;`. */
|
|
139
|
+
readonly span: Span;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A `@runtime { ... }` block whose declarations emit native custom properties. */
|
|
143
|
+
export interface RuntimeBlock {
|
|
144
|
+
readonly kind: "runtime";
|
|
145
|
+
/** Declarations in authored order, including inline variant segments. */
|
|
146
|
+
readonly declarations: readonly Declaration[];
|
|
147
|
+
/** Covers `@runtime` through the closing `}`. */
|
|
148
|
+
readonly span: Span;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A `@media-types { ... }` block of file-local media alias definitions. */
|
|
152
|
+
export interface MediaTypesBlock {
|
|
153
|
+
readonly kind: "media-types";
|
|
154
|
+
/** Alias definitions in authored order; later keys win at merge time. */
|
|
155
|
+
readonly aliases: readonly AliasDeclaration[];
|
|
156
|
+
/** Covers `@media-types` through the closing `}`. */
|
|
157
|
+
readonly span: Span;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** One `alias: condition;` definition inside `@media-types`. */
|
|
161
|
+
export interface AliasDeclaration {
|
|
162
|
+
readonly kind: "alias-declaration";
|
|
163
|
+
/** Alias name without the `@` sigil; may begin with a digit (`2xl`). */
|
|
164
|
+
readonly name: string;
|
|
165
|
+
/** Raw media condition text as authored, trimmed of surrounding whitespace. */
|
|
166
|
+
readonly media: string;
|
|
167
|
+
/** Covers the name through the terminating `;`. */
|
|
168
|
+
readonly span: Span;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* A top-level `@group.<name> { ... }` reusable declaration group (ADR-0017).
|
|
173
|
+
*
|
|
174
|
+
* A definition is inert: it emits no CSS and only a matching
|
|
175
|
+
* {@link GroupUseSite} splices its declarations into a rule. The block accepts
|
|
176
|
+
* declarations and nothing else; a nested rule, conditional block, native
|
|
177
|
+
* at-rule or further `@group.` statement inside it is a CHIKX1001-family
|
|
178
|
+
* diagnostic and that statement is omitted while the rest of the definition
|
|
179
|
+
* survives. Names are plain CSS identifiers matched exactly and
|
|
180
|
+
* case-sensitively, and the dotted form is contiguous only.
|
|
181
|
+
*
|
|
182
|
+
* An empty or unused definition is legal and produces no diagnostic. Duplicate
|
|
183
|
+
* definitions in one module stay in the AST as separate nodes; the resolver
|
|
184
|
+
* reports the later one as CHIKX2001 (plan G2).
|
|
185
|
+
*/
|
|
186
|
+
export interface GroupDefinition {
|
|
187
|
+
readonly kind: "group-definition";
|
|
188
|
+
/** Group name without the `@group.` prefix, exactly as authored (`card`, `keyframes`). */
|
|
189
|
+
readonly name: string;
|
|
190
|
+
/** Declarations in authored order, including inline variant segments. */
|
|
191
|
+
readonly declarations: readonly Declaration[];
|
|
192
|
+
/** Covers `@group` through the closing `}`. */
|
|
193
|
+
readonly span: Span;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A selector block: the only place declarations, nested rules and conditional blocks live. */
|
|
197
|
+
export interface Rule {
|
|
198
|
+
readonly kind: "rule";
|
|
199
|
+
/** Raw selector list exactly as authored, including functional pseudos and escapes. */
|
|
200
|
+
readonly selector: string;
|
|
201
|
+
/** Covers only the selector text, so diagnostics can point at selectors precisely. */
|
|
202
|
+
readonly selectorSpan: Span;
|
|
203
|
+
/** Declarations, nested rules, conditional blocks and native at-rules in authored order. */
|
|
204
|
+
readonly body: readonly BlockItem[];
|
|
205
|
+
/** Covers the selector through the closing `}`, including the block. */
|
|
206
|
+
readonly span: Span;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Any construct that may appear inside a rule block or a native at-rule block. */
|
|
210
|
+
export type BlockItem = Declaration | Rule | ConditionalBlock | NativeAtRule | GroupUseSite;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A `@group.<name> { ... }` use site inside a rule body (ADR-0017).
|
|
214
|
+
*
|
|
215
|
+
* The block is required in v0.1 and holds per-use-site overrides only;
|
|
216
|
+
* expansion splices the group's defaults before these declarations at the
|
|
217
|
+
* authored position (plan G3). A definition is the same syntax at the top level
|
|
218
|
+
* of a file. Inside this block declarations are the only valid statement: a
|
|
219
|
+
* nested rule, conditional block or native at-rule is a CHIKX1001-family
|
|
220
|
+
* diagnostic and only that statement is omitted. Conditional use sites such as
|
|
221
|
+
* `@group.x @md { ... }` are out of v1.
|
|
222
|
+
*/
|
|
223
|
+
export interface GroupUseSite {
|
|
224
|
+
readonly kind: "group-use-site";
|
|
225
|
+
/** Group name without the `@group.` prefix, exactly as authored and case-sensitive. */
|
|
226
|
+
readonly name: string;
|
|
227
|
+
/** Override declarations in authored order, including inline variant segments. */
|
|
228
|
+
readonly declarations: readonly Declaration[];
|
|
229
|
+
/** Covers `@group` through the closing `}`. */
|
|
230
|
+
readonly span: Span;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A rule-scoped `@md { ... }` conditional block (ADR-0004).
|
|
235
|
+
*
|
|
236
|
+
* A native at-rule inside a conditional block is invalid per the §3.2 grammar
|
|
237
|
+
* and is reported as a CHIKX1001-family diagnostic with statement-boundary
|
|
238
|
+
* recovery.
|
|
239
|
+
*/
|
|
240
|
+
export interface ConditionalBlock {
|
|
241
|
+
readonly kind: "conditional-block";
|
|
242
|
+
/** Parsed modifier combination applied to every member of the block. */
|
|
243
|
+
readonly variant: Modifier;
|
|
244
|
+
/** Conditional blocks contain declarations, nested rules and further conditional blocks only. */
|
|
245
|
+
readonly body: readonly ConditionalBlockItem[];
|
|
246
|
+
/** Covers the modifier through the closing `}`. */
|
|
247
|
+
readonly span: Span;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Members allowed inside a conditional block by the §3.2 grammar. */
|
|
251
|
+
export type ConditionalBlockItem = Declaration | Rule | ConditionalBlock;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A property declaration with an optional inline-variant chain.
|
|
255
|
+
*
|
|
256
|
+
* `!important` binds per value segment (ADR-0003): it stays ordinary CSS token
|
|
257
|
+
* content of the segment it terminates and is never propagated to other
|
|
258
|
+
* segments.
|
|
259
|
+
*/
|
|
260
|
+
export interface Declaration {
|
|
261
|
+
readonly kind: "declaration";
|
|
262
|
+
/** Property name exactly as authored, including custom properties (`--brand`). */
|
|
263
|
+
readonly property: string;
|
|
264
|
+
/** Raw base-value slice, including a trailing `!important` when present. */
|
|
265
|
+
readonly value: string;
|
|
266
|
+
/**
|
|
267
|
+
* Parsed base-value tokens, present only when {@link value} contains a `$`
|
|
268
|
+
* reference (ADR-0005).
|
|
269
|
+
*/
|
|
270
|
+
readonly tokens?: readonly Token[];
|
|
271
|
+
/** Inline variants in authored order; empty when the declaration has none. */
|
|
272
|
+
readonly variants: readonly Variant[];
|
|
273
|
+
/**
|
|
274
|
+
* Whether the base value segment carries `!important`. Never implies that any
|
|
275
|
+
* variant is important.
|
|
276
|
+
*/
|
|
277
|
+
readonly important?: boolean;
|
|
278
|
+
/** Covers the property through the last value character; the terminating `;` is excluded. */
|
|
279
|
+
readonly span: Span;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** A parsed Chikx condition: one or more aliases joined by `+` (logical AND). */
|
|
283
|
+
export interface Modifier {
|
|
284
|
+
/** Alias names in authored order, without `@`; duplicates are preserved until lowering normalizes them. */
|
|
285
|
+
readonly aliases: readonly string[];
|
|
286
|
+
/** Covers the modifier text including `@` and `+` joins. */
|
|
287
|
+
readonly span: Span;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** One inline variant segment: its condition, value and per-segment importance. */
|
|
291
|
+
export interface Variant extends Modifier {
|
|
292
|
+
/** Raw value slice for this segment, including a trailing `!important` when present. */
|
|
293
|
+
readonly value: string;
|
|
294
|
+
/**
|
|
295
|
+
* Parsed value tokens, present only when {@link value} contains a `$`
|
|
296
|
+
* reference (ADR-0005).
|
|
297
|
+
*/
|
|
298
|
+
readonly tokens?: readonly Token[];
|
|
299
|
+
/** Whether this segment alone carries `!important` (ADR-0003). */
|
|
300
|
+
readonly important?: boolean;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** A native CSS at-rule preserved with its authored meaning. */
|
|
304
|
+
export interface NativeAtRule {
|
|
305
|
+
readonly kind: "native-at-rule";
|
|
306
|
+
/** At-rule name without the `@` sigil (for example `media`, `keyframes`, `font-face`). */
|
|
307
|
+
readonly name: string;
|
|
308
|
+
/** Raw prelude text as authored, trimmed of surrounding whitespace; empty when absent. */
|
|
309
|
+
readonly prelude: string;
|
|
310
|
+
/**
|
|
311
|
+
* Parsed block members for block at-rules, or `undefined` for statement
|
|
312
|
+
* at-rules such as `@import` and `@charset`. Contexts that cannot accept
|
|
313
|
+
* Chikx transformations are rejected semantically rather than rewritten.
|
|
314
|
+
*/
|
|
315
|
+
readonly block?: readonly BlockItem[];
|
|
316
|
+
/** Covers the `@` name through the block or terminating `;`. */
|
|
317
|
+
readonly span: Span;
|
|
318
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Span } from "./span.js";
|
|
2
|
+
|
|
3
|
+
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stable diagnostic identifier of the form `CHIKX####`.
|
|
7
|
+
*
|
|
8
|
+
* Families are CHIKX1xxx (syntax and lexical), CHIKX2xxx (symbols and
|
|
9
|
+
* modules), CHIKX3xxx (media and conditions), CHIKX4xxx (naming and exports)
|
|
10
|
+
* and CHIKX5xxx (output planning). Subcodes may be added inside a family
|
|
11
|
+
* without changing the shape of {@link DIAGNOSTIC_CODES}; every code is stable
|
|
12
|
+
* once released.
|
|
13
|
+
*/
|
|
14
|
+
export type DiagnosticCode = `CHIKX${Digit}${Digit}${Digit}${Digit}`;
|
|
15
|
+
|
|
16
|
+
/** A diagnostic is either fatal for the affected construct or advisory. */
|
|
17
|
+
export type DiagnosticSeverity = "error" | "warning";
|
|
18
|
+
|
|
19
|
+
/** The five stable diagnostic families. */
|
|
20
|
+
export type DiagnosticFamily = "syntax" | "variables" | "media" | "naming" | "output";
|
|
21
|
+
|
|
22
|
+
/** Registry metadata for one reserved diagnostic code. */
|
|
23
|
+
export interface DiagnosticCodeInfo {
|
|
24
|
+
/** The code itself, identical to its key in {@link DIAGNOSTIC_CODES}. */
|
|
25
|
+
readonly code: DiagnosticCode;
|
|
26
|
+
/** Family the code belongs to. */
|
|
27
|
+
readonly family: DiagnosticFamily;
|
|
28
|
+
/** Severity producers should use unless a documented case narrows it. */
|
|
29
|
+
readonly defaultSeverity: DiagnosticSeverity;
|
|
30
|
+
/** Short, user-facing description of when the code is reported. */
|
|
31
|
+
readonly summary: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Codes reserved for v0.1; additional subcodes may join a family later. */
|
|
35
|
+
export type ReservedDiagnosticCode =
|
|
36
|
+
| "CHIKX1001"
|
|
37
|
+
| "CHIKX1002"
|
|
38
|
+
| "CHIKX1003"
|
|
39
|
+
| "CHIKX2001"
|
|
40
|
+
| "CHIKX3001"
|
|
41
|
+
| "CHIKX4001"
|
|
42
|
+
| "CHIKX5001";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Every reserved Chikx diagnostic with a short description.
|
|
46
|
+
*
|
|
47
|
+
* Family anchors double as the canonical code for the whole family, so early
|
|
48
|
+
* implementations may report the anchor while finer subcodes are introduced
|
|
49
|
+
* later. Statement-scoped syntax diagnostics span the affected statement so
|
|
50
|
+
* editors and fixtures can point at its start.
|
|
51
|
+
*/
|
|
52
|
+
export const DIAGNOSTIC_CODES: Readonly<Record<ReservedDiagnosticCode, DiagnosticCodeInfo>> = {
|
|
53
|
+
CHIKX1001: {
|
|
54
|
+
code: "CHIKX1001",
|
|
55
|
+
family: "syntax",
|
|
56
|
+
defaultSeverity: "error",
|
|
57
|
+
summary:
|
|
58
|
+
"General syntax or lexical error, including a conditional block outside a rule, an unknown setup key, a duplicate setting, a duplicate @setup block and a lexer-level recovery.",
|
|
59
|
+
},
|
|
60
|
+
CHIKX1002: {
|
|
61
|
+
code: "CHIKX1002",
|
|
62
|
+
family: "syntax",
|
|
63
|
+
defaultSeverity: "error",
|
|
64
|
+
summary:
|
|
65
|
+
"Missing semicolon after a Chikx declaration. v0.1 requires semicolons for Chikx declarations, while an ordinary CSS final declaration without a trailing semicolon before `}` MAY be accepted (SPECIFICATION §3.1).",
|
|
66
|
+
},
|
|
67
|
+
CHIKX1003: {
|
|
68
|
+
code: "CHIKX1003",
|
|
69
|
+
family: "syntax",
|
|
70
|
+
defaultSeverity: "error",
|
|
71
|
+
summary:
|
|
72
|
+
"Malformed declaration or block: unbalanced parentheses or braces in values, or an unrecoverable statement.",
|
|
73
|
+
},
|
|
74
|
+
CHIKX2001: {
|
|
75
|
+
code: "CHIKX2001",
|
|
76
|
+
family: "variables",
|
|
77
|
+
defaultSeverity: "error",
|
|
78
|
+
summary:
|
|
79
|
+
"Symbol or module error: undefined token, import cycle, duplicate or ambiguous definition, or a compile-time/runtime name collision.",
|
|
80
|
+
},
|
|
81
|
+
CHIKX3001: {
|
|
82
|
+
code: "CHIKX3001",
|
|
83
|
+
family: "media",
|
|
84
|
+
defaultSeverity: "error",
|
|
85
|
+
summary:
|
|
86
|
+
"Media or condition error: unknown alias, unsupported alias combination or a combination that cannot form valid CSS.",
|
|
87
|
+
},
|
|
88
|
+
CHIKX4001: {
|
|
89
|
+
code: "CHIKX4001",
|
|
90
|
+
family: "naming",
|
|
91
|
+
defaultSeverity: "error",
|
|
92
|
+
summary:
|
|
93
|
+
"Naming or export error: camelCase alias collision, invalid CSS identifier, or an omitted named export that is reserved or not a valid JavaScript identifier (a warning in that case).",
|
|
94
|
+
},
|
|
95
|
+
CHIKX5001: {
|
|
96
|
+
code: "CHIKX5001",
|
|
97
|
+
family: "output",
|
|
98
|
+
defaultSeverity: "error",
|
|
99
|
+
summary:
|
|
100
|
+
"Output planning error: duplicate target, input/output overlap, workspace or symlink escape, or another unsafe output plan.",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** One reported problem tied to an exact source range. */
|
|
105
|
+
export interface Diagnostic {
|
|
106
|
+
/** Stable Chikx code, always a member of the CHIKX#### family. */
|
|
107
|
+
readonly code: DiagnosticCode;
|
|
108
|
+
/** Whether the affected construct is rejected or merely flagged. */
|
|
109
|
+
readonly severity: DiagnosticSeverity;
|
|
110
|
+
/** Complete, user-facing explanation with actionable context. */
|
|
111
|
+
readonly message: string;
|
|
112
|
+
/** Exact source range; line and column are derived from its offsets. */
|
|
113
|
+
readonly span: Span;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Create an error diagnostic; the affected construct is rejected. */
|
|
117
|
+
export function error(code: DiagnosticCode, message: string, span: Span): Diagnostic {
|
|
118
|
+
return { code, severity: "error", message, span };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Create a warning diagnostic; output is still produced. */
|
|
122
|
+
export function warning(code: DiagnosticCode, message: string, span: Span): Diagnostic {
|
|
123
|
+
return { code, severity: "warning", message, span };
|
|
124
|
+
}
|