@chikx/compiler 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/emitter/index.d.ts +96 -0
- package/dist/emitter/index.d.ts.map +1 -0
- package/dist/emitter/index.js +415 -0
- package/dist/emitter/index.js.map +1 -0
- package/dist/formatter/index.d.ts +53 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +464 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/host/node.d.ts +34 -0
- package/dist/host/node.d.ts.map +1 -0
- package/dist/host/node.js +80 -0
- package/dist/host/node.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +792 -0
- package/dist/index.js.map +1 -0
- package/dist/ir/factories.d.ts +35 -0
- package/dist/ir/factories.d.ts.map +1 -0
- package/dist/ir/factories.js +47 -0
- package/dist/ir/factories.js.map +1 -0
- package/dist/ir/index.d.ts +13 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +2 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/types.d.ts +139 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +2 -0
- package/dist/ir/types.js.map +1 -0
- package/dist/lexer/at-keywords.d.ts +27 -0
- package/dist/lexer/at-keywords.d.ts.map +1 -0
- package/dist/lexer/at-keywords.js +35 -0
- package/dist/lexer/at-keywords.js.map +1 -0
- package/dist/lexer/characters.d.ts +38 -0
- package/dist/lexer/characters.d.ts.map +1 -0
- package/dist/lexer/characters.js +74 -0
- package/dist/lexer/characters.js.map +1 -0
- package/dist/lexer/comments.d.ts +22 -0
- package/dist/lexer/comments.d.ts.map +1 -0
- package/dist/lexer/comments.js +20 -0
- package/dist/lexer/comments.js.map +1 -0
- package/dist/lexer/diagnostics.d.ts +24 -0
- package/dist/lexer/diagnostics.d.ts.map +1 -0
- package/dist/lexer/diagnostics.js +29 -0
- package/dist/lexer/diagnostics.js.map +1 -0
- package/dist/lexer/dollar-refs.d.ts +13 -0
- package/dist/lexer/dollar-refs.d.ts.map +1 -0
- package/dist/lexer/dollar-refs.js +22 -0
- package/dist/lexer/dollar-refs.js.map +1 -0
- package/dist/lexer/index.d.ts +32 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +26 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/names.d.ts +23 -0
- package/dist/lexer/names.d.ts.map +1 -0
- package/dist/lexer/names.js +48 -0
- package/dist/lexer/names.js.map +1 -0
- package/dist/lexer/numbers.d.ts +22 -0
- package/dist/lexer/numbers.d.ts.map +1 -0
- package/dist/lexer/numbers.js +60 -0
- package/dist/lexer/numbers.js.map +1 -0
- package/dist/lexer/scanner.d.ts +30 -0
- package/dist/lexer/scanner.d.ts.map +1 -0
- package/dist/lexer/scanner.js +158 -0
- package/dist/lexer/scanner.js.map +1 -0
- package/dist/lexer/strings.d.ts +25 -0
- package/dist/lexer/strings.d.ts.map +1 -0
- package/dist/lexer/strings.js +41 -0
- package/dist/lexer/strings.js.map +1 -0
- package/dist/lexer/urls.d.ts +28 -0
- package/dist/lexer/urls.d.ts.map +1 -0
- package/dist/lexer/urls.js +54 -0
- package/dist/lexer/urls.js.map +1 -0
- package/dist/lowering/expand-groups.d.ts +61 -0
- package/dist/lowering/expand-groups.d.ts.map +1 -0
- package/dist/lowering/expand-groups.js +117 -0
- package/dist/lowering/expand-groups.js.map +1 -0
- package/dist/lowering/group.d.ts +30 -0
- package/dist/lowering/group.d.ts.map +1 -0
- package/dist/lowering/group.js +109 -0
- package/dist/lowering/group.js.map +1 -0
- package/dist/lowering/index.d.ts +26 -0
- package/dist/lowering/index.d.ts.map +1 -0
- package/dist/lowering/index.js +23 -0
- package/dist/lowering/index.js.map +1 -0
- package/dist/lowering/lower.d.ts +21 -0
- package/dist/lowering/lower.d.ts.map +1 -0
- package/dist/lowering/lower.js +296 -0
- package/dist/lowering/lower.js.map +1 -0
- package/dist/lowering/media.d.ts +63 -0
- package/dist/lowering/media.d.ts.map +1 -0
- package/dist/lowering/media.js +237 -0
- package/dist/lowering/media.js.map +1 -0
- package/dist/lowering/merge.d.ts +35 -0
- package/dist/lowering/merge.d.ts.map +1 -0
- package/dist/lowering/merge.js +146 -0
- package/dist/lowering/merge.js.map +1 -0
- package/dist/lowering/property-families.d.ts +50 -0
- package/dist/lowering/property-families.d.ts.map +1 -0
- package/dist/lowering/property-families.js +175 -0
- package/dist/lowering/property-families.js.map +1 -0
- package/dist/lowering/spans.d.ts +36 -0
- package/dist/lowering/spans.d.ts.map +1 -0
- package/dist/lowering/spans.js +100 -0
- package/dist/lowering/spans.js.map +1 -0
- package/dist/naming/index.d.ts +37 -0
- package/dist/naming/index.d.ts.map +1 -0
- package/dist/naming/index.js +34 -0
- package/dist/naming/index.js.map +1 -0
- package/dist/naming/mapgen.d.ts +70 -0
- package/dist/naming/mapgen.d.ts.map +1 -0
- package/dist/naming/mapgen.js +153 -0
- package/dist/naming/mapgen.js.map +1 -0
- package/dist/naming/merge.d.ts +62 -0
- package/dist/naming/merge.d.ts.map +1 -0
- package/dist/naming/merge.js +77 -0
- package/dist/naming/merge.js.map +1 -0
- package/dist/naming/rewrite.d.ts +14 -0
- package/dist/naming/rewrite.d.ts.map +1 -0
- package/dist/naming/rewrite.js +191 -0
- package/dist/naming/rewrite.js.map +1 -0
- package/dist/naming/scan.d.ts +80 -0
- package/dist/naming/scan.d.ts.map +1 -0
- package/dist/naming/scan.js +193 -0
- package/dist/naming/scan.js.map +1 -0
- package/dist/naming/table.d.ts +68 -0
- package/dist/naming/table.d.ts.map +1 -0
- package/dist/naming/table.js +132 -0
- package/dist/naming/table.js.map +1 -0
- package/dist/naming/types.d.ts +94 -0
- package/dist/naming/types.d.ts.map +1 -0
- package/dist/naming/types.js +2 -0
- package/dist/naming/types.js.map +1 -0
- package/dist/output/import-path.d.ts +24 -0
- package/dist/output/import-path.d.ts.map +1 -0
- package/dist/output/import-path.js +30 -0
- package/dist/output/import-path.js.map +1 -0
- package/dist/output/index.d.ts +40 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +138 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/manifest.d.ts +17 -0
- package/dist/output/manifest.d.ts.map +1 -0
- package/dist/output/manifest.js +22 -0
- package/dist/output/manifest.js.map +1 -0
- package/dist/output/paths.d.ts +54 -0
- package/dist/output/paths.d.ts.map +1 -0
- package/dist/output/paths.js +183 -0
- package/dist/output/paths.js.map +1 -0
- package/dist/output/resolve.d.ts +100 -0
- package/dist/output/resolve.d.ts.map +1 -0
- package/dist/output/resolve.js +313 -0
- package/dist/output/resolve.js.map +1 -0
- package/dist/output/validate.d.ts +82 -0
- package/dist/output/validate.d.ts.map +1 -0
- package/dist/output/validate.js +128 -0
- package/dist/output/validate.js.map +1 -0
- package/dist/parser/cursor.d.ts +55 -0
- package/dist/parser/cursor.d.ts.map +1 -0
- package/dist/parser/cursor.js +120 -0
- package/dist/parser/cursor.js.map +1 -0
- package/dist/parser/declaration.d.ts +21 -0
- package/dist/parser/declaration.d.ts.map +1 -0
- package/dist/parser/declaration.js +201 -0
- package/dist/parser/declaration.js.map +1 -0
- package/dist/parser/diagnostics.d.ts +52 -0
- package/dist/parser/diagnostics.d.ts.map +1 -0
- package/dist/parser/diagnostics.js +55 -0
- package/dist/parser/diagnostics.js.map +1 -0
- package/dist/parser/group.d.ts +26 -0
- package/dist/parser/group.d.ts.map +1 -0
- package/dist/parser/group.js +219 -0
- package/dist/parser/group.js.map +1 -0
- package/dist/parser/index.d.ts +30 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +48 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/modifier.d.ts +25 -0
- package/dist/parser/modifier.d.ts.map +1 -0
- package/dist/parser/modifier.js +41 -0
- package/dist/parser/modifier.js.map +1 -0
- package/dist/parser/recovery.d.ts +23 -0
- package/dist/parser/recovery.d.ts.map +1 -0
- package/dist/parser/recovery.js +80 -0
- package/dist/parser/recovery.js.map +1 -0
- package/dist/parser/rule.d.ts +39 -0
- package/dist/parser/rule.d.ts.map +1 -0
- package/dist/parser/rule.js +337 -0
- package/dist/parser/rule.js.map +1 -0
- package/dist/parser/statement.d.ts +21 -0
- package/dist/parser/statement.d.ts.map +1 -0
- package/dist/parser/statement.js +48 -0
- package/dist/parser/statement.js.map +1 -0
- package/dist/parser/statements.d.ts +33 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +605 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/value.d.ts +57 -0
- package/dist/parser/value.d.ts.map +1 -0
- package/dist/parser/value.js +226 -0
- package/dist/parser/value.js.map +1 -0
- package/dist/resolver/graph.d.ts +20 -0
- package/dist/resolver/graph.d.ts.map +1 -0
- package/dist/resolver/graph.js +382 -0
- package/dist/resolver/graph.js.map +1 -0
- package/dist/resolver/groups.d.ts +70 -0
- package/dist/resolver/groups.d.ts.map +1 -0
- package/dist/resolver/groups.js +143 -0
- package/dist/resolver/groups.js.map +1 -0
- package/dist/resolver/index.d.ts +46 -0
- package/dist/resolver/index.d.ts.map +1 -0
- package/dist/resolver/index.js +46 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/resolver/keyframes.d.ts +56 -0
- package/dist/resolver/keyframes.d.ts.map +1 -0
- package/dist/resolver/keyframes.js +102 -0
- package/dist/resolver/keyframes.js.map +1 -0
- package/dist/resolver/paths.d.ts +37 -0
- package/dist/resolver/paths.d.ts.map +1 -0
- package/dist/resolver/paths.js +135 -0
- package/dist/resolver/paths.js.map +1 -0
- package/dist/resolver/rules.d.ts +34 -0
- package/dist/resolver/rules.d.ts.map +1 -0
- package/dist/resolver/rules.js +52 -0
- package/dist/resolver/rules.js.map +1 -0
- package/dist/resolver/scopes.d.ts +44 -0
- package/dist/resolver/scopes.d.ts.map +1 -0
- package/dist/resolver/scopes.js +213 -0
- package/dist/resolver/scopes.js.map +1 -0
- package/dist/resolver/types.d.ts +238 -0
- package/dist/resolver/types.d.ts.map +1 -0
- package/dist/resolver/types.js +11 -0
- package/dist/resolver/types.js.map +1 -0
- package/dist/selectors/flatten.d.ts +95 -0
- package/dist/selectors/flatten.d.ts.map +1 -0
- package/dist/selectors/flatten.js +384 -0
- package/dist/selectors/flatten.js.map +1 -0
- package/dist/selectors/index.d.ts +15 -0
- package/dist/selectors/index.d.ts.map +1 -0
- package/dist/selectors/index.js +14 -0
- package/dist/selectors/index.js.map +1 -0
- package/dist/selectors/scan.d.ts +54 -0
- package/dist/selectors/scan.d.ts.map +1 -0
- package/dist/selectors/scan.js +191 -0
- package/dist/selectors/scan.js.map +1 -0
- package/dist/selectors/specificity.d.ts +28 -0
- package/dist/selectors/specificity.d.ts.map +1 -0
- package/dist/selectors/specificity.js +297 -0
- package/dist/selectors/specificity.js.map +1 -0
- package/dist/setup-list.d.ts +41 -0
- package/dist/setup-list.d.ts.map +1 -0
- package/dist/setup-list.js +122 -0
- package/dist/setup-list.js.map +1 -0
- package/dist/sourcemaps/index.d.ts +14 -0
- package/dist/sourcemaps/index.d.ts.map +1 -0
- package/dist/sourcemaps/index.js +13 -0
- package/dist/sourcemaps/index.js.map +1 -0
- package/dist/sourcemaps/mappings.d.ts +77 -0
- package/dist/sourcemaps/mappings.d.ts.map +1 -0
- package/dist/sourcemaps/mappings.js +124 -0
- package/dist/sourcemaps/mappings.js.map +1 -0
- package/dist/sourcemaps/vlq.d.ts +12 -0
- package/dist/sourcemaps/vlq.d.ts.map +1 -0
- package/dist/sourcemaps/vlq.js +29 -0
- package/dist/sourcemaps/vlq.js.map +1 -0
- package/dist/types/ast.d.ts +291 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +2 -0
- package/dist/types/ast.js.map +1 -0
- package/dist/types/diagnostics.d.ts +55 -0
- package/dist/types/diagnostics.d.ts.map +1 -0
- package/dist/types/diagnostics.js +61 -0
- package/dist/types/diagnostics.js.map +1 -0
- package/dist/types/options.d.ts +274 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +11 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/result.d.ts +112 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +2 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/span.d.ts +19 -0
- package/dist/types/span.d.ts.map +1 -0
- package/dist/types/span.js +2 -0
- package/dist/types/span.js.map +1 -0
- package/dist/types/token.d.ts +68 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +2 -0
- package/dist/types/token.js.map +1 -0
- package/dist/variables/ast.d.ts +56 -0
- package/dist/variables/ast.d.ts.map +1 -0
- package/dist/variables/ast.js +167 -0
- package/dist/variables/ast.js.map +1 -0
- package/dist/variables/expand.d.ts +109 -0
- package/dist/variables/expand.d.ts.map +1 -0
- package/dist/variables/expand.js +213 -0
- package/dist/variables/expand.js.map +1 -0
- package/dist/variables/index.d.ts +36 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +33 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/naming.d.ts +39 -0
- package/dist/variables/naming.d.ts.map +1 -0
- package/dist/variables/naming.js +14 -0
- package/dist/variables/naming.js.map +1 -0
- package/dist/variables/runtime.d.ts +81 -0
- package/dist/variables/runtime.d.ts.map +1 -0
- package/dist/variables/runtime.js +228 -0
- package/dist/variables/runtime.js.map +1 -0
- package/dist/variables/substitute.d.ts +65 -0
- package/dist/variables/substitute.d.ts.map +1 -0
- package/dist/variables/substitute.js +73 -0
- package/dist/variables/substitute.js.map +1 -0
- package/dist/variables/walk.d.ts +37 -0
- package/dist/variables/walk.d.ts.map +1 -0
- package/dist/variables/walk.js +113 -0
- package/dist/variables/walk.js.map +1 -0
- package/package.json +35 -4
- 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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { splitReference } from "./expand.js";
|
|
2
|
+
/**
|
|
3
|
+
* Map each declaration segment start to its parsed value tokens.
|
|
4
|
+
*
|
|
5
|
+
* Lowering tiles a declaration span into one segment per value (A05), and the
|
|
6
|
+
* IR keeps that segment origin in `DeclarationIr.span`, so an IR declaration
|
|
7
|
+
* can recover the authored tokens by its `span.start`. The value is `undefined`
|
|
8
|
+
* when the authored segment contains no `$` reference (`tokens` is optional by
|
|
9
|
+
* contract), which is also the case where substitution has nothing to do.
|
|
10
|
+
*/
|
|
11
|
+
export function segmentValueTokens(ast) {
|
|
12
|
+
const segments = new Map();
|
|
13
|
+
if (ast === undefined)
|
|
14
|
+
return segments;
|
|
15
|
+
const addDeclaration = (declaration) => {
|
|
16
|
+
if (declaration.tokens !== undefined)
|
|
17
|
+
segments.set(declaration.span.start, declaration.tokens);
|
|
18
|
+
for (const variant of declaration.variants) {
|
|
19
|
+
if (variant.tokens !== undefined)
|
|
20
|
+
segments.set(variant.span.start, variant.tokens);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const visitBody = (items) => {
|
|
24
|
+
for (const item of items) {
|
|
25
|
+
switch (item.kind) {
|
|
26
|
+
case "declaration":
|
|
27
|
+
addDeclaration(item);
|
|
28
|
+
break;
|
|
29
|
+
case "rule":
|
|
30
|
+
visitBody(item.body);
|
|
31
|
+
break;
|
|
32
|
+
case "conditional-block":
|
|
33
|
+
visitBody(item.body);
|
|
34
|
+
break;
|
|
35
|
+
case "native-at-rule":
|
|
36
|
+
if (item.block !== undefined)
|
|
37
|
+
visitBody(item.block);
|
|
38
|
+
break;
|
|
39
|
+
case "group-use-site":
|
|
40
|
+
// Use-site overrides are ordinary declarations of the consuming
|
|
41
|
+
// module even before expansion replaces the node (ADR-0017).
|
|
42
|
+
for (const declaration of item.declarations)
|
|
43
|
+
addDeclaration(declaration);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
for (const item of ast.items) {
|
|
49
|
+
if (item.kind === "rule")
|
|
50
|
+
visitBody(item.body);
|
|
51
|
+
else if (item.kind === "native-at-rule" && item.block !== undefined)
|
|
52
|
+
visitBody(item.block);
|
|
53
|
+
}
|
|
54
|
+
return segments;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Collect the segment starts authored inside top-level `@group.<name>`
|
|
58
|
+
* definitions (ADR-0017).
|
|
59
|
+
*
|
|
60
|
+
* Definitions emit no IR, so a {@link DeclarationIr} whose origin segment is in
|
|
61
|
+
* this set can only have reached the IR through use-site expansion. Substitution
|
|
62
|
+
* uses that to enforce owner decision (b): group defaults are compile-time only,
|
|
63
|
+
* so a `@runtime` reference there is CHIKX2001 and the segment is omitted
|
|
64
|
+
* instead of rewritten to `var(--...)` with the consuming build's prefix.
|
|
65
|
+
*
|
|
66
|
+
* Both the base segment and every inline-variant segment are included, matching
|
|
67
|
+
* the IR's per-segment spans.
|
|
68
|
+
*/
|
|
69
|
+
export function groupDefaultSegments(ast) {
|
|
70
|
+
const starts = new Set();
|
|
71
|
+
if (ast === undefined)
|
|
72
|
+
return starts;
|
|
73
|
+
for (const item of ast.items) {
|
|
74
|
+
if (item.kind !== "group-definition")
|
|
75
|
+
continue;
|
|
76
|
+
for (const declaration of item.declarations) {
|
|
77
|
+
starts.add(declaration.span.start);
|
|
78
|
+
for (const variant of declaration.variants)
|
|
79
|
+
starts.add(variant.span.start);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return starts;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Collect authored `$` references from one module's AST.
|
|
86
|
+
*
|
|
87
|
+
* `includeRules` adds references from stylesheet rule values (used for the entry
|
|
88
|
+
* module, whose declarations are compiled); without it only `@variables` and
|
|
89
|
+
* `@runtime` values are visited, which is what imported token-only modules can
|
|
90
|
+
* contribute to the entry's artifact (SPECIFICATION.md §6.1: imports bring in
|
|
91
|
+
* tokens only, not rules). Rule values include the declarations of `@group.`
|
|
92
|
+
* use-site blocks, because this module's build emits them (ADR-0017).
|
|
93
|
+
*/
|
|
94
|
+
export function astReferences(ast, options) {
|
|
95
|
+
const references = [];
|
|
96
|
+
const collect = (tokens, file) => {
|
|
97
|
+
if (tokens === undefined)
|
|
98
|
+
return;
|
|
99
|
+
for (const token of tokens) {
|
|
100
|
+
if (token.kind !== "dollar-ref")
|
|
101
|
+
continue;
|
|
102
|
+
const reference = splitReference(token.value);
|
|
103
|
+
if (reference === null)
|
|
104
|
+
continue;
|
|
105
|
+
references.push({ reference, span: { start: token.start, end: token.end, file } });
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const collectDeclaration = (declaration, file) => {
|
|
109
|
+
collect(declaration.tokens, file);
|
|
110
|
+
for (const variant of declaration.variants)
|
|
111
|
+
collect(variant.tokens, file);
|
|
112
|
+
};
|
|
113
|
+
const collectTokenDeclaration = (token, file) => {
|
|
114
|
+
collect(token.tokens, file);
|
|
115
|
+
};
|
|
116
|
+
const visitBody = (items, file) => {
|
|
117
|
+
for (const item of items) {
|
|
118
|
+
switch (item.kind) {
|
|
119
|
+
case "declaration":
|
|
120
|
+
collectDeclaration(item, file);
|
|
121
|
+
break;
|
|
122
|
+
case "rule":
|
|
123
|
+
visitBody(item.body, file);
|
|
124
|
+
break;
|
|
125
|
+
case "conditional-block":
|
|
126
|
+
visitBody(item.body, file);
|
|
127
|
+
break;
|
|
128
|
+
case "native-at-rule":
|
|
129
|
+
if (item.block !== undefined)
|
|
130
|
+
visitBody(item.block, file);
|
|
131
|
+
break;
|
|
132
|
+
case "group-use-site":
|
|
133
|
+
// Use-site overrides are emitted in this module's build, so a
|
|
134
|
+
// `@runtime` reference authored there must register its custom
|
|
135
|
+
// property exactly like a plain declaration (ADR-0017 item 6).
|
|
136
|
+
for (const declaration of item.declarations)
|
|
137
|
+
collectDeclaration(declaration, file);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const file = ast.file;
|
|
143
|
+
for (const item of ast.items) {
|
|
144
|
+
switch (item.kind) {
|
|
145
|
+
case "variables":
|
|
146
|
+
for (const token of item.tokens)
|
|
147
|
+
collectTokenDeclaration(token, file);
|
|
148
|
+
break;
|
|
149
|
+
case "runtime":
|
|
150
|
+
for (const declaration of item.declarations)
|
|
151
|
+
collectDeclaration(declaration, file);
|
|
152
|
+
break;
|
|
153
|
+
case "rule":
|
|
154
|
+
if (options.includeRules)
|
|
155
|
+
visitBody(item.body, file);
|
|
156
|
+
break;
|
|
157
|
+
case "native-at-rule":
|
|
158
|
+
if (options.includeRules && item.block !== undefined)
|
|
159
|
+
visitBody(item.block, file);
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return references;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/variables/ast.ts"],"names":[],"mappings":"AAGA,OA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2
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
3
|
+
import type { Span } from "../types/span.js";
|
|
4
|
+
/**
|
|
5
|
+
* `$`-reference resolution and textual expansion (SPECIFICATION.md §6.1).
|
|
6
|
+
*
|
|
7
|
+
* Both passes share this core: substitution renders compile-time tokens
|
|
8
|
+
* textually and runtime tokens as `var(--...)`, while runtime emission reuses
|
|
9
|
+
* the same walk for `@runtime` values. Resolution always uses the token scope
|
|
10
|
+
* of the module whose text is being expanded, so imported values resolve in
|
|
11
|
+
* their defining module and a local override never mutates an imported module
|
|
12
|
+
* (§6.1).
|
|
13
|
+
*
|
|
14
|
+
* Expansion is textual, not evaluative: the authored slice is spliced, so
|
|
15
|
+
* whitespace, `calc()` spacing, comments and every non-reference token stay
|
|
16
|
+
* byte-identical. The built-in `keyframes` namespace (ADR-0015) is the one
|
|
17
|
+
* reference family with no declaring value: `$keyframes.<name>` resolves to the
|
|
18
|
+
* authored keyframe name text and is spliced as a literal.
|
|
19
|
+
*/
|
|
20
|
+
/** Maximum nested compile-time expansions before a chain is rejected. */
|
|
21
|
+
export declare const MAX_EXPANSION_DEPTH = 64;
|
|
22
|
+
/**
|
|
23
|
+
* Where one value text came from.
|
|
24
|
+
*
|
|
25
|
+
* `module` selects the scope used to resolve references in the text. `start`
|
|
26
|
+
* is the absolute source offset of `text[0]` when it is known (the AST keeps
|
|
27
|
+
* parsed value tokens for values containing `$`, ADR-0005), which lets
|
|
28
|
+
* diagnostics point at the exact reference; otherwise `fallback` (the owning
|
|
29
|
+
* declaration or segment) is used.
|
|
30
|
+
*/
|
|
31
|
+
export interface ValueOrigin {
|
|
32
|
+
/** Canonical path of the module that authored the text. */
|
|
33
|
+
readonly module: string;
|
|
34
|
+
/** Absolute offset of the first character of the text, or `null` when unknown. */
|
|
35
|
+
readonly start: number | null;
|
|
36
|
+
/** Span reported when the exact reference offset cannot be derived. */
|
|
37
|
+
readonly fallback: Span;
|
|
38
|
+
}
|
|
39
|
+
/** Hooks that make expansion policy explicit for each caller. */
|
|
40
|
+
export interface ExpansionHooks {
|
|
41
|
+
/**
|
|
42
|
+
* Renders a reference to a runtime token. Substitution and runtime emission
|
|
43
|
+
* both emit `var(--...)`; the authored text is passed for diagnostics.
|
|
44
|
+
*/
|
|
45
|
+
readonly runtimeRef: (token: ScopedToken, authored: string) => string;
|
|
46
|
+
/** Receives one diagnostic per rejected reference. */
|
|
47
|
+
readonly report: (diagnostic: Diagnostic) => void;
|
|
48
|
+
}
|
|
49
|
+
/** One authored `$name` or `$name.member` reference. */
|
|
50
|
+
export interface TokenReference {
|
|
51
|
+
/** Symbol name without the `$` sigil or namespace. */
|
|
52
|
+
readonly name: string;
|
|
53
|
+
/** Namespace alias without the `$` sigil, when the reference is `$ns.member`. */
|
|
54
|
+
readonly namespace?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolution outcome for one reference.
|
|
58
|
+
*
|
|
59
|
+
* `text` is a built-in compile-time reference whose expansion is literal CSS
|
|
60
|
+
* text rather than another value: `$keyframes.<name>` becomes the authored
|
|
61
|
+
* keyframe name (ADR-0015). It is spliced as-is and never recursed into.
|
|
62
|
+
*/
|
|
63
|
+
export type ReferenceResolution = {
|
|
64
|
+
readonly kind: "compile";
|
|
65
|
+
readonly token: ScopedToken;
|
|
66
|
+
} | {
|
|
67
|
+
readonly kind: "runtime";
|
|
68
|
+
readonly token: ScopedToken;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "text";
|
|
71
|
+
readonly text: string;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: "error";
|
|
74
|
+
readonly diagnostic: Diagnostic;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Split authored `$ref` token text into name and optional namespace.
|
|
78
|
+
*
|
|
79
|
+
* Escapes are preserved: an escaped dot (`$a\.b`) stays part of the name
|
|
80
|
+
* because CSS escapes never introduce a member separator. Returns `null` for a
|
|
81
|
+
* bare `$`, which the lexer never emits as `dollar-ref` anyway.
|
|
82
|
+
*/
|
|
83
|
+
export declare function splitReference(authored: string): TokenReference | null;
|
|
84
|
+
/**
|
|
85
|
+
* Resolve one reference against a module's scopes.
|
|
86
|
+
*
|
|
87
|
+
* A bare `$name` consults the compile-time scope first, then the runtime scope
|
|
88
|
+
* (A07 handoff: the resolver already merged unqualified imports so a local
|
|
89
|
+
* definition shadows them). `$ns.member` consults only the namespace member
|
|
90
|
+
* maps, never the merged `$name` table, so namespaced imports stay independent
|
|
91
|
+
* (§6.1). Every failure is a CHIKX2001 with the reference span.
|
|
92
|
+
*/
|
|
93
|
+
export declare function resolveReference(reference: TokenReference, module: string, graph: ModuleGraph, span: Span): ReferenceResolution;
|
|
94
|
+
/**
|
|
95
|
+
* Expand every `$` reference in `text`, or return `null` when a reference is
|
|
96
|
+
* rejected.
|
|
97
|
+
*
|
|
98
|
+
* Each resolved compile-time token inserts its defining module's raw value,
|
|
99
|
+
* recursively expanded in that module's scope. A repeated token on the current
|
|
100
|
+
* expansion stack, or a chain longer than {@link MAX_EXPANSION_DEPTH}, is a
|
|
101
|
+
* CHIKX2001 cycle/depth error and aborts the value so the caller can omit the
|
|
102
|
+
* affected construct instead of leaking a literal `$`.
|
|
103
|
+
*
|
|
104
|
+
* Purity: the input text and graph are never mutated, and the result is a new
|
|
105
|
+
* string. Lexer diagnostics from re-scanning a value slice are intentionally
|
|
106
|
+
* ignored; the parser already owns lexical reporting.
|
|
107
|
+
*/
|
|
108
|
+
export declare function expandValue(text: string, origin: ValueOrigin, graph: ModuleGraph, hooks: ExpansionHooks, stack?: readonly string[]): string | null;
|
|
109
|
+
//# sourceMappingURL=expand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../../src/variables/expand.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,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,CAAA;CAAE,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CActE;AAMD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,GACT,mBAAmB,CAsErB;AAiCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,cAAc,EACrB,KAAK,GAAE,SAAS,MAAM,EAAO,GAC5B,MAAM,GAAG,IAAI,CA6Ef"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { tokenize } from "../lexer/index.js";
|
|
2
|
+
import { KEYFRAMES_NAMESPACE } from "../resolver/index.js";
|
|
3
|
+
import { error } from "../types/diagnostics.js";
|
|
4
|
+
/**
|
|
5
|
+
* `$`-reference resolution and textual expansion (SPECIFICATION.md §6.1).
|
|
6
|
+
*
|
|
7
|
+
* Both passes share this core: substitution renders compile-time tokens
|
|
8
|
+
* textually and runtime tokens as `var(--...)`, while runtime emission reuses
|
|
9
|
+
* the same walk for `@runtime` values. Resolution always uses the token scope
|
|
10
|
+
* of the module whose text is being expanded, so imported values resolve in
|
|
11
|
+
* their defining module and a local override never mutates an imported module
|
|
12
|
+
* (§6.1).
|
|
13
|
+
*
|
|
14
|
+
* Expansion is textual, not evaluative: the authored slice is spliced, so
|
|
15
|
+
* whitespace, `calc()` spacing, comments and every non-reference token stay
|
|
16
|
+
* byte-identical. The built-in `keyframes` namespace (ADR-0015) is the one
|
|
17
|
+
* reference family with no declaring value: `$keyframes.<name>` resolves to the
|
|
18
|
+
* authored keyframe name text and is spliced as a literal.
|
|
19
|
+
*/
|
|
20
|
+
/** Maximum nested compile-time expansions before a chain is rejected. */
|
|
21
|
+
export const MAX_EXPANSION_DEPTH = 64;
|
|
22
|
+
/**
|
|
23
|
+
* Split authored `$ref` token text into name and optional namespace.
|
|
24
|
+
*
|
|
25
|
+
* Escapes are preserved: an escaped dot (`$a\.b`) stays part of the name
|
|
26
|
+
* because CSS escapes never introduce a member separator. Returns `null` for a
|
|
27
|
+
* bare `$`, which the lexer never emits as `dollar-ref` anyway.
|
|
28
|
+
*/
|
|
29
|
+
export function splitReference(authored) {
|
|
30
|
+
if (!authored.startsWith("$") || authored.length < 2)
|
|
31
|
+
return null;
|
|
32
|
+
const body = authored.slice(1);
|
|
33
|
+
for (let index = 0; index < body.length; index++) {
|
|
34
|
+
const character = body[index];
|
|
35
|
+
if (character === "\\") {
|
|
36
|
+
index++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (character === "." && index > 0 && index < body.length - 1) {
|
|
40
|
+
return { name: body.slice(index + 1), namespace: body.slice(0, index) };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { name: body };
|
|
44
|
+
}
|
|
45
|
+
function fail(message, span) {
|
|
46
|
+
return { kind: "error", diagnostic: error("CHIKX2001", message, span) };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve one reference against a module's scopes.
|
|
50
|
+
*
|
|
51
|
+
* A bare `$name` consults the compile-time scope first, then the runtime scope
|
|
52
|
+
* (A07 handoff: the resolver already merged unqualified imports so a local
|
|
53
|
+
* definition shadows them). `$ns.member` consults only the namespace member
|
|
54
|
+
* maps, never the merged `$name` table, so namespaced imports stay independent
|
|
55
|
+
* (§6.1). Every failure is a CHIKX2001 with the reference span.
|
|
56
|
+
*/
|
|
57
|
+
export function resolveReference(reference, module, graph, span) {
|
|
58
|
+
const record = graph.modules.get(module);
|
|
59
|
+
const display = reference.namespace === undefined
|
|
60
|
+
? `$${reference.name}`
|
|
61
|
+
: `$${reference.namespace}.${reference.name}`;
|
|
62
|
+
if (record === undefined) {
|
|
63
|
+
return fail(`Module "${module}" is missing from the module graph, so "${display}" cannot be resolved.`, span);
|
|
64
|
+
}
|
|
65
|
+
if (reference.namespace === undefined) {
|
|
66
|
+
const compile = record.compileScope.tokens.get(reference.name);
|
|
67
|
+
if (compile !== undefined)
|
|
68
|
+
return { kind: "compile", token: compile };
|
|
69
|
+
const runtime = record.runtimeScope.tokens.get(reference.name);
|
|
70
|
+
if (runtime !== undefined)
|
|
71
|
+
return { kind: "runtime", token: runtime };
|
|
72
|
+
if (reference.name === KEYFRAMES_NAMESPACE) {
|
|
73
|
+
return fail(`"$${reference.name}" is a built-in namespace, not a token; reference a member such as "$${reference.name}.<name>".`, span);
|
|
74
|
+
}
|
|
75
|
+
if (record.compileScope.namespaces.has(reference.name) ||
|
|
76
|
+
record.runtimeScope.namespaces.has(reference.name)) {
|
|
77
|
+
return fail(`"$${reference.name}" is a namespace, not a token; reference a member such as "$${reference.name}.<name>".`, span);
|
|
78
|
+
}
|
|
79
|
+
return fail(`Undefined token "${display}" in "${module}".`, span);
|
|
80
|
+
}
|
|
81
|
+
// Built-in `keyframes` namespace (ADR-0015): a compile-time reference that
|
|
82
|
+
// expands to the authored keyframe name. Visibility is resolved by the module
|
|
83
|
+
// graph (own blocks plus `styles` imports), so an unknown member and an
|
|
84
|
+
// out-of-scope name both stay CHIKX2001 with the segment omitted.
|
|
85
|
+
if (reference.namespace === KEYFRAMES_NAMESPACE) {
|
|
86
|
+
const keyframe = record.keyframes.get(reference.name);
|
|
87
|
+
if (keyframe === undefined) {
|
|
88
|
+
return fail(`Unknown keyframe "${display}" in "${module}"; "$keyframes" exposes this file's own @keyframes names and those of modules imported with @use "..." styles (ADR-0015).`, span);
|
|
89
|
+
}
|
|
90
|
+
return { kind: "text", text: keyframe.name };
|
|
91
|
+
}
|
|
92
|
+
const compileNamespace = record.compileScope.namespaces.get(reference.namespace);
|
|
93
|
+
const runtimeNamespace = record.runtimeScope.namespaces.get(reference.namespace);
|
|
94
|
+
const namespace = compileNamespace ?? runtimeNamespace;
|
|
95
|
+
if (namespace === undefined) {
|
|
96
|
+
return fail(`Unknown token namespace "$${reference.namespace}" in "${module}"; import it with @use "..." as ${reference.namespace}.`, span);
|
|
97
|
+
}
|
|
98
|
+
const compileMember = compileNamespace?.members.get(reference.name);
|
|
99
|
+
if (compileMember !== undefined)
|
|
100
|
+
return { kind: "compile", token: compileMember };
|
|
101
|
+
const runtimeMember = runtimeNamespace?.members.get(reference.name);
|
|
102
|
+
if (runtimeMember !== undefined)
|
|
103
|
+
return { kind: "runtime", token: runtimeMember };
|
|
104
|
+
return fail(`Module "${namespace.module}" does not export "${display}" through namespace "$${reference.namespace}".`, span);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Absolute span of one `dollar-ref` token, or `null` when it is not authored.
|
|
108
|
+
*
|
|
109
|
+
* `text` is normally the authored slice starting at `origin.start`, but a
|
|
110
|
+
* rewritten value can contain generated `$` characters: an invalid `@setup
|
|
111
|
+
* prefix` such as `"$"` renders a runtime reference as `var(--$-p)`, and
|
|
112
|
+
* re-lexing that text would invent `$-p` at offsets taken from the *authored*
|
|
113
|
+
* base, ending past the end of the file. Offsets are only trusted while they
|
|
114
|
+
* still fall inside the fallback span of the text they were derived from; any
|
|
115
|
+
* other `$` is output from an earlier pass, not a reference the author wrote.
|
|
116
|
+
*/
|
|
117
|
+
function referenceSpan(origin, start, end) {
|
|
118
|
+
if (origin.start === null)
|
|
119
|
+
return origin.fallback;
|
|
120
|
+
const absoluteStart = origin.start + start;
|
|
121
|
+
const absoluteEnd = origin.start + end;
|
|
122
|
+
const authored = origin.fallback;
|
|
123
|
+
if (absoluteStart < authored.start || absoluteEnd > authored.end || absoluteStart > absoluteEnd) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return { start: absoluteStart, end: absoluteEnd, file: origin.module };
|
|
127
|
+
}
|
|
128
|
+
/** `$name` display form used in cycle chains. */
|
|
129
|
+
function displayName(key) {
|
|
130
|
+
return `$${key.slice(key.lastIndexOf("\u0000") + 1)}`;
|
|
131
|
+
}
|
|
132
|
+
function tokenKey(token) {
|
|
133
|
+
return `compile\u0000${token.module}\u0000${token.name}`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Expand every `$` reference in `text`, or return `null` when a reference is
|
|
137
|
+
* rejected.
|
|
138
|
+
*
|
|
139
|
+
* Each resolved compile-time token inserts its defining module's raw value,
|
|
140
|
+
* recursively expanded in that module's scope. A repeated token on the current
|
|
141
|
+
* expansion stack, or a chain longer than {@link MAX_EXPANSION_DEPTH}, is a
|
|
142
|
+
* CHIKX2001 cycle/depth error and aborts the value so the caller can omit the
|
|
143
|
+
* affected construct instead of leaking a literal `$`.
|
|
144
|
+
*
|
|
145
|
+
* Purity: the input text and graph are never mutated, and the result is a new
|
|
146
|
+
* string. Lexer diagnostics from re-scanning a value slice are intentionally
|
|
147
|
+
* ignored; the parser already owns lexical reporting.
|
|
148
|
+
*/
|
|
149
|
+
export function expandValue(text, origin, graph, hooks, stack = []) {
|
|
150
|
+
if (!text.includes("$"))
|
|
151
|
+
return text;
|
|
152
|
+
const { tokens } = tokenize(text, origin.module);
|
|
153
|
+
let output = "";
|
|
154
|
+
let cursor = 0;
|
|
155
|
+
let changed = false;
|
|
156
|
+
for (const token of tokens) {
|
|
157
|
+
if (token.kind !== "dollar-ref")
|
|
158
|
+
continue;
|
|
159
|
+
const reference = splitReference(token.value);
|
|
160
|
+
if (reference === null)
|
|
161
|
+
continue;
|
|
162
|
+
const span = referenceSpan(origin, token.start, token.end);
|
|
163
|
+
if (span === null)
|
|
164
|
+
continue;
|
|
165
|
+
const resolution = resolveReference(reference, origin.module, graph, span);
|
|
166
|
+
if (resolution.kind === "error") {
|
|
167
|
+
hooks.report(resolution.diagnostic);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
if (resolution.kind === "runtime") {
|
|
171
|
+
output += text.slice(cursor, token.start);
|
|
172
|
+
output += hooks.runtimeRef(resolution.token, token.value);
|
|
173
|
+
cursor = token.end;
|
|
174
|
+
changed = true;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (resolution.kind === "text") {
|
|
178
|
+
// Built-in compile-time text (`$keyframes.<name>`, ADR-0015): spliced
|
|
179
|
+
// verbatim, never expanded recursively, so no `$` can survive here.
|
|
180
|
+
output += text.slice(cursor, token.start);
|
|
181
|
+
output += resolution.text;
|
|
182
|
+
cursor = token.end;
|
|
183
|
+
changed = true;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const definition = resolution.token;
|
|
187
|
+
const key = tokenKey(definition);
|
|
188
|
+
if (stack.includes(key)) {
|
|
189
|
+
const chain = [...stack.map(displayName), displayName(key)].join(" -> ");
|
|
190
|
+
hooks.report(error("CHIKX2001", `Detected a variable reference cycle: ${chain}.`, span));
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
if (stack.length >= MAX_EXPANSION_DEPTH) {
|
|
194
|
+
hooks.report(error("CHIKX2001", `Variable expansion exceeded ${MAX_EXPANSION_DEPTH} nested references at "$${definition.name}".`, span));
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const nested = expandValue(definition.declaration.value, {
|
|
198
|
+
module: definition.module,
|
|
199
|
+
start: definition.declaration.tokens?.[0]?.start ?? null,
|
|
200
|
+
fallback: definition.span,
|
|
201
|
+
}, graph, hooks, [...stack, key]);
|
|
202
|
+
if (nested === null)
|
|
203
|
+
return null;
|
|
204
|
+
output += text.slice(cursor, token.start);
|
|
205
|
+
output += nested;
|
|
206
|
+
cursor = token.end;
|
|
207
|
+
changed = true;
|
|
208
|
+
}
|
|
209
|
+
if (!changed)
|
|
210
|
+
return text;
|
|
211
|
+
return output + text.slice(cursor);
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=expand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.js","sourceRoot":"","sources":["../../src/variables/expand.ts"],"names":[],"mappings":"AAAA,OAAO,EA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W,CAAC,KAAK,EAC5B;YACE,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI;YACxD,QAAQ,EAAE,UAAU,CAAC,IAAI;SAC1B,EACD,KAAK,EACL,KAAK,EACL,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAChB,CAAC;QACF,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAEjC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,IAAI,MAAM,CAAC;QACjB,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;QACnB,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IAED,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time variables and runtime tokens (P3, SPECIFICATION.md §6).
|
|
3
|
+
*
|
|
4
|
+
* Two pure passes complete the variables story of the pipeline:
|
|
5
|
+
*
|
|
6
|
+
* 1. {@link substitute} — resolves every `$name` / `$name.member` reference in
|
|
7
|
+
* declaration values against A07's module scopes, splices compile-time values
|
|
8
|
+
* textually (recursively, in each value's defining module) and rewrites
|
|
9
|
+
* runtime references to `var(--...)`. Undefined symbols, unknown namespaces
|
|
10
|
+
* or members and reference cycles are CHIKX2001 at the reference span and the
|
|
11
|
+
* affected declaration segment is omitted, so a literal `$` never reaches
|
|
12
|
+
* CSS. The built-in `keyframes` namespace (ADR-0015) expands
|
|
13
|
+
* `$keyframes.<name>` to the authored keyframe name text.
|
|
14
|
+
* 2. {@link emitRuntimeTokens} — emits `:root` custom-property rules for
|
|
15
|
+
* `@runtime` tokens (prefix-aware) with conditional `:root` overrides for
|
|
16
|
+
* inline variants, resolves duplicate property names in merge order with the
|
|
17
|
+
* entry last (ADR-0016), and rewrites runtime references in declaration values.
|
|
18
|
+
*
|
|
19
|
+
* Canonical pipeline position for consumers:
|
|
20
|
+
*
|
|
21
|
+
* ```text
|
|
22
|
+
* parse → buildModuleGraph → lower → substitute → emitRuntimeTokens
|
|
23
|
+
* → (P4: class rewrite → groupRuns) → emitCss
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Both passes are deterministic, frozen-output and filesystem-free; they never
|
|
27
|
+
* read the AST for source text, mutate their inputs or throw on malformed IR.
|
|
28
|
+
* Barrel wiring is lead-directed; import this facade until integration.
|
|
29
|
+
*/
|
|
30
|
+
export { emitRuntimeTokens } from "./runtime.js";
|
|
31
|
+
export type { RuntimeEmitOptions, RuntimeEmitResult } from "./runtime.js";
|
|
32
|
+
export { substitute } from "./substitute.js";
|
|
33
|
+
export type { SubstituteResult } from "./substitute.js";
|
|
34
|
+
export { effectivePrefix, runtimePropertyName } from "./naming.js";
|
|
35
|
+
export type { VariableNamingOptions } from "./naming.js";
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/variables/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACnE,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time variables and runtime tokens (P3, SPECIFICATION.md §6).
|
|
3
|
+
*
|
|
4
|
+
* Two pure passes complete the variables story of the pipeline:
|
|
5
|
+
*
|
|
6
|
+
* 1. {@link substitute} — resolves every `$name` / `$name.member` reference in
|
|
7
|
+
* declaration values against A07's module scopes, splices compile-time values
|
|
8
|
+
* textually (recursively, in each value's defining module) and rewrites
|
|
9
|
+
* runtime references to `var(--...)`. Undefined symbols, unknown namespaces
|
|
10
|
+
* or members and reference cycles are CHIKX2001 at the reference span and the
|
|
11
|
+
* affected declaration segment is omitted, so a literal `$` never reaches
|
|
12
|
+
* CSS. The built-in `keyframes` namespace (ADR-0015) expands
|
|
13
|
+
* `$keyframes.<name>` to the authored keyframe name text.
|
|
14
|
+
* 2. {@link emitRuntimeTokens} — emits `:root` custom-property rules for
|
|
15
|
+
* `@runtime` tokens (prefix-aware) with conditional `:root` overrides for
|
|
16
|
+
* inline variants, resolves duplicate property names in merge order with the
|
|
17
|
+
* entry last (ADR-0016), and rewrites runtime references in declaration values.
|
|
18
|
+
*
|
|
19
|
+
* Canonical pipeline position for consumers:
|
|
20
|
+
*
|
|
21
|
+
* ```text
|
|
22
|
+
* parse → buildModuleGraph → lower → substitute → emitRuntimeTokens
|
|
23
|
+
* → (P4: class rewrite → groupRuns) → emitCss
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Both passes are deterministic, frozen-output and filesystem-free; they never
|
|
27
|
+
* read the AST for source text, mutate their inputs or throw on malformed IR.
|
|
28
|
+
* Barrel wiring is lead-directed; import this facade until integration.
|
|
29
|
+
*/
|
|
30
|
+
export { emitRuntimeTokens } from "./runtime.js";
|
|
31
|
+
export { substitute } from "./substitute.js";
|
|
32
|
+
export { effectivePrefix, runtimePropertyName } from "./naming.js";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/variables/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { NamingOptions } from "../types/options.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime custom-property naming (SPECIFICATION.md §6.2, §7.2).
|
|
4
|
+
*
|
|
5
|
+
* Runtime tokens are emitted as native custom properties whose name is the
|
|
6
|
+
* effective file prefix plus the authored token name:
|
|
7
|
+
*
|
|
8
|
+
* - prefix `ui`, token `primary` → `--ui-primary`;
|
|
9
|
+
* - empty prefix, token `primary` → `--primary`.
|
|
10
|
+
*
|
|
11
|
+
* The prefix is authored configuration, exactly like the class prefix of §7.2,
|
|
12
|
+
* and is copied verbatim. Validating it as a CSS identifier is class-naming
|
|
13
|
+
* work (P4/A09); this pass never rewrites the prefix, so an invalid prefix
|
|
14
|
+
* produces an authoring error rather than a silently renamed property.
|
|
15
|
+
*/
|
|
16
|
+
/** Options that determine the effective runtime custom-property prefix. */
|
|
17
|
+
export interface VariableNamingOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Effective file-level prefix, normally `CompileOptions.prefix` after `@setup`
|
|
20
|
+
* resolution. Empty or omitted means custom properties are unprefixed.
|
|
21
|
+
*/
|
|
22
|
+
readonly prefix?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Class-naming options; when `naming.prefix` is present it wins over
|
|
25
|
+
* {@link prefix}, matching the precedence documented on `CompileOptions`
|
|
26
|
+
* (SPECIFICATION.md §7.2).
|
|
27
|
+
*/
|
|
28
|
+
readonly naming?: Pick<NamingOptions, "prefix">;
|
|
29
|
+
}
|
|
30
|
+
/** Resolve the effective prefix for runtime custom-property names. */
|
|
31
|
+
export declare function effectivePrefix(options?: VariableNamingOptions): string;
|
|
32
|
+
/**
|
|
33
|
+
* Custom-property name for one runtime token.
|
|
34
|
+
*
|
|
35
|
+
* Pure string composition: an empty prefix yields `--<name>`, otherwise
|
|
36
|
+
* `--<prefix>-<name>` (SPECIFICATION.md §6.2 example emits `--ui-primary`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function runtimePropertyName(name: string, prefix: string): string;
|
|
39
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/variables/naming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;CACjD;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAE3E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Resolve the effective prefix for runtime custom-property names. */
|
|
2
|
+
export function effectivePrefix(options = {}) {
|
|
3
|
+
return options.naming?.prefix ?? options.prefix ?? "";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Custom-property name for one runtime token.
|
|
7
|
+
*
|
|
8
|
+
* Pure string composition: an empty prefix yields `--<name>`, otherwise
|
|
9
|
+
* `--<prefix>-<name>` (SPECIFICATION.md §6.2 example emits `--ui-primary`).
|
|
10
|
+
*/
|
|
11
|
+
export function runtimePropertyName(name, prefix) {
|
|
12
|
+
return prefix === "" ? `--${name}` : `--${prefix}-${name}`;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=naming.js.map
|