@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,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-scope construction for the module resolver.
|
|
3
|
+
*
|
|
4
|
+
* A scope answers the question A08 asks: for a visible `$name` or
|
|
5
|
+
* `$namespace.member`, which module declares it, what AST node carries the
|
|
6
|
+
* value, and how did it become visible? Local definitions are collected first
|
|
7
|
+
* so imports always resolve against the target's *own* definitions and never
|
|
8
|
+
* re-export transitively (SPECIFICATION.md §6.1).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Declaration, Stylesheet, TokenDeclaration } from "../types/ast.js";
|
|
12
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
13
|
+
import { error } from "../types/diagnostics.js";
|
|
14
|
+
import type { Span } from "../types/span.js";
|
|
15
|
+
import { GROUP_DIRECTIVE } from "./groups.js";
|
|
16
|
+
import { KEYFRAMES_NAMESPACE } from "./keyframes.js";
|
|
17
|
+
import type {
|
|
18
|
+
ImportSymbolOrigin,
|
|
19
|
+
ResolvedImport,
|
|
20
|
+
ScopedNamespace,
|
|
21
|
+
ScopedToken,
|
|
22
|
+
ScopedTokenType,
|
|
23
|
+
TokenScope,
|
|
24
|
+
} from "./types.js";
|
|
25
|
+
|
|
26
|
+
/** A module's own, non-imported symbols, one map per symbol space. */
|
|
27
|
+
export interface LocalSymbols {
|
|
28
|
+
/** Definitions authored in `@variables` blocks. */
|
|
29
|
+
readonly compile: ReadonlyMap<string, ScopedToken>;
|
|
30
|
+
/** Definitions authored in `@runtime` blocks. */
|
|
31
|
+
readonly runtime: ReadonlyMap<string, ScopedToken>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One `@use "... as namespace"` binding before symbol-space filtering. */
|
|
35
|
+
interface NamespaceBinding {
|
|
36
|
+
readonly namespace: string;
|
|
37
|
+
readonly target: string;
|
|
38
|
+
readonly span: Span;
|
|
39
|
+
readonly specifier: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** An unqualified import that exports one name. */
|
|
43
|
+
interface UnqualifiedProvider {
|
|
44
|
+
readonly target: string;
|
|
45
|
+
readonly tokenType: ScopedTokenType;
|
|
46
|
+
readonly definition: ScopedToken;
|
|
47
|
+
readonly import: ResolvedImport;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Collect a module's local compile-time and runtime symbols in authored order.
|
|
52
|
+
*
|
|
53
|
+
* Reports CHIKX2001 at the offending declaration for a duplicate local name
|
|
54
|
+
* within or across blocks, and for a name defined as both a compile-time and a
|
|
55
|
+
* runtime variable (§6.1, §6.2). The first definition wins in the scope so the
|
|
56
|
+
* result stays deterministic even though the input is already erroneous.
|
|
57
|
+
*/
|
|
58
|
+
export function collectLocalSymbols(
|
|
59
|
+
file: string,
|
|
60
|
+
ast: Stylesheet,
|
|
61
|
+
report: (diagnostic: Diagnostic) => void,
|
|
62
|
+
): LocalSymbols {
|
|
63
|
+
const compile = new Map<string, ScopedToken>();
|
|
64
|
+
const runtime = new Map<string, ScopedToken>();
|
|
65
|
+
|
|
66
|
+
const add = (
|
|
67
|
+
target: Map<string, ScopedToken>,
|
|
68
|
+
tokenType: ScopedTokenType,
|
|
69
|
+
name: string,
|
|
70
|
+
declaration: TokenDeclaration | Declaration,
|
|
71
|
+
): void => {
|
|
72
|
+
if (target.has(name)) {
|
|
73
|
+
report(
|
|
74
|
+
error(
|
|
75
|
+
"CHIKX2001",
|
|
76
|
+
`Duplicate local ${labelFor(tokenType)} variable "$${name}" in "${file}".`,
|
|
77
|
+
declaration.span,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
target.set(name, {
|
|
83
|
+
name,
|
|
84
|
+
tokenType,
|
|
85
|
+
module: file,
|
|
86
|
+
span: declaration.span,
|
|
87
|
+
declaration,
|
|
88
|
+
origin: { kind: "local" },
|
|
89
|
+
unqualified: true,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
for (const item of ast.items) {
|
|
94
|
+
if (item.kind === "variables") {
|
|
95
|
+
for (const token of item.tokens) add(compile, "compile", token.name, token);
|
|
96
|
+
} else if (item.kind === "runtime") {
|
|
97
|
+
for (const declaration of item.declarations) {
|
|
98
|
+
add(runtime, "runtime", declaration.property, declaration);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const [name, runtimeToken] of runtime) {
|
|
104
|
+
const compileToken = compile.get(name);
|
|
105
|
+
if (compileToken === undefined) continue;
|
|
106
|
+
const later =
|
|
107
|
+
compileToken.span.start <= runtimeToken.span.start ? runtimeToken.span : compileToken.span;
|
|
108
|
+
report(
|
|
109
|
+
error(
|
|
110
|
+
"CHIKX2001",
|
|
111
|
+
`"$${name}" cannot be both a compile-time and a runtime variable in "${file}".`,
|
|
112
|
+
later,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { compile, runtime };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Build both token scopes for one module from its resolved imports.
|
|
122
|
+
*
|
|
123
|
+
* Unqualified imports merge into the `$name` namespace shared by both symbol
|
|
124
|
+
* spaces, with a local definition of either kind taking precedence. Namespaced
|
|
125
|
+
* imports are exposed only through `namespaces`, so `$layout` stays
|
|
126
|
+
* unresolvable while `$layout.spacing` works. Ambiguous unqualified names are
|
|
127
|
+
* CHIKX2001 at the second conflicting `@use`; the first provider is kept in the
|
|
128
|
+
* scope for deterministic downstream behaviour when the caller chooses to
|
|
129
|
+
* continue after errors.
|
|
130
|
+
*/
|
|
131
|
+
export function buildScopes(
|
|
132
|
+
file: string,
|
|
133
|
+
locals: LocalSymbols,
|
|
134
|
+
imports: readonly ResolvedImport[],
|
|
135
|
+
localsFor: (module: string) => LocalSymbols | undefined,
|
|
136
|
+
report: (diagnostic: Diagnostic) => void,
|
|
137
|
+
): { readonly compileScope: TokenScope; readonly runtimeScope: TokenScope } {
|
|
138
|
+
const bindings = collectNamespaceBindings(file, imports, report);
|
|
139
|
+
const unqualified = resolveUnqualified(file, locals, imports, localsFor, report);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
compileScope: buildScope(file, "compile", locals, localsFor, bindings, unqualified),
|
|
143
|
+
runtimeScope: buildScope(file, "runtime", locals, localsFor, bindings, unqualified),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Merge unqualified imports into one shared name table.
|
|
149
|
+
*
|
|
150
|
+
* Compile-time and runtime imports share the `$name` namespace, matching the
|
|
151
|
+
* `$name`/`$name.member` syntax: a single local definition of either kind
|
|
152
|
+
* shadows every unqualified import of that name, and two distinct providers
|
|
153
|
+
* (same or different symbol spaces) are ambiguous. The first provider wins so
|
|
154
|
+
* repeated runs and post-error recovery stay deterministic.
|
|
155
|
+
*/
|
|
156
|
+
function resolveUnqualified(
|
|
157
|
+
file: string,
|
|
158
|
+
locals: LocalSymbols,
|
|
159
|
+
imports: readonly ResolvedImport[],
|
|
160
|
+
localsFor: (module: string) => LocalSymbols | undefined,
|
|
161
|
+
report: (diagnostic: Diagnostic) => void,
|
|
162
|
+
): Map<string, ScopedToken> {
|
|
163
|
+
const providers = new Map<string, UnqualifiedProvider[]>();
|
|
164
|
+
|
|
165
|
+
for (const imported of imports) {
|
|
166
|
+
if (imported.target === undefined || imported.item.alias !== undefined) continue;
|
|
167
|
+
const exported = localsFor(imported.target);
|
|
168
|
+
if (exported === undefined) continue;
|
|
169
|
+
|
|
170
|
+
for (const tokenType of ["compile", "runtime"] as const) {
|
|
171
|
+
for (const [name, definition] of exported[tokenType]) {
|
|
172
|
+
if (locals.compile.has(name) || locals.runtime.has(name)) continue;
|
|
173
|
+
const existing = providers.get(name);
|
|
174
|
+
if (existing === undefined) {
|
|
175
|
+
providers.set(name, [
|
|
176
|
+
{ target: imported.target, tokenType, definition, import: imported },
|
|
177
|
+
]);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (
|
|
181
|
+
existing.some(
|
|
182
|
+
(provider) => provider.target === imported.target && provider.tokenType === tokenType,
|
|
183
|
+
)
|
|
184
|
+
) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
existing.push({ target: imported.target, tokenType, definition, import: imported });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const winners = new Map<string, ScopedToken>();
|
|
193
|
+
for (const [name, list] of providers) {
|
|
194
|
+
const first = list[0];
|
|
195
|
+
if (first === undefined) continue;
|
|
196
|
+
if (list.length > 1) {
|
|
197
|
+
const conflicting = list[1];
|
|
198
|
+
const span =
|
|
199
|
+
conflicting === undefined ? first.import.item.span : conflicting.import.item.span;
|
|
200
|
+
const sources = list
|
|
201
|
+
.map((provider) => `"${provider.target}" (${labelFor(provider.tokenType)})`)
|
|
202
|
+
.join(", ");
|
|
203
|
+
report(
|
|
204
|
+
error(
|
|
205
|
+
"CHIKX2001",
|
|
206
|
+
`Ambiguous unqualified import in "${file}": "$${name}" is exported by ${sources}. Import it with a namespace (@use "..." as <alias>) or define "$${name}" locally to choose one.`,
|
|
207
|
+
span,
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
winners.set(name, importedToken(first.definition, importOrigin(first.import), true));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return winners;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function buildScope(
|
|
218
|
+
file: string,
|
|
219
|
+
kind: ScopedTokenType,
|
|
220
|
+
locals: LocalSymbols,
|
|
221
|
+
localsFor: (module: string) => LocalSymbols | undefined,
|
|
222
|
+
bindings: ReadonlyMap<string, NamespaceBinding>,
|
|
223
|
+
unqualified: ReadonlyMap<string, ScopedToken>,
|
|
224
|
+
): TokenScope {
|
|
225
|
+
const tokens = new Map<string, ScopedToken>(locals[kind]);
|
|
226
|
+
const namespaces = new Map<string, ScopedNamespace>();
|
|
227
|
+
|
|
228
|
+
for (const binding of bindings.values()) {
|
|
229
|
+
const exported = localsFor(binding.target);
|
|
230
|
+
if (exported === undefined) continue;
|
|
231
|
+
const members = new Map<string, ScopedToken>();
|
|
232
|
+
const origin: ImportSymbolOrigin = {
|
|
233
|
+
kind: "import",
|
|
234
|
+
module: binding.target,
|
|
235
|
+
specifier: binding.specifier,
|
|
236
|
+
span: binding.span,
|
|
237
|
+
namespace: binding.namespace,
|
|
238
|
+
};
|
|
239
|
+
for (const [name, definition] of exported[kind]) {
|
|
240
|
+
members.set(name, importedToken(definition, origin, false));
|
|
241
|
+
}
|
|
242
|
+
namespaces.set(binding.namespace, {
|
|
243
|
+
namespace: binding.namespace,
|
|
244
|
+
module: binding.target,
|
|
245
|
+
span: binding.span,
|
|
246
|
+
specifier: binding.specifier,
|
|
247
|
+
members,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
for (const [name, definition] of unqualified) {
|
|
252
|
+
if (definition.tokenType === kind) tokens.set(name, definition);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return { kind, module: file, tokens, namespaces };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function collectNamespaceBindings(
|
|
259
|
+
file: string,
|
|
260
|
+
imports: readonly ResolvedImport[],
|
|
261
|
+
report: (diagnostic: Diagnostic) => void,
|
|
262
|
+
): Map<string, NamespaceBinding> {
|
|
263
|
+
const bindings = new Map<string, NamespaceBinding>();
|
|
264
|
+
|
|
265
|
+
for (const imported of imports) {
|
|
266
|
+
const alias = imported.item.alias;
|
|
267
|
+
if (imported.target === undefined || alias === undefined || alias === "") continue;
|
|
268
|
+
|
|
269
|
+
// The built-in `keyframes` namespace is reserved (ADR-0015): an alias would
|
|
270
|
+
// shadow names that ADR-0015 defines, so it is a CHIKX2001 instead of a
|
|
271
|
+
// second, competing namespace.
|
|
272
|
+
if (alias === KEYFRAMES_NAMESPACE) {
|
|
273
|
+
report(
|
|
274
|
+
error(
|
|
275
|
+
"CHIKX2001",
|
|
276
|
+
`"$${alias}" is a built-in namespace (ADR-0015) and cannot be used as an @use alias in "${file}".`,
|
|
277
|
+
imported.item.span,
|
|
278
|
+
),
|
|
279
|
+
);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// The built-in `@group.<name>` construct owns the `group` directive name
|
|
284
|
+
// (ADR-0017 item 5, §3.6), so an alias of that name is rejected the same
|
|
285
|
+
// way: CHIKX2001 at the `@use`, no namespace, and the edge itself still
|
|
286
|
+
// resolves.
|
|
287
|
+
if (alias === GROUP_DIRECTIVE) {
|
|
288
|
+
report(
|
|
289
|
+
error(
|
|
290
|
+
"CHIKX2001",
|
|
291
|
+
`"${alias}" is a reserved directive name (ADR-0017) and cannot be used as an @use alias in "${file}".`,
|
|
292
|
+
imported.item.span,
|
|
293
|
+
),
|
|
294
|
+
);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const existing = bindings.get(alias);
|
|
299
|
+
if (existing === undefined) {
|
|
300
|
+
bindings.set(alias, {
|
|
301
|
+
namespace: alias,
|
|
302
|
+
target: imported.target,
|
|
303
|
+
span: imported.item.span,
|
|
304
|
+
specifier: imported.specifier,
|
|
305
|
+
});
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (existing.target !== imported.target) {
|
|
310
|
+
report(
|
|
311
|
+
error(
|
|
312
|
+
"CHIKX2001",
|
|
313
|
+
`Duplicate namespace "${alias}" in "${file}" refers to both "${existing.target}" and "${imported.target}".`,
|
|
314
|
+
imported.item.span,
|
|
315
|
+
),
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return bindings;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function importedToken(
|
|
324
|
+
definition: ScopedToken,
|
|
325
|
+
origin: ImportSymbolOrigin,
|
|
326
|
+
unqualified: boolean,
|
|
327
|
+
): ScopedToken {
|
|
328
|
+
return { ...definition, origin, unqualified };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function importOrigin(imported: ResolvedImport): ImportSymbolOrigin {
|
|
332
|
+
return {
|
|
333
|
+
kind: "import",
|
|
334
|
+
module: imported.target ?? imported.specifier,
|
|
335
|
+
specifier: imported.specifier,
|
|
336
|
+
span: imported.item.span,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function labelFor(tokenType: ScopedTokenType): string {
|
|
341
|
+
return tokenType === "compile" ? "compile-time" : "runtime";
|
|
342
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public shapes produced by the module resolver.
|
|
3
|
+
*
|
|
4
|
+
* These types are the A08 handoff: a scope tells substitution where every
|
|
5
|
+
* visible symbol is defined, how it was brought into the file, and whether it
|
|
6
|
+
* may be referenced without a namespace. All module identifiers are canonical
|
|
7
|
+
* paths as returned by {@link ModuleHost.canonicalize}, normalized to forward
|
|
8
|
+
* slashes.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
Declaration,
|
|
13
|
+
GroupDefinition,
|
|
14
|
+
Stylesheet,
|
|
15
|
+
TokenDeclaration,
|
|
16
|
+
UseImport,
|
|
17
|
+
} from "../types/ast.js";
|
|
18
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
19
|
+
import type { Span } from "../types/span.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolver-internal record of one resolved `@use` statement.
|
|
23
|
+
*
|
|
24
|
+
* Not part of the facade: `target` is present only when the import passed
|
|
25
|
+
* containment and existence checks, so later passes can distinguish a broken
|
|
26
|
+
* edge (already diagnosed) from a real dependency.
|
|
27
|
+
*/
|
|
28
|
+
export interface ResolvedImport {
|
|
29
|
+
/** The authored AST node. */
|
|
30
|
+
readonly item: UseImport;
|
|
31
|
+
/** Specifier after CSS string-escape decoding. */
|
|
32
|
+
readonly specifier: string;
|
|
33
|
+
/** Canonical target path when resolution succeeded. */
|
|
34
|
+
readonly target?: string;
|
|
35
|
+
/**
|
|
36
|
+
* `true` when the import carried the `styles` clause, so the edge also merges
|
|
37
|
+
* the target's rules into the importing build (ADR-0014). Token-only imports
|
|
38
|
+
* are `false`.
|
|
39
|
+
*/
|
|
40
|
+
readonly styles: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The two symbol spaces a Chikx module can export. */
|
|
44
|
+
export type ScopedTokenType = "compile" | "runtime";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One `@keyframes` name referenceable as `$keyframes.<name>` in a module.
|
|
48
|
+
*
|
|
49
|
+
* Names are not symbols with a value: substitution splices {@link name} as
|
|
50
|
+
* literal CSS text, and the same authored text resolves identically in every
|
|
51
|
+
* module that can see it (ADR-0015).
|
|
52
|
+
*/
|
|
53
|
+
export interface KeyframeName {
|
|
54
|
+
/** Authored keyframe name, a plain identifier (no quotes or escapes). */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
/** Canonical path of the module whose `@keyframes` block declared it. */
|
|
57
|
+
readonly module: string;
|
|
58
|
+
/** Span of the declaring `@keyframes` at-rule in that module. */
|
|
59
|
+
readonly span: Span;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* One `@group.<name>` definition visible to a module (ADR-0017).
|
|
64
|
+
*
|
|
65
|
+
* The definition stays in its declaring module: {@link module} and
|
|
66
|
+
* {@link definition} always point at the module that authored it, so expansion
|
|
67
|
+
* can attribute `$refs` to that module (SPECIFICATION.md §6.1).
|
|
68
|
+
*/
|
|
69
|
+
export interface VisibleGroup {
|
|
70
|
+
/** Group name without the `@group.` prefix, matched exactly and case-sensitively. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** Canonical path of the module whose `@group` block declares it. */
|
|
73
|
+
readonly module: string;
|
|
74
|
+
/** Span of the declaring `@group` at-rule in that module. */
|
|
75
|
+
readonly span: Span;
|
|
76
|
+
/** The declaring definition node, carrying the defaults and their authored spans. */
|
|
77
|
+
readonly definition: GroupDefinition;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* How one group name resolves from a module's point of view (ADR-0017 item 5).
|
|
82
|
+
*
|
|
83
|
+
* Both variants stay inert data for the expansion pass: it splices
|
|
84
|
+
* {@link VisibleGroup.definition} for `resolved` and reports CHIKX2001 at the
|
|
85
|
+
* use site for `ambiguous` (plan G3). Ambiguity is not a resolver diagnostic
|
|
86
|
+
* because only a use site makes it actionable.
|
|
87
|
+
*/
|
|
88
|
+
export type GroupResolution =
|
|
89
|
+
| {
|
|
90
|
+
/** Exactly one addressable definition: local first, otherwise a single import. */
|
|
91
|
+
readonly kind: "resolved";
|
|
92
|
+
readonly group: VisibleGroup;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
/** Two or more imported definitions and no local one. */
|
|
96
|
+
readonly kind: "ambiguous";
|
|
97
|
+
/** The contested group name. */
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/** Distinct visible definitions in traversal order; the message names their modules. */
|
|
100
|
+
readonly candidates: readonly VisibleGroup[];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Origin of a symbol declared in the scope's own file. */
|
|
104
|
+
export interface LocalSymbolOrigin {
|
|
105
|
+
readonly kind: "local";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Origin of a symbol reached through a `@use` statement. */
|
|
109
|
+
export interface ImportSymbolOrigin {
|
|
110
|
+
readonly kind: "import";
|
|
111
|
+
/** Canonical path of the module that declares the symbol. */
|
|
112
|
+
readonly module: string;
|
|
113
|
+
/** Import specifier after CSS string-escape decoding, as authored otherwise. */
|
|
114
|
+
readonly specifier: string;
|
|
115
|
+
/** Span of the `@use` statement in the importing file. */
|
|
116
|
+
readonly span: Span;
|
|
117
|
+
/** Namespace alias when the import was written `as alias`; absent otherwise. */
|
|
118
|
+
readonly namespace?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** How a visible symbol entered a token scope. */
|
|
122
|
+
export type SymbolOrigin = LocalSymbolOrigin | ImportSymbolOrigin;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* One visible token definition from the substitution point of view.
|
|
126
|
+
*
|
|
127
|
+
* The definition itself stays in its declaring module: {@link module} and
|
|
128
|
+
* {@link declaration} always point at the module that authored the value, so a
|
|
129
|
+
* local override never mutates an imported module (SPECIFICATION.md §6.1).
|
|
130
|
+
*/
|
|
131
|
+
export interface ScopedToken {
|
|
132
|
+
/** Symbol name without the `$` sigil, exactly as authored. */
|
|
133
|
+
readonly name: string;
|
|
134
|
+
/** Which symbol space the definition belongs to. */
|
|
135
|
+
readonly tokenType: ScopedTokenType;
|
|
136
|
+
/** Canonical path of the module that declares this symbol. */
|
|
137
|
+
readonly module: string;
|
|
138
|
+
/** Span of the declaring `TokenDeclaration` or `Declaration`. */
|
|
139
|
+
readonly span: Span;
|
|
140
|
+
/**
|
|
141
|
+
* The declaring AST node, carrying the raw value, optional parsed value
|
|
142
|
+
* tokens and runtime variants. Immutable by contract.
|
|
143
|
+
*/
|
|
144
|
+
readonly declaration: TokenDeclaration | Declaration;
|
|
145
|
+
/** Whether the symbol is local or imported, and via which `@use`. */
|
|
146
|
+
readonly origin: SymbolOrigin;
|
|
147
|
+
/**
|
|
148
|
+
* Whether a bare `$name` reference may resolve to this symbol. Always `true`
|
|
149
|
+
* for locals and unqualified imports; `false` for namespaced members, which
|
|
150
|
+
* are reachable only as `$namespace.name`.
|
|
151
|
+
*/
|
|
152
|
+
readonly unqualified: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The members one `@use "... as namespace"` statement exposes. */
|
|
156
|
+
export interface ScopedNamespace {
|
|
157
|
+
/** Authored alias without the `$` sigil. */
|
|
158
|
+
readonly namespace: string;
|
|
159
|
+
/** Canonical path of the imported module. */
|
|
160
|
+
readonly module: string;
|
|
161
|
+
/** Span of the `@use` statement in the importing file. */
|
|
162
|
+
readonly span: Span;
|
|
163
|
+
/** Decoded import specifier as authored otherwise. */
|
|
164
|
+
readonly specifier: string;
|
|
165
|
+
/**
|
|
166
|
+
* Symbols exported by the target module's own `@variables`/`@runtime`
|
|
167
|
+
* blocks. There is no transitive re-export: member definitions are always
|
|
168
|
+
* local to {@link module}.
|
|
169
|
+
*/
|
|
170
|
+
readonly members: ReadonlyMap<string, ScopedToken>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Visible symbols of one module for one symbol space.
|
|
175
|
+
*
|
|
176
|
+
* `tokens` holds the names a bare `$name` reference may use after local
|
|
177
|
+
* definitions shadow unqualified imports; `namespaces` holds every namespaced
|
|
178
|
+
* import, with `members` filtered to this scope's {@link kind}.
|
|
179
|
+
*/
|
|
180
|
+
export interface TokenScope {
|
|
181
|
+
/** The symbol space this scope exposes. */
|
|
182
|
+
readonly kind: ScopedTokenType;
|
|
183
|
+
/** Canonical path of the module whose source defines this scope. */
|
|
184
|
+
readonly module: string;
|
|
185
|
+
/** Unqualified, directly referenceable symbols. */
|
|
186
|
+
readonly tokens: ReadonlyMap<string, ScopedToken>;
|
|
187
|
+
/** Namespaced imports, addressable as `$namespace.member`. */
|
|
188
|
+
readonly namespaces: ReadonlyMap<string, ScopedNamespace>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** One parsed and validated module of the graph. */
|
|
192
|
+
export interface ModuleRecord {
|
|
193
|
+
/** Canonical path used as the module cache key and graph key. */
|
|
194
|
+
readonly file: string;
|
|
195
|
+
/** Immutable AST produced by `parseTokens`. */
|
|
196
|
+
readonly ast: Stylesheet;
|
|
197
|
+
/**
|
|
198
|
+
* Canonical paths this module imports, deduplicated in first-authored
|
|
199
|
+
* `@use` order. Includes token-only and rule-merge (`styles`) imports.
|
|
200
|
+
* Failed imports are reported as diagnostics and omitted.
|
|
201
|
+
*/
|
|
202
|
+
readonly dependencies: readonly string[];
|
|
203
|
+
/**
|
|
204
|
+
* Canonical paths imported with the `styles` clause, deduplicated in
|
|
205
|
+
* first-authored `@use` order (ADR-0014). These modules contribute their rules
|
|
206
|
+
* to a consuming build; `dependencies` is the superset used for scopes and
|
|
207
|
+
* cycle detection.
|
|
208
|
+
*/
|
|
209
|
+
readonly styleDependencies: readonly string[];
|
|
210
|
+
/** Canonical paths of modules importing this one, sorted for determinism. */
|
|
211
|
+
readonly importedBy: readonly string[];
|
|
212
|
+
/** Compile-time (`@variables`) scope, including namespace member maps. */
|
|
213
|
+
readonly compileScope: TokenScope;
|
|
214
|
+
/** Runtime (`@runtime`) scope, including namespace member maps. */
|
|
215
|
+
readonly runtimeScope: TokenScope;
|
|
216
|
+
/**
|
|
217
|
+
* `@keyframes` names visible to this module as `$keyframes.<name>` (ADR-0015):
|
|
218
|
+
* its own top-level blocks plus those of every module reached through a
|
|
219
|
+
* `styles` `@use` edge (ADR-0014), because that is exactly the CSS this module's
|
|
220
|
+
* build emits. Token-only imports contribute nothing.
|
|
221
|
+
*/
|
|
222
|
+
readonly keyframes: ReadonlyMap<string, KeyframeName>;
|
|
223
|
+
/**
|
|
224
|
+
* `@group.<name>` definitions visible to this module (ADR-0017): its own
|
|
225
|
+
* top-level definitions plus those of every module reached through a `styles`
|
|
226
|
+
* `@use` edge (ADR-0014), transitively in authored order. Token-only imports
|
|
227
|
+
* contribute no groups.
|
|
228
|
+
*
|
|
229
|
+
* A local definition shadows imported definitions of the same name without a
|
|
230
|
+
* diagnostic; two imported definitions with no local one are
|
|
231
|
+
* {@link GroupResolution} `ambiguous` and stay inert until a use site reports
|
|
232
|
+
* CHIKX2001 (plan G3). The map is resolver-internal data: it carries no
|
|
233
|
+
* expansion state and nothing is emitted for a definition.
|
|
234
|
+
*/
|
|
235
|
+
readonly groups: ReadonlyMap<string, GroupResolution>;
|
|
236
|
+
/**
|
|
237
|
+
* Whether the module contains top-level stylesheet rules or native at-rules.
|
|
238
|
+
* Token-only modules report `false` so P4/P5 can skip artifact emission
|
|
239
|
+
* (SPECIFICATION.md §6.1).
|
|
240
|
+
*/
|
|
241
|
+
readonly hasRules: boolean;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Result of {@link buildModuleGraph}. */
|
|
245
|
+
export interface ModuleGraph {
|
|
246
|
+
/** Every successfully loaded module keyed by canonical path. */
|
|
247
|
+
readonly modules: ReadonlyMap<string, ModuleRecord>;
|
|
248
|
+
/**
|
|
249
|
+
* Deterministic topological order: dependencies before importers, ties by
|
|
250
|
+
* canonical path. Modules participating in an import cycle are omitted after
|
|
251
|
+
* their CHIKX2001 diagnostic; every other loaded module appears exactly once.
|
|
252
|
+
*/
|
|
253
|
+
readonly order: readonly string[];
|
|
254
|
+
/**
|
|
255
|
+
* Parse diagnostics followed by resolver diagnostics, stably sorted by file,
|
|
256
|
+
* offset and code so identical inputs always yield identical output.
|
|
257
|
+
*/
|
|
258
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
259
|
+
}
|