@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
package/src/index.ts
ADDED
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@chikx/compiler` public entry point.
|
|
3
|
+
*
|
|
4
|
+
* The frozen contracts of task A02 live in `./types/*`. `parse`, `compile`,
|
|
5
|
+
* `compileProject` and `planOutputs` are wired here; the compiler core remains
|
|
6
|
+
* pure and filesystem-free through an injected {@link ModuleHost}. `compile` is
|
|
7
|
+
* the batteries-included single-source entry point and uses the default Node
|
|
8
|
+
* host from `./host/node.js`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { emitCss } from "./emitter/index.js";
|
|
12
|
+
import { createNodeHost } from "./host/node.js";
|
|
13
|
+
import { stylesheetIr } from "./ir/factories.js";
|
|
14
|
+
import type { StylesheetIr } from "./ir/types.js";
|
|
15
|
+
import { tokenize } from "./lexer/index.js";
|
|
16
|
+
import type { TokenizeResult } from "./lexer/index.js";
|
|
17
|
+
import { expandGroupUseSites, groupRuns, lower } from "./lowering/index.js";
|
|
18
|
+
import { generateClassMap, mergeClassTables, renameClasses } from "./naming/index.js";
|
|
19
|
+
import type { ClassMapOptions, ClassTableSource } from "./naming/index.js";
|
|
20
|
+
import { stylesheetImportSpecifier } from "./output/import-path.js";
|
|
21
|
+
import { planOutputs } from "./output/index.js";
|
|
22
|
+
import type { OutputPlannerContext, OutputPlannerHost } from "./output/index.js";
|
|
23
|
+
import {
|
|
24
|
+
basenamePath,
|
|
25
|
+
dirnamePath,
|
|
26
|
+
isAbsolutePath,
|
|
27
|
+
joinPath,
|
|
28
|
+
normalizePath,
|
|
29
|
+
relativePath,
|
|
30
|
+
} from "./output/paths.js";
|
|
31
|
+
import { defaultSetupFor } from "./output/resolve.js";
|
|
32
|
+
import { parseTokens } from "./parser/index.js";
|
|
33
|
+
import { buildModuleGraph, styleModuleOrder } from "./resolver/index.js";
|
|
34
|
+
import type { GroupResolution, ModuleGraph } from "./resolver/index.js";
|
|
35
|
+
import { flattenIr } from "./selectors/index.js";
|
|
36
|
+
import { decodeSetupList, decodeSetupScalar } from "./setup-list.js";
|
|
37
|
+
import type { Setting, Stylesheet } from "./types/ast.js";
|
|
38
|
+
import type { Diagnostic } from "./types/diagnostics.js";
|
|
39
|
+
import { error } from "./types/diagnostics.js";
|
|
40
|
+
import type {
|
|
41
|
+
CompileOptions,
|
|
42
|
+
CompileProjectOptions,
|
|
43
|
+
MediaGroupingMode,
|
|
44
|
+
ModuleHost,
|
|
45
|
+
OutputOptions,
|
|
46
|
+
ParseOptions,
|
|
47
|
+
ProjectConfig,
|
|
48
|
+
ResolvedSetup,
|
|
49
|
+
} from "./types/options.js";
|
|
50
|
+
import type { ClassMap, CompileResult, ParseResult, PlanOutputsInput } from "./types/result.js";
|
|
51
|
+
import { emitRuntimeTokens, substitute } from "./variables/index.js";
|
|
52
|
+
|
|
53
|
+
export type {
|
|
54
|
+
AliasDeclaration,
|
|
55
|
+
BlockItem,
|
|
56
|
+
ConditionalBlock,
|
|
57
|
+
ConditionalBlockItem,
|
|
58
|
+
Declaration,
|
|
59
|
+
GroupDefinition,
|
|
60
|
+
GroupUseSite,
|
|
61
|
+
MediaTypesBlock,
|
|
62
|
+
Modifier,
|
|
63
|
+
NativeAtRule,
|
|
64
|
+
Rule,
|
|
65
|
+
RuntimeBlock,
|
|
66
|
+
Setting,
|
|
67
|
+
SetupBlock,
|
|
68
|
+
Stylesheet,
|
|
69
|
+
StylesheetItem,
|
|
70
|
+
TokenDeclaration,
|
|
71
|
+
UseImport,
|
|
72
|
+
Variant,
|
|
73
|
+
VariablesBlock,
|
|
74
|
+
} from "./types/ast.js";
|
|
75
|
+
export type {
|
|
76
|
+
Diagnostic,
|
|
77
|
+
DiagnosticCode,
|
|
78
|
+
DiagnosticCodeInfo,
|
|
79
|
+
DiagnosticFamily,
|
|
80
|
+
DiagnosticSeverity,
|
|
81
|
+
ReservedDiagnosticCode,
|
|
82
|
+
} from "./types/diagnostics.js";
|
|
83
|
+
export { DIAGNOSTIC_CODES, error, warning } from "./types/diagnostics.js";
|
|
84
|
+
export type {
|
|
85
|
+
CliOutputOverrides,
|
|
86
|
+
CompileOptions,
|
|
87
|
+
CompileProjectOptions,
|
|
88
|
+
CompilerConfig,
|
|
89
|
+
MediaGroupingMode,
|
|
90
|
+
ModuleHost,
|
|
91
|
+
NamingOptions,
|
|
92
|
+
NamingStrategy,
|
|
93
|
+
OutputOptions,
|
|
94
|
+
ParseOptions,
|
|
95
|
+
ProjectConfig,
|
|
96
|
+
ResolvedSetup,
|
|
97
|
+
} from "./types/options.js";
|
|
98
|
+
export type {
|
|
99
|
+
ClassMap,
|
|
100
|
+
CompileResult,
|
|
101
|
+
ManifestEntry,
|
|
102
|
+
OutputKind,
|
|
103
|
+
OutputPlan,
|
|
104
|
+
ParseResult,
|
|
105
|
+
PlanOutputs,
|
|
106
|
+
PlanOutputsInput,
|
|
107
|
+
PlanOutputsResult,
|
|
108
|
+
PlannedOutput,
|
|
109
|
+
} from "./types/result.js";
|
|
110
|
+
export type { Span } from "./types/span.js";
|
|
111
|
+
export type { Token, TokenKind } from "./types/token.js";
|
|
112
|
+
|
|
113
|
+
/** Tokenize Chikx source into a lossless token stream plus lexical diagnostics. */
|
|
114
|
+
export { tokenize };
|
|
115
|
+
/** Result of {@link tokenize}: tokens in source order plus lexical diagnostics. */
|
|
116
|
+
export type { TokenizeResult };
|
|
117
|
+
/** Default Node/Bun filesystem host used by {@link compile}. */
|
|
118
|
+
export { createNodeHost };
|
|
119
|
+
/** Optional host and cross-entry target context accepted by {@link planOutputs}. */
|
|
120
|
+
export type { OutputPlannerContext, OutputPlannerHost };
|
|
121
|
+
/** Validate and return a complete output plan without writing. */
|
|
122
|
+
export { planOutputs };
|
|
123
|
+
/** Decode a comma-separated `@setup` value list and its per-item diagnostics. */
|
|
124
|
+
export { decodeSetupList, decodeSetupScalar } from "./setup-list.js";
|
|
125
|
+
/** One decoded list item and the decoder result (ADR-0019). */
|
|
126
|
+
export type { SetupListEntry, SetupListResult } from "./setup-list.js";
|
|
127
|
+
/** Canonical source formatting (pure parse→print; errors return the input). */
|
|
128
|
+
export { format } from "./formatter/index.js";
|
|
129
|
+
/** Result of {@link format}: canonical text plus parse diagnostics. */
|
|
130
|
+
export type { FormatResult } from "./formatter/index.js";
|
|
131
|
+
|
|
132
|
+
/** Every `@setup` key understood by `compile` and `compileProject`. */
|
|
133
|
+
const SETUP_KEYS: ReadonlySet<string> = new Set([
|
|
134
|
+
"prefix",
|
|
135
|
+
"css-dir",
|
|
136
|
+
"css-name",
|
|
137
|
+
"map-dir",
|
|
138
|
+
"map-name",
|
|
139
|
+
"emit-css",
|
|
140
|
+
"emit-map",
|
|
141
|
+
"map-types",
|
|
142
|
+
"emit-types",
|
|
143
|
+
"source-map",
|
|
144
|
+
"minify",
|
|
145
|
+
"module",
|
|
146
|
+
"map-inherit",
|
|
147
|
+
"import-css",
|
|
148
|
+
"media-grouping",
|
|
149
|
+
]);
|
|
150
|
+
|
|
151
|
+
const BOOLEAN_SETUP_KEYS: ReadonlySet<string> = new Set([
|
|
152
|
+
"emit-css",
|
|
153
|
+
"emit-map",
|
|
154
|
+
"map-types",
|
|
155
|
+
"emit-types",
|
|
156
|
+
"source-map",
|
|
157
|
+
"minify",
|
|
158
|
+
"map-inherit",
|
|
159
|
+
"import-css",
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
interface DecodedSetup {
|
|
163
|
+
/** Authored file-level values; missing keys mean "not authored". */
|
|
164
|
+
readonly values: Partial<MutableSetup>;
|
|
165
|
+
/**
|
|
166
|
+
* `module: true` marker (ADR-0014): this file is a rule-bearing module, so
|
|
167
|
+
* its own build suppresses CSS, map and type artifacts unless the file authors
|
|
168
|
+
* those keys explicitly.
|
|
169
|
+
*/
|
|
170
|
+
readonly moduleOnly: boolean;
|
|
171
|
+
/** File-level `media-grouping` override (ADR-0024), when authored validly. */
|
|
172
|
+
readonly mediaGrouping?: MediaGroupingMode;
|
|
173
|
+
/** CHIKX1001 diagnostics for unknown keys, duplicates and invalid values. */
|
|
174
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Mutable view used while merging defaults, project config, file setup and API. */
|
|
178
|
+
type MutableSetup = { -readonly [Key in keyof ResolvedSetup]: ResolvedSetup[Key] };
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Tolerantly parse Chikx source into an immutable AST plus diagnostics,
|
|
182
|
+
* recovering at safe statement boundaries for editor use.
|
|
183
|
+
*
|
|
184
|
+
* Pipeline: {@link tokenize} then the A04 `parseTokens` stage. Diagnostics are
|
|
185
|
+
* merged in a stable order — **lexical diagnostics first** (emitted while
|
|
186
|
+
* tokenizing), then syntactic diagnostics — because both use the CHIKX1xxx
|
|
187
|
+
* family and each stage already reports in source order. Neither stage throws,
|
|
188
|
+
* so a partial `Stylesheet` is always returned.
|
|
189
|
+
*/
|
|
190
|
+
export function parse(source: string, options: ParseOptions): ParseResult {
|
|
191
|
+
const lexed = tokenize(source, options.file);
|
|
192
|
+
const parsed = parseTokens(lexed.tokens, options.file);
|
|
193
|
+
return Object.freeze({
|
|
194
|
+
ast: parsed.ast,
|
|
195
|
+
diagnostics: Object.freeze([...lexed.diagnostics, ...parsed.diagnostics]),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Compile one Chikx source string to CSS, JS class map, declarations and/or a
|
|
201
|
+
* source map, returning artifacts and diagnostics without writing files.
|
|
202
|
+
*
|
|
203
|
+
* The pipeline is `parse` → optional module graph → (`expandGroupUseSites` →
|
|
204
|
+
* `lower` → `substitute` → `renameClasses` per style-imported module) →
|
|
205
|
+
* `expandGroupUseSites` → `lower` → `substitute` → `renameClasses` for the
|
|
206
|
+
* entry → `mergeClassTables` → `emitRuntimeTokens` → `groupRuns` → `flattenIr`
|
|
207
|
+
* → `emitCss` → `planOutputs` → `generateClassMap`.
|
|
208
|
+
* Rule-bearing `styles` imports (ADR-0014) contribute their rules first, in
|
|
209
|
+
* depth-first `@use` order, each renamed with the module's own `@setup` prefix;
|
|
210
|
+
* the importing build then has one merged class map and declaration file. A
|
|
211
|
+
* module that authors `@setup { map-inherit: false; }` (ADR-0020) still merges
|
|
212
|
+
* its rules but keeps its bindings out of the importer's map and declarations.
|
|
213
|
+
* A file that authors `@setup { import-css: true; }` (ADR-0021) gets one
|
|
214
|
+
* side-effect import of its planned stylesheet at the top of the JS map; without
|
|
215
|
+
* it (the default) the map stays import-free for plain Node.
|
|
216
|
+
* File `@setup` values are decoded here, then explicit `CompileOptions` output
|
|
217
|
+
* fields override them (API/CLI precedence). Prefix precedence is
|
|
218
|
+
* `options.prefix` → `options.naming.prefix` → file `@setup prefix` → `""`;
|
|
219
|
+
* strategy `none` disables prefixing. `@setup { module: true }` suppresses this
|
|
220
|
+
* file's own CSS, map, types and CSS import unless those keys are authored.
|
|
221
|
+
*
|
|
222
|
+
* `options.workspaceRoot` is the containment root and the Node host's root. It
|
|
223
|
+
* defaults to `process.cwd()` at call time inside {@link createNodeHost}. When
|
|
224
|
+
* the source has no `@use`, a memory-only single-file graph is built so runtime
|
|
225
|
+
* token and variable passes still see the entry; no filesystem is read for the
|
|
226
|
+
* source itself.
|
|
227
|
+
*/
|
|
228
|
+
export async function compile(source: string, options: CompileOptions): Promise<CompileResult> {
|
|
229
|
+
const parsed = parse(source, { file: options.file });
|
|
230
|
+
const nodeHost = createNodeHost(options.workspaceRoot);
|
|
231
|
+
const workspaceRoot = normalizePath(nodeHost.workspaceRoot());
|
|
232
|
+
const entryAbsolute = normalizePath(
|
|
233
|
+
isAbsolutePath(options.file) ? options.file : joinPath(workspaceRoot, options.file),
|
|
234
|
+
);
|
|
235
|
+
const canonicalEntry = normalizePath(nodeHost.canonicalize(entryAbsolute));
|
|
236
|
+
const decoded = decodeSetup(parsed.ast);
|
|
237
|
+
const hasUse = parsed.ast.items.some((item) => item.kind === "use");
|
|
238
|
+
|
|
239
|
+
let graph: ModuleGraph;
|
|
240
|
+
let ast = parsed.ast;
|
|
241
|
+
let entryKey = canonicalEntry;
|
|
242
|
+
let baseDiagnostics: readonly Diagnostic[];
|
|
243
|
+
let sourceTexts: ReadonlyMap<string, string>;
|
|
244
|
+
|
|
245
|
+
if (hasUse) {
|
|
246
|
+
const recorded = createRecordingHost(withEntrySource(nodeHost, entryAbsolute, source));
|
|
247
|
+
sourceTexts = recorded.sources;
|
|
248
|
+
graph = await buildModuleGraph([entryAbsolute], recorded.host, options);
|
|
249
|
+
const record = graph.modules.get(canonicalEntry);
|
|
250
|
+
if (record !== undefined) ast = record.ast;
|
|
251
|
+
baseDiagnostics =
|
|
252
|
+
record === undefined
|
|
253
|
+
? [...parsed.diagnostics, ...graph.diagnostics]
|
|
254
|
+
: diagnosticsForEntry(graph, canonicalEntry);
|
|
255
|
+
} else {
|
|
256
|
+
const recorded = createRecordingHost(createMemoryHost(source, entryAbsolute, workspaceRoot));
|
|
257
|
+
sourceTexts = recorded.sources;
|
|
258
|
+
graph = await buildModuleGraph([entryAbsolute], recorded.host, options);
|
|
259
|
+
entryKey = entryAbsolute;
|
|
260
|
+
const record = graph.modules.get(entryKey);
|
|
261
|
+
if (record !== undefined) ast = record.ast;
|
|
262
|
+
baseDiagnostics = singleFileDiagnostics(
|
|
263
|
+
parsed.diagnostics,
|
|
264
|
+
diagnosticsForEntry(graph, entryKey),
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const setup = buildCompileSetup(options.file, options, decoded);
|
|
269
|
+
const sourceFile = sourcePathFor(entryAbsolute, workspaceRoot, options.file);
|
|
270
|
+
const passOptions: CompileOptions = { ...options, file: sourceFile };
|
|
271
|
+
|
|
272
|
+
return compileEntry({
|
|
273
|
+
ast,
|
|
274
|
+
entryKey,
|
|
275
|
+
sourceFile,
|
|
276
|
+
graph,
|
|
277
|
+
setup,
|
|
278
|
+
prefix: setup.prefix,
|
|
279
|
+
options: passOptions,
|
|
280
|
+
mediaGrouping: decoded.mediaGrouping ?? options.mediaGrouping ?? "safe",
|
|
281
|
+
workspaceRoot,
|
|
282
|
+
host: nodeHost,
|
|
283
|
+
sourceTexts,
|
|
284
|
+
baseDiagnostics,
|
|
285
|
+
setupDiagnostics: decoded.diagnostics,
|
|
286
|
+
...(options.mapInherit === undefined ? {} : { moduleMapInherit: options.mapInherit }),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Resolve modules for several entries through an injected host and compile each
|
|
292
|
+
* entry with one shared module graph.
|
|
293
|
+
*
|
|
294
|
+
* Project-level `options.output` and `options.naming` form the project layer;
|
|
295
|
+
* file `@setup` values override them. `options.configFile`/`projectRoot` are
|
|
296
|
+
* reserved for the P5 project loader and are not read here. The returned record
|
|
297
|
+
* is keyed by the entry strings exactly as supplied.
|
|
298
|
+
*/
|
|
299
|
+
export async function compileProject(
|
|
300
|
+
entries: string[],
|
|
301
|
+
host: ModuleHost,
|
|
302
|
+
options: CompileProjectOptions,
|
|
303
|
+
): Promise<Record<string, CompileResult>> {
|
|
304
|
+
const workspaceRoot = normalizePath(options.projectRoot ?? host.workspaceRoot());
|
|
305
|
+
const projectHost: ModuleHost =
|
|
306
|
+
options.projectRoot === undefined
|
|
307
|
+
? host
|
|
308
|
+
: {
|
|
309
|
+
readFile: (path) => host.readFile(path),
|
|
310
|
+
fileExists: (path) => host.fileExists(path),
|
|
311
|
+
canonicalize: (path) => host.canonicalize(path),
|
|
312
|
+
resolvePath: (from, to) => host.resolvePath(from, to),
|
|
313
|
+
workspaceRoot: () => workspaceRoot,
|
|
314
|
+
};
|
|
315
|
+
const absoluteEntries = entries.map((entry) =>
|
|
316
|
+
normalizePath(isAbsolutePath(entry) ? entry : joinPath(workspaceRoot, entry)),
|
|
317
|
+
);
|
|
318
|
+
const graphOptions: CompileOptions = {
|
|
319
|
+
file: absoluteEntries[0] ?? "",
|
|
320
|
+
...(options.media === undefined ? {} : { media: options.media }),
|
|
321
|
+
};
|
|
322
|
+
const recorded = createRecordingHost(projectHost);
|
|
323
|
+
const graph = await buildModuleGraph(absoluteEntries, recorded.host, graphOptions);
|
|
324
|
+
const projectConfig = projectDirectoryConfig(options.output);
|
|
325
|
+
const results: Record<string, CompileResult> = {};
|
|
326
|
+
|
|
327
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
328
|
+
const entry = entries[index] ?? "";
|
|
329
|
+
const absolute = absoluteEntries[index] ?? entry;
|
|
330
|
+
const canonical = normalizePath(projectHost.canonicalize(absolute));
|
|
331
|
+
const record = graph.modules.get(canonical);
|
|
332
|
+
const sourceFile = sourcePathFor(absolute, workspaceRoot, entry);
|
|
333
|
+
|
|
334
|
+
if (record === undefined) {
|
|
335
|
+
results[entry] = emptyCompileResult(
|
|
336
|
+
graph.diagnostics.filter((diagnostic) => normalizePath(diagnostic.span.file) === canonical),
|
|
337
|
+
);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const decoded = decodeSetup(record.ast);
|
|
342
|
+
const setup = buildProjectSetup(sourceFile, options, decoded);
|
|
343
|
+
const passOptions: CompileOptions = { ...options, file: sourceFile };
|
|
344
|
+
results[entry] = compileEntry({
|
|
345
|
+
ast: record.ast,
|
|
346
|
+
entryKey: canonical,
|
|
347
|
+
sourceFile,
|
|
348
|
+
graph,
|
|
349
|
+
setup,
|
|
350
|
+
...(projectConfig === undefined ? {} : { projectConfig }),
|
|
351
|
+
prefix: setup.prefix,
|
|
352
|
+
options: passOptions,
|
|
353
|
+
mediaGrouping: decoded.mediaGrouping ?? options.mediaGrouping ?? "safe",
|
|
354
|
+
workspaceRoot,
|
|
355
|
+
host: projectHost,
|
|
356
|
+
sourceTexts: recorded.sources,
|
|
357
|
+
baseDiagnostics: diagnosticsForEntry(graph, canonical),
|
|
358
|
+
setupDiagnostics: decoded.diagnostics,
|
|
359
|
+
...(options.output?.mapInherit === undefined
|
|
360
|
+
? {}
|
|
361
|
+
: { moduleMapInherit: options.output.mapInherit }),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return results;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface CompileEntryInput {
|
|
369
|
+
readonly ast: Stylesheet;
|
|
370
|
+
/** Canonical graph key for the entry module. */
|
|
371
|
+
readonly entryKey: string;
|
|
372
|
+
/** Workspace-relative POSIX source path used in diagnostics and plans. */
|
|
373
|
+
readonly sourceFile: string;
|
|
374
|
+
readonly graph: ModuleGraph;
|
|
375
|
+
readonly setup: ResolvedSetup;
|
|
376
|
+
/** Project-level config used only for output-directory provenance. */
|
|
377
|
+
readonly projectConfig?: ProjectConfig;
|
|
378
|
+
/** Effective class/runtime prefix after API and file precedence. */
|
|
379
|
+
readonly prefix: string;
|
|
380
|
+
/** Effective media grouping mode: file `@setup` > project/API > `safe` (ADR-0024). */
|
|
381
|
+
readonly mediaGrouping: MediaGroupingMode;
|
|
382
|
+
readonly options: CompileOptions;
|
|
383
|
+
readonly workspaceRoot: string;
|
|
384
|
+
readonly host: ModuleHost;
|
|
385
|
+
/** Authored source text keyed by normalized module path, for source maps. */
|
|
386
|
+
readonly sourceTexts: ReadonlyMap<string, string>;
|
|
387
|
+
readonly baseDiagnostics: readonly Diagnostic[];
|
|
388
|
+
/**
|
|
389
|
+
* Base map-inheritance value for style-merged modules (ADR-0020). Comes from
|
|
390
|
+
* the API/project output layer; each module's own `@setup map-inherit` wins.
|
|
391
|
+
* Omitted means `true`, preserving ADR-0014 output byte-for-byte.
|
|
392
|
+
*/
|
|
393
|
+
readonly moduleMapInherit?: boolean;
|
|
394
|
+
readonly setupDiagnostics: readonly Diagnostic[];
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** No visible groups: used when the entry module record is unavailable. */
|
|
398
|
+
const NO_GROUPS: ReadonlyMap<string, GroupResolution> = new Map();
|
|
399
|
+
|
|
400
|
+
/** Run every pure pass for one already-loaded entry and return frozen artifacts. */
|
|
401
|
+
function compileEntry(input: CompileEntryInput): CompileResult {
|
|
402
|
+
const styleModules = styleModuleOrder(input.graph, input.entryKey);
|
|
403
|
+
const moduleDiagnostics: Diagnostic[] = [];
|
|
404
|
+
const moduleIr: StylesheetIr[] = [];
|
|
405
|
+
const tables: ClassTableSource[] = [];
|
|
406
|
+
|
|
407
|
+
// Rule-merge imports (ADR-0014): each module is expanded, lowered,
|
|
408
|
+
// substituted and renamed on its own, with its own setup prefix. Imported
|
|
409
|
+
// modules come first in the IR (depth-first in authored `@use` order), then
|
|
410
|
+
// the entry's rules.
|
|
411
|
+
for (const file of styleModules) {
|
|
412
|
+
const record = input.graph.modules.get(file);
|
|
413
|
+
if (record === undefined) continue;
|
|
414
|
+
const decoded = decodeSetup(record.ast);
|
|
415
|
+
const prefix = modulePrefix(input.options, decoded);
|
|
416
|
+
const expanded = expandGroupUseSites(record.ast, { module: file, groups: record.groups });
|
|
417
|
+
const lowered = lower(expanded.ast, input.options);
|
|
418
|
+
const substituted = substitute(lowered.ir, input.graph, file, { prefix: input.prefix });
|
|
419
|
+
const renamed = renameClasses(substituted.ir, { prefix });
|
|
420
|
+
moduleDiagnostics.push(
|
|
421
|
+
...decoded.diagnostics,
|
|
422
|
+
...expanded.diagnostics,
|
|
423
|
+
...lowered.diagnostics,
|
|
424
|
+
...substituted.diagnostics,
|
|
425
|
+
...renamed.diagnostics,
|
|
426
|
+
);
|
|
427
|
+
moduleIr.push(renamed.ir);
|
|
428
|
+
tables.push({
|
|
429
|
+
table: renamed.classes,
|
|
430
|
+
label: sourcePathFor(file, input.workspaceRoot, file),
|
|
431
|
+
mapInherit: decoded.values.mapInherit ?? input.moduleMapInherit ?? true,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const entryGroups = input.graph.modules.get(input.entryKey)?.groups ?? NO_GROUPS;
|
|
436
|
+
const expandedEntry = expandGroupUseSites(input.ast, {
|
|
437
|
+
module: input.entryKey,
|
|
438
|
+
groups: entryGroups,
|
|
439
|
+
});
|
|
440
|
+
const lowered = lower(expandedEntry.ast, input.options);
|
|
441
|
+
const substituted = substitute(lowered.ir, input.graph, input.entryKey, {
|
|
442
|
+
prefix: input.prefix,
|
|
443
|
+
});
|
|
444
|
+
const renamed = renameClasses(substituted.ir, { prefix: input.prefix });
|
|
445
|
+
tables.push({ table: renamed.classes, label: input.sourceFile });
|
|
446
|
+
|
|
447
|
+
const merged = mergeClassTables(tables);
|
|
448
|
+
const combinedIr = stylesheetIr([...moduleIr.flatMap((ir) => ir.rules), ...renamed.ir.rules]);
|
|
449
|
+
const runtime = emitRuntimeTokens(combinedIr, input.graph, input.entryKey, {
|
|
450
|
+
prefix: input.prefix,
|
|
451
|
+
...(input.options.media === undefined ? {} : { media: input.options.media }),
|
|
452
|
+
...(styleModules.length === 0 ? {} : { ruleModules: styleModules }),
|
|
453
|
+
});
|
|
454
|
+
const grouped = groupRuns(runtime.ir, input.mediaGrouping);
|
|
455
|
+
const flattened = flattenIr(grouped);
|
|
456
|
+
|
|
457
|
+
const planInput: PlanOutputsInput = {
|
|
458
|
+
sourceFile: input.sourceFile,
|
|
459
|
+
setup: input.setup,
|
|
460
|
+
workspaceRoot: input.workspaceRoot,
|
|
461
|
+
...(input.projectConfig === undefined ? {} : { projectConfig: input.projectConfig }),
|
|
462
|
+
};
|
|
463
|
+
const plan = planOutputs(planInput, {
|
|
464
|
+
host: { canonicalize: (path) => input.host.canonicalize(path) },
|
|
465
|
+
});
|
|
466
|
+
const cssOutput = plan.plan.outputs.find((output) => output.kind === "css");
|
|
467
|
+
const emitted = emitCss(flattened.ir, {
|
|
468
|
+
minify: input.setup.minify,
|
|
469
|
+
...(input.setup.sourceMap && cssOutput !== undefined
|
|
470
|
+
? {
|
|
471
|
+
sourceMap: {
|
|
472
|
+
// The comment and `file` field must name the planned CSS basename.
|
|
473
|
+
file: basenamePath(cssOutput.workspacePath),
|
|
474
|
+
sourceText: (file) => input.sourceTexts.get(normalizePath(file)),
|
|
475
|
+
sourcePath: (file) => mapSourcePath(file, input.workspaceRoot, input.host),
|
|
476
|
+
includeSourcesContent: true,
|
|
477
|
+
},
|
|
478
|
+
}
|
|
479
|
+
: {}),
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
const map =
|
|
483
|
+
input.setup.emitMap === true ? generateClassMap(merged.table, classMapOptions()) : undefined;
|
|
484
|
+
|
|
485
|
+
/** Opt-in CSS side-effect import for the class map (ADR-0021). */
|
|
486
|
+
function classMapOptions(): ClassMapOptions {
|
|
487
|
+
if (input.setup.importCss !== true) return {};
|
|
488
|
+
const jsOutput = plan.plan.outputs.find((output) => output.kind === "js");
|
|
489
|
+
// Authored destinations keep their order, so the first `css` plan entry is
|
|
490
|
+
// the canonical artifact for a `css-dir` list (ADR-0019, ADR-0021).
|
|
491
|
+
const cssOutput = plan.plan.outputs.find((output) => output.kind === "css");
|
|
492
|
+
if (jsOutput === undefined || cssOutput === undefined) return {};
|
|
493
|
+
return {
|
|
494
|
+
cssImport: stylesheetImportSpecifier(jsOutput.absolutePath, cssOutput.absolutePath),
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const diagnostics = mergeDiagnostics(
|
|
499
|
+
input.setupDiagnostics,
|
|
500
|
+
input.baseDiagnostics,
|
|
501
|
+
moduleDiagnostics,
|
|
502
|
+
expandedEntry.diagnostics,
|
|
503
|
+
lowered.diagnostics,
|
|
504
|
+
substituted.diagnostics,
|
|
505
|
+
runtime.diagnostics,
|
|
506
|
+
renamed.diagnostics,
|
|
507
|
+
merged.diagnostics,
|
|
508
|
+
flattened.diagnostics,
|
|
509
|
+
emitted.diagnostics,
|
|
510
|
+
map === undefined ? [] : map.diagnostics,
|
|
511
|
+
plan.diagnostics,
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
return Object.freeze({
|
|
515
|
+
...(input.setup.emitCss ? { css: emitted.css } : {}),
|
|
516
|
+
...(emitted.map === undefined ? {} : { sourceMap: emitted.map }),
|
|
517
|
+
...(map === undefined ? {} : { js: map.js }),
|
|
518
|
+
...(map === undefined || !input.setup.emitTypes ? {} : { types: map.types }),
|
|
519
|
+
classes: classMapOf(merged.table.entries),
|
|
520
|
+
diagnostics: Object.freeze(diagnostics),
|
|
521
|
+
dependencies: Object.freeze(
|
|
522
|
+
dependenciesForEntry(input.graph, input.entryKey, input.workspaceRoot),
|
|
523
|
+
),
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Decode every `@setup` block in document order, rejecting unknown/duplicate keys. */
|
|
528
|
+
function decodeSetup(ast: Stylesheet): DecodedSetup {
|
|
529
|
+
const values: Partial<MutableSetup> = {};
|
|
530
|
+
const diagnostics: Diagnostic[] = [];
|
|
531
|
+
const seen = new Set<string>();
|
|
532
|
+
let moduleOnly = false;
|
|
533
|
+
let mediaGrouping: MediaGroupingMode | undefined;
|
|
534
|
+
// `map-types` is the canonical declaration flag; `emit-types` is its legacy
|
|
535
|
+
// alias. Resolve them together so the canonical key wins regardless of order.
|
|
536
|
+
let mapTypes: boolean | undefined;
|
|
537
|
+
let emitTypes: boolean | undefined;
|
|
538
|
+
|
|
539
|
+
for (const item of ast.items) {
|
|
540
|
+
if (item.kind !== "setup") continue;
|
|
541
|
+
for (const setting of item.settings) {
|
|
542
|
+
if (!SETUP_KEYS.has(setting.key)) {
|
|
543
|
+
diagnostics.push(
|
|
544
|
+
error("CHIKX1001", `Unknown @setup setting "${setting.key}".`, setting.span),
|
|
545
|
+
);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (seen.has(setting.key)) {
|
|
549
|
+
diagnostics.push(
|
|
550
|
+
error("CHIKX1001", `Duplicate @setup setting "${setting.key}".`, setting.span),
|
|
551
|
+
);
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
seen.add(setting.key);
|
|
555
|
+
// `module` is a marker, not a resolved output setting: it only removes
|
|
556
|
+
// defaults for this file's own build (ADR-0014).
|
|
557
|
+
if (setting.key === "module") {
|
|
558
|
+
const moduleValue = decodeBoolean(setting);
|
|
559
|
+
if (moduleValue === undefined) {
|
|
560
|
+
diagnostics.push(
|
|
561
|
+
error(
|
|
562
|
+
"CHIKX1001",
|
|
563
|
+
`@setup setting "module" expects true or false, not ${setting.value.trim()}.`,
|
|
564
|
+
setting.span,
|
|
565
|
+
),
|
|
566
|
+
);
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
moduleOnly = moduleValue;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (setting.key === "media-grouping") {
|
|
573
|
+
const value = decodeSetupScalar(setting.value);
|
|
574
|
+
if (value === "merge" || value === "safe" || value === "none") {
|
|
575
|
+
mediaGrouping = value;
|
|
576
|
+
} else {
|
|
577
|
+
diagnostics.push(
|
|
578
|
+
error(
|
|
579
|
+
"CHIKX1001",
|
|
580
|
+
`@setup setting "media-grouping" expects "merge", "safe" or "none", not ${setting.value.trim()}.`,
|
|
581
|
+
setting.valueSpan,
|
|
582
|
+
),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
if (BOOLEAN_SETUP_KEYS.has(setting.key)) {
|
|
588
|
+
const value = decodeBoolean(setting);
|
|
589
|
+
if (value === undefined) {
|
|
590
|
+
diagnostics.push(
|
|
591
|
+
error(
|
|
592
|
+
"CHIKX1001",
|
|
593
|
+
`@setup setting "${setting.key}" expects true or false, not ${setting.value.trim()}.`,
|
|
594
|
+
setting.span,
|
|
595
|
+
),
|
|
596
|
+
);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if (setting.key === "map-types") {
|
|
600
|
+
mapTypes = value;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (setting.key === "emit-types") {
|
|
604
|
+
emitTypes = value;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
assignBooleanSetting(values, setting.key, value);
|
|
608
|
+
} else if (setting.key === "css-dir") {
|
|
609
|
+
const decoded = decodeSetupList(setting.value, setting.valueSpan);
|
|
610
|
+
diagnostics.push(...decoded.diagnostics);
|
|
611
|
+
if (decoded.diagnostics.length > 0) continue;
|
|
612
|
+
const first = decoded.entries[0];
|
|
613
|
+
if (first === undefined) continue;
|
|
614
|
+
values.cssDir = first.value;
|
|
615
|
+
if (decoded.entries.length > 1) {
|
|
616
|
+
values.cssDirs = decoded.entries.map((entry) => entry.value);
|
|
617
|
+
}
|
|
618
|
+
} else {
|
|
619
|
+
assignStringSetting(values, setting.key, decodeSetupScalar(setting.value));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const types = mapTypes ?? emitTypes;
|
|
625
|
+
if (types !== undefined) values.emitTypes = types;
|
|
626
|
+
|
|
627
|
+
return {
|
|
628
|
+
values,
|
|
629
|
+
moduleOnly,
|
|
630
|
+
...(mediaGrouping === undefined ? {} : { mediaGrouping }),
|
|
631
|
+
diagnostics,
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function decodeBoolean(setting: Setting): boolean | undefined {
|
|
636
|
+
const raw = setting.value.trim();
|
|
637
|
+
if (raw === "true") return true;
|
|
638
|
+
if (raw === "false") return false;
|
|
639
|
+
return undefined;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function assignStringSetting(target: Partial<MutableSetup>, key: string, value: string): void {
|
|
643
|
+
switch (key) {
|
|
644
|
+
case "prefix":
|
|
645
|
+
target.prefix = value;
|
|
646
|
+
break;
|
|
647
|
+
case "css-name":
|
|
648
|
+
target.cssName = value;
|
|
649
|
+
break;
|
|
650
|
+
case "map-dir":
|
|
651
|
+
target.mapDir = value;
|
|
652
|
+
break;
|
|
653
|
+
case "map-name":
|
|
654
|
+
target.mapName = value;
|
|
655
|
+
break;
|
|
656
|
+
default:
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function assignBooleanSetting(target: Partial<MutableSetup>, key: string, value: boolean): void {
|
|
662
|
+
switch (key) {
|
|
663
|
+
case "emit-css":
|
|
664
|
+
target.emitCss = value;
|
|
665
|
+
break;
|
|
666
|
+
case "emit-map":
|
|
667
|
+
target.emitMap = value;
|
|
668
|
+
break;
|
|
669
|
+
case "map-types":
|
|
670
|
+
case "emit-types":
|
|
671
|
+
target.emitTypes = value;
|
|
672
|
+
break;
|
|
673
|
+
case "source-map":
|
|
674
|
+
target.sourceMap = value;
|
|
675
|
+
break;
|
|
676
|
+
case "minify":
|
|
677
|
+
target.minify = value;
|
|
678
|
+
break;
|
|
679
|
+
case "map-inherit":
|
|
680
|
+
target.mapInherit = value;
|
|
681
|
+
break;
|
|
682
|
+
case "import-css":
|
|
683
|
+
target.importCss = value;
|
|
684
|
+
break;
|
|
685
|
+
default:
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function definedOutput(options: OutputOptions | undefined): Partial<MutableSetup> {
|
|
691
|
+
if (options === undefined) return {};
|
|
692
|
+
const values: Partial<MutableSetup> = {};
|
|
693
|
+
if (options.cssDir !== undefined) values.cssDir = options.cssDir;
|
|
694
|
+
if (options.cssName !== undefined) values.cssName = options.cssName;
|
|
695
|
+
if (options.mapDir !== undefined) values.mapDir = options.mapDir;
|
|
696
|
+
if (options.mapName !== undefined) values.mapName = options.mapName;
|
|
697
|
+
if (options.emitCss !== undefined) values.emitCss = options.emitCss;
|
|
698
|
+
if (options.emitMap !== undefined) values.emitMap = options.emitMap;
|
|
699
|
+
const types = options.mapTypes ?? options.emitTypes;
|
|
700
|
+
if (types !== undefined) values.emitTypes = types;
|
|
701
|
+
if (options.sourceMap !== undefined) values.sourceMap = options.sourceMap;
|
|
702
|
+
if (options.minify !== undefined) values.minify = options.minify;
|
|
703
|
+
if (options.mapInherit !== undefined) values.mapInherit = options.mapInherit;
|
|
704
|
+
if (options.importCss !== undefined) values.importCss = options.importCss;
|
|
705
|
+
return values;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function buildCompileSetup(
|
|
709
|
+
file: string,
|
|
710
|
+
options: CompileOptions,
|
|
711
|
+
decoded: DecodedSetup,
|
|
712
|
+
): ResolvedSetup {
|
|
713
|
+
const defaults = defaultSetupFor(file);
|
|
714
|
+
const merged: MutableSetup = {
|
|
715
|
+
...defaults,
|
|
716
|
+
...moduleSuppression(decoded.moduleOnly),
|
|
717
|
+
...decoded.values,
|
|
718
|
+
...definedOutput(options),
|
|
719
|
+
prefix: "",
|
|
720
|
+
};
|
|
721
|
+
// An explicit API/CLI `cssDir` is a single destination and replaces a file
|
|
722
|
+
// list (ADR-0019); only the file layer can author a list.
|
|
723
|
+
if (options.cssDir !== undefined) merged.cssDirs = undefined;
|
|
724
|
+
return {
|
|
725
|
+
...merged,
|
|
726
|
+
prefix: resolveCompilePrefix(options, decoded),
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function buildProjectSetup(
|
|
731
|
+
file: string,
|
|
732
|
+
options: CompileProjectOptions,
|
|
733
|
+
decoded: DecodedSetup,
|
|
734
|
+
): ResolvedSetup {
|
|
735
|
+
const defaults = defaultSetupFor(file);
|
|
736
|
+
const merged: MutableSetup = {
|
|
737
|
+
...defaults,
|
|
738
|
+
...definedOutput(options.output),
|
|
739
|
+
...moduleSuppression(decoded.moduleOnly),
|
|
740
|
+
...decoded.values,
|
|
741
|
+
prefix: "",
|
|
742
|
+
};
|
|
743
|
+
if (options.output?.cssDir !== undefined) merged.cssDirs = undefined;
|
|
744
|
+
return {
|
|
745
|
+
...merged,
|
|
746
|
+
prefix: resolveProjectPrefix(options, decoded),
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Output defaults removed by `@setup { module: true }` (ADR-0014).
|
|
752
|
+
*
|
|
753
|
+
* A module-only file writes no artifacts of its own, so CSS, map and types are
|
|
754
|
+
* suppressed. The suppression sits above built-in defaults and project
|
|
755
|
+
* configuration but below the file's own explicit `emit-*` keys and explicit
|
|
756
|
+
* API/CLI overrides, so authoring a key restores it.
|
|
757
|
+
*/
|
|
758
|
+
function moduleSuppression(moduleOnly: boolean): Partial<MutableSetup> {
|
|
759
|
+
if (!moduleOnly) return {};
|
|
760
|
+
return { emitCss: false, emitMap: false, emitTypes: false };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function resolveCompilePrefix(options: CompileOptions, decoded: DecodedSetup): string {
|
|
764
|
+
if ((options.naming?.strategy ?? "prefix") === "none") return "";
|
|
765
|
+
return options.prefix ?? options.naming?.prefix ?? decoded.values.prefix ?? "";
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function resolveProjectPrefix(options: CompileProjectOptions, decoded: DecodedSetup): string {
|
|
769
|
+
if ((options.naming?.strategy ?? "prefix") === "none") return "";
|
|
770
|
+
return decoded.values.prefix ?? options.naming?.prefix ?? "";
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Effective class prefix of a style-imported module (ADR-0014).
|
|
775
|
+
*
|
|
776
|
+
* Only the module's own `@setup prefix` applies: the importing file's prefix,
|
|
777
|
+
* the API `prefix` and the project `classes.prefix` never reach merged rules. A
|
|
778
|
+
* module without `@setup` therefore merges unprefixed. `naming.strategy: "none"`
|
|
779
|
+
* still disables prefixing for the whole build.
|
|
780
|
+
*/
|
|
781
|
+
function modulePrefix(options: CompileOptions, decoded: DecodedSetup): string {
|
|
782
|
+
if ((options.naming?.strategy ?? "prefix") === "none") return "";
|
|
783
|
+
return decoded.values.prefix ?? "";
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/** Build the null-prototype class map required by the frozen `ClassMap` type. */
|
|
787
|
+
function classMapOf(
|
|
788
|
+
entries: readonly { readonly name: string; readonly emitted: string; readonly global: boolean }[],
|
|
789
|
+
): ClassMap {
|
|
790
|
+
const map = Object.create(null) as Record<string, string>;
|
|
791
|
+
for (const entry of entries) {
|
|
792
|
+
if (!entry.global) map[entry.name] = entry.emitted;
|
|
793
|
+
}
|
|
794
|
+
return Object.freeze(map) as ClassMap;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/** Workspace-relative POSIX dependencies of one entry, excluding the entry itself. */
|
|
798
|
+
function dependenciesForEntry(
|
|
799
|
+
graph: ModuleGraph,
|
|
800
|
+
entryKey: string,
|
|
801
|
+
workspaceRoot: string,
|
|
802
|
+
): string[] {
|
|
803
|
+
const reachable = new Set<string>();
|
|
804
|
+
const queue = [entryKey];
|
|
805
|
+
while (queue.length > 0) {
|
|
806
|
+
const file = queue.shift() as string;
|
|
807
|
+
if (reachable.has(file)) continue;
|
|
808
|
+
reachable.add(file);
|
|
809
|
+
const record = graph.modules.get(file);
|
|
810
|
+
if (record === undefined) continue;
|
|
811
|
+
for (const dependency of record.dependencies) queue.push(dependency);
|
|
812
|
+
}
|
|
813
|
+
reachable.delete(entryKey);
|
|
814
|
+
|
|
815
|
+
const relative = [...reachable].map((file) => relativePath(workspaceRoot, file));
|
|
816
|
+
return relative
|
|
817
|
+
.filter((path) => !isAbsolutePath(path) && path !== ".." && !path.startsWith("../"))
|
|
818
|
+
.sort();
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Caller-facing diagnostics for a source compiled without `@use`.
|
|
823
|
+
*
|
|
824
|
+
* The memory graph reparses the same source, so its syntax (`CHIKX1xxx`)
|
|
825
|
+
* diagnostics duplicate `parsed.diagnostics`; the caller's parse keeps the
|
|
826
|
+
* authored file label and stays authoritative. Resolver diagnostics
|
|
827
|
+
* (`CHIKX2xxx`+) exist only in the graph and must survive, so a duplicate
|
|
828
|
+
* `@variables` key reports one `CHIKX2001` with the resolver's message and span
|
|
829
|
+
* just as the module-graph path does (CSSX-U04).
|
|
830
|
+
*/
|
|
831
|
+
function singleFileDiagnostics(
|
|
832
|
+
parsed: readonly Diagnostic[],
|
|
833
|
+
graphDiagnostics: readonly Diagnostic[],
|
|
834
|
+
): readonly Diagnostic[] {
|
|
835
|
+
const resolverDiagnostics = graphDiagnostics.filter(
|
|
836
|
+
(diagnostic) => !diagnostic.code.startsWith("CHIKX1"),
|
|
837
|
+
);
|
|
838
|
+
return mergeDiagnostics(parsed, resolverDiagnostics);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** Graph diagnostics whose file belongs to the entry's reachable module set. */
|
|
842
|
+
function diagnosticsForEntry(graph: ModuleGraph, entryKey: string): readonly Diagnostic[] {
|
|
843
|
+
const reachable = new Set<string>();
|
|
844
|
+
const queue = [entryKey];
|
|
845
|
+
while (queue.length > 0) {
|
|
846
|
+
const file = queue.shift() as string;
|
|
847
|
+
if (reachable.has(file)) continue;
|
|
848
|
+
reachable.add(file);
|
|
849
|
+
const record = graph.modules.get(file);
|
|
850
|
+
if (record === undefined) continue;
|
|
851
|
+
for (const dependency of record.dependencies) queue.push(dependency);
|
|
852
|
+
}
|
|
853
|
+
return graph.diagnostics.filter((diagnostic) =>
|
|
854
|
+
reachable.has(normalizePath(diagnostic.span.file)),
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
function projectDirectoryConfig(output: OutputOptions | undefined): ProjectConfig | undefined {
|
|
859
|
+
if (output === undefined) return undefined;
|
|
860
|
+
const directories: OutputOptions = {
|
|
861
|
+
...(output.cssDir === undefined ? {} : { cssDir: output.cssDir }),
|
|
862
|
+
...(output.mapDir === undefined ? {} : { mapDir: output.mapDir }),
|
|
863
|
+
};
|
|
864
|
+
if (directories.cssDir === undefined && directories.mapDir === undefined) return undefined;
|
|
865
|
+
return { output: directories };
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function emptyCompileResult(diagnostics: readonly Diagnostic[] = []): CompileResult {
|
|
869
|
+
const classes = Object.freeze(Object.create(null)) as ClassMap;
|
|
870
|
+
return Object.freeze({
|
|
871
|
+
classes,
|
|
872
|
+
diagnostics: Object.freeze([...diagnostics]),
|
|
873
|
+
dependencies: Object.freeze([]),
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** Resolve an authored source path to a workspace-relative POSIX path when possible. */
|
|
878
|
+
function sourcePathFor(absolute: string, workspaceRoot: string, authored: string): string {
|
|
879
|
+
const relative = relativePath(workspaceRoot, absolute);
|
|
880
|
+
if (
|
|
881
|
+
relative === "." ||
|
|
882
|
+
isAbsolutePath(relative) ||
|
|
883
|
+
relative === ".." ||
|
|
884
|
+
relative.startsWith("../")
|
|
885
|
+
) {
|
|
886
|
+
return normalizePath(authored);
|
|
887
|
+
}
|
|
888
|
+
return relative;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** Project a span file path into the workspace-relative POSIX form maps require. */
|
|
892
|
+
function mapSourcePath(file: string, workspaceRoot: string, host: ModuleHost): string {
|
|
893
|
+
const roots = new Set<string>([workspaceRoot]);
|
|
894
|
+
try {
|
|
895
|
+
roots.add(normalizePath(host.canonicalize(workspaceRoot)));
|
|
896
|
+
} catch {
|
|
897
|
+
// A host that cannot canonicalize the root keeps the lexical form only.
|
|
898
|
+
}
|
|
899
|
+
for (const root of roots) {
|
|
900
|
+
const relative = relativePath(root, file);
|
|
901
|
+
if (
|
|
902
|
+
relative !== "." &&
|
|
903
|
+
!isAbsolutePath(relative) &&
|
|
904
|
+
relative !== ".." &&
|
|
905
|
+
!relative.startsWith("../")
|
|
906
|
+
) {
|
|
907
|
+
return relative;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
return normalizePath(file);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Wrap a host so every authored source read by the module graph is retained for
|
|
915
|
+
* source-map generation.
|
|
916
|
+
*
|
|
917
|
+
* `ModuleRecord` intentionally stores no source text (A07 contract), so the
|
|
918
|
+
* index pipeline records it here without changing frozen or resolver types.
|
|
919
|
+
* Keys are normalized module paths, exactly the paths that end up in IR spans.
|
|
920
|
+
*/
|
|
921
|
+
function createRecordingHost(host: ModuleHost): {
|
|
922
|
+
readonly host: ModuleHost;
|
|
923
|
+
readonly sources: ReadonlyMap<string, string>;
|
|
924
|
+
} {
|
|
925
|
+
const sources = new Map<string, string>();
|
|
926
|
+
return {
|
|
927
|
+
sources,
|
|
928
|
+
host: {
|
|
929
|
+
async readFile(path: string): Promise<string> {
|
|
930
|
+
const source = await host.readFile(path);
|
|
931
|
+
sources.set(normalizePath(path), source);
|
|
932
|
+
return source;
|
|
933
|
+
},
|
|
934
|
+
fileExists: (path) => host.fileExists(path),
|
|
935
|
+
canonicalize: (path) => host.canonicalize(path),
|
|
936
|
+
resolvePath: (from, to) => host.resolvePath(from, to),
|
|
937
|
+
workspaceRoot: () => host.workspaceRoot(),
|
|
938
|
+
},
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Memory host for a source with no `@use`: it makes the parsed entry available
|
|
944
|
+
* to the graph passes without reading the filesystem.
|
|
945
|
+
*/
|
|
946
|
+
function createMemoryHost(source: string, entry: string, workspaceRoot: string): ModuleHost {
|
|
947
|
+
const normalizedEntry = normalizePath(entry);
|
|
948
|
+
const same = (path: string): boolean => normalizePath(path) === normalizedEntry;
|
|
949
|
+
return {
|
|
950
|
+
async readFile(path: string): Promise<string> {
|
|
951
|
+
if (same(path)) return source;
|
|
952
|
+
throw new Error(`ENOENT: ${path}`);
|
|
953
|
+
},
|
|
954
|
+
async fileExists(path: string): Promise<boolean> {
|
|
955
|
+
return same(path);
|
|
956
|
+
},
|
|
957
|
+
canonicalize(path: string): string {
|
|
958
|
+
return normalizePath(path);
|
|
959
|
+
},
|
|
960
|
+
resolvePath(from: string, to: string): string {
|
|
961
|
+
return isAbsolutePath(to) ? normalizePath(to) : joinPath(dirnamePath(from), to);
|
|
962
|
+
},
|
|
963
|
+
workspaceRoot(): string {
|
|
964
|
+
return workspaceRoot;
|
|
965
|
+
},
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Wrap the default host so the in-memory source overrides the entry file while
|
|
971
|
+
* imports still resolve through the real Node host.
|
|
972
|
+
*/
|
|
973
|
+
function withEntrySource(host: ModuleHost, entry: string, source: string): ModuleHost {
|
|
974
|
+
const normalizedEntry = normalizePath(entry);
|
|
975
|
+
const canonicalEntry = normalizePath(host.canonicalize(normalizedEntry));
|
|
976
|
+
const same = (path: string): boolean => {
|
|
977
|
+
const normalized = normalizePath(path);
|
|
978
|
+
return normalized === normalizedEntry || normalized === canonicalEntry;
|
|
979
|
+
};
|
|
980
|
+
return {
|
|
981
|
+
async readFile(path: string): Promise<string> {
|
|
982
|
+
if (same(path)) return source;
|
|
983
|
+
return host.readFile(path);
|
|
984
|
+
},
|
|
985
|
+
async fileExists(path: string): Promise<boolean> {
|
|
986
|
+
if (same(path)) return true;
|
|
987
|
+
return host.fileExists(path);
|
|
988
|
+
},
|
|
989
|
+
canonicalize(path: string): string {
|
|
990
|
+
if (same(path)) return canonicalEntry;
|
|
991
|
+
return host.canonicalize(path);
|
|
992
|
+
},
|
|
993
|
+
resolvePath(from: string, to: string): string {
|
|
994
|
+
return host.resolvePath(from, to);
|
|
995
|
+
},
|
|
996
|
+
workspaceRoot(): string {
|
|
997
|
+
return host.workspaceRoot();
|
|
998
|
+
},
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function mergeDiagnostics(...groups: readonly (readonly Diagnostic[])[]): Diagnostic[] {
|
|
1003
|
+
const merged: Diagnostic[] = [];
|
|
1004
|
+
const seen = new Set<string>();
|
|
1005
|
+
for (const group of groups) {
|
|
1006
|
+
for (const diagnostic of group) {
|
|
1007
|
+
const key = [
|
|
1008
|
+
diagnostic.code,
|
|
1009
|
+
diagnostic.severity,
|
|
1010
|
+
diagnostic.span.file,
|
|
1011
|
+
diagnostic.span.start,
|
|
1012
|
+
diagnostic.span.end,
|
|
1013
|
+
diagnostic.message,
|
|
1014
|
+
].join("\u0000");
|
|
1015
|
+
if (seen.has(key)) continue;
|
|
1016
|
+
seen.add(key);
|
|
1017
|
+
merged.push(diagnostic);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return merged;
|
|
1021
|
+
}
|