@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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class naming and export generation (P4, SPECIFICATION.md §7.2 / §8).
|
|
3
|
+
*
|
|
4
|
+
* Two pure passes complete the naming story of the pipeline:
|
|
5
|
+
*
|
|
6
|
+
* 1. {@link renameClasses} — walks the lowered IR after {@link substitute},
|
|
7
|
+
* rebuilds every rule selector with the naming table applied (prefix strategy,
|
|
8
|
+
* `:global(...)` escape), and returns the first-appearance class table.
|
|
9
|
+
* 2. `generateClassMap` — turns that table into an ESM module of camelCase
|
|
10
|
+
* `export const` bindings plus matching opt-in TypeScript declarations, with
|
|
11
|
+
* deterministic `_`/`_N` identifier adjustments and CHIKX4001 warnings.
|
|
12
|
+
* 3. {@link mergeClassTables} — unions the renamed tables of a rule-bearing
|
|
13
|
+
* (`styles`) module graph into the single table the importing build exports
|
|
14
|
+
* (ADR-0014), enforcing the strict same-name/different-emitted conflict.
|
|
15
|
+
*
|
|
16
|
+
* Canonical pipeline position for consumers:
|
|
17
|
+
*
|
|
18
|
+
* ```text
|
|
19
|
+
* parse → buildModuleGraph → (per module) lower → substitute → renameClasses
|
|
20
|
+
* → mergeClassTables → emitRuntimeTokens → groupRuns → flattenIr → emitCss
|
|
21
|
+
* (→ generateClassMap for the JS map and opt-in .d.ts)
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* `renameClasses` only rewrites selectors, so it is independent of the single
|
|
25
|
+
* merged-build runtime emission; the class table is identical either way.
|
|
26
|
+
*
|
|
27
|
+
* Every pass is deterministic, frozen-output and filesystem-free; they never
|
|
28
|
+
* mutate their inputs and never throw on malformed IR. Barrel wiring is
|
|
29
|
+
* lead-directed; import this facade until integration.
|
|
30
|
+
*/
|
|
31
|
+
export { renameClasses } from "./rewrite.js";
|
|
32
|
+
export { generateClassMap } from "./mapgen.js";
|
|
33
|
+
export { mergeClassTables } from "./merge.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/naming/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ClassMapResult, ClassTable } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* JavaScript class-map and TypeScript declaration generation
|
|
4
|
+
* (SPECIFICATION.md §8, ADR-0010, CSSX-A52).
|
|
5
|
+
*
|
|
6
|
+
* Output contract, fixed here and covered by goldens:
|
|
7
|
+
*
|
|
8
|
+
* - **Named exports only.** The map is one `export const <identifier> = "<emitted>";`
|
|
9
|
+
* line per local class, in the class table's first-appearance order. There is
|
|
10
|
+
* no default export and no object literal: the map's single purpose is to
|
|
11
|
+
* provide the DOM `class` value as an importable JavaScript binding, so
|
|
12
|
+
* consumers write `import { contactPanel } from "./x.map.js"` and
|
|
13
|
+
* `class={contactPanel}`. Export order is deterministic.
|
|
14
|
+
* - **Identifier shape.** Each class name is split on `-` and `_` and camelCased
|
|
15
|
+
* (`card-header` → `cardHeader`, `panel_head` → `panelHead`); leading and
|
|
16
|
+
* trailing `_` runs are kept (`__proto__` → `__proto__`). Three adjustments
|
|
17
|
+
* keep every class reachable, because there is no object fallback:
|
|
18
|
+
* - characters outside the JavaScript identifier set become `_`
|
|
19
|
+
* (`foo.bar` → `foo_bar`);
|
|
20
|
+
* - an alias that would start with a digit, or that sanitizes to nothing, is
|
|
21
|
+
* prefixed with `_` (`2col` → `_2col`, `-` → `_`);
|
|
22
|
+
* - a reserved word is prefixed with `_` (`default` → `_default`).
|
|
23
|
+
* - **Collisions are resolved, not dropped.** If two classes resolve to the same
|
|
24
|
+
* identifier, the first-authored class keeps it and later ones get `_2`, `_3`
|
|
25
|
+
* (… first free suffix) in first-appearance order. Suffixes are allocated
|
|
26
|
+
* against the identifiers already emitted, so if an earlier export already
|
|
27
|
+
* uses `fooBar_2`, the next collision becomes `fooBar_3`.
|
|
28
|
+
* - **Diagnostics.** Each adjusted identifier (shape or collision) reports one
|
|
29
|
+
* CHIKX4001 **warning** naming the authored class and the exported binding.
|
|
30
|
+
* Warnings never fail a build; the output is already complete and unambiguous.
|
|
31
|
+
* - **Declarations mirror the JS exactly** when enabled: one
|
|
32
|
+
* `export declare const <identifier>: "<emitted>";` line per class in the same
|
|
33
|
+
* order, with literal string types and no `any`. The declarations are opt-in
|
|
34
|
+
* (`map-types` / `emit-types`, default off) and never contain a `map` object or
|
|
35
|
+
* a default export.
|
|
36
|
+
* - `__proto__` needs no special handling: as a `const` binding it is an ordinary
|
|
37
|
+
* identifier and there is no object literal to poison.
|
|
38
|
+
* - Global classes never reach either file (§8).
|
|
39
|
+
*
|
|
40
|
+
* Formatting is fixed so generated files are stable: one line per binding and
|
|
41
|
+
* one trailing newline. By default the map has no CSS side-effect import;
|
|
42
|
+
* loading the stylesheet is the consumer's responsibility (`<link>` or an
|
|
43
|
+
* explicit `import "./x.css"`). A consumer that wants the map to carry the
|
|
44
|
+
* stylesheet through its bundler opts in with `import-css: true` /
|
|
45
|
+
* `output.importCss` (ADR-0021): exactly one `import "<specifier>";` line is
|
|
46
|
+
* prepended and `.d.ts` declarations stay pure. An empty table yields an empty
|
|
47
|
+
* file unless that import was requested.
|
|
48
|
+
*/
|
|
49
|
+
/** Options for {@link generateClassMap}. */
|
|
50
|
+
export interface ClassMapOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Relative specifier of the emitted stylesheet (ADR-0021). Present only when
|
|
53
|
+
* `import-css` is enabled and the build emits CSS; the caller computes it
|
|
54
|
+
* from the planned artifacts with {@link stylesheetImportSpecifier}.
|
|
55
|
+
*/
|
|
56
|
+
readonly cssImport?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generate the ESM class map and matching `.d.ts` text for one class table.
|
|
60
|
+
*
|
|
61
|
+
* Pure and deterministic: the same table and options always produce
|
|
62
|
+
* byte-identical text. Global classes are excluded; reserved identifiers and
|
|
63
|
+
* digit-leading names are prefixed with `_` and identifier collisions get a
|
|
64
|
+
* numeric suffix, each with one CHIKX4001 warning.
|
|
65
|
+
*
|
|
66
|
+
* @param classes Class table produced by `renameClasses`.
|
|
67
|
+
* @param options Optional stylesheet import (ADR-0021).
|
|
68
|
+
*/
|
|
69
|
+
export declare function generateClassMap(classes: ClassTable, options?: ClassMapOptions): ClassMapResult;
|
|
70
|
+
//# sourceMappingURL=mapgen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapgen.d.ts","sourceRoot":"","sources":["../../src/naming/mapgen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AA4JD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAqBhB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { warning } from "../types/diagnostics.js";
|
|
2
|
+
/** `true` when `name` can be declared as a bare JavaScript binding. */
|
|
3
|
+
function isValidJsIdentifier(name) {
|
|
4
|
+
return /^[$_\p{ID_Start}][$_\p{ID_Continue}]*$/u.test(name);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Naive camelCase alias before identifier adjustments.
|
|
8
|
+
*
|
|
9
|
+
* Leading and trailing `_` runs are preserved (they carry meaning for names such
|
|
10
|
+
* as `__proto__`), while interior `-`/`_` runs are separators and the following
|
|
11
|
+
* letter is capitalized. A name made only of separators keeps its underscores.
|
|
12
|
+
*/
|
|
13
|
+
function camelCaseAlias(name) {
|
|
14
|
+
const leading = /^_+/u.exec(name)?.[0] ?? "";
|
|
15
|
+
const rest = name.slice(leading.length);
|
|
16
|
+
const trailing = /_+$/u.exec(rest)?.[0] ?? "";
|
|
17
|
+
const core = rest.slice(0, rest.length - trailing.length);
|
|
18
|
+
const parts = core.split(/[-_]+/u).filter((part) => part.length > 0);
|
|
19
|
+
const first = parts[0] ?? "";
|
|
20
|
+
let alias = first;
|
|
21
|
+
for (let index = 1; index < parts.length; index += 1) {
|
|
22
|
+
const part = parts[index] ?? "";
|
|
23
|
+
alias += part.charAt(0).toUpperCase() + part.slice(1);
|
|
24
|
+
}
|
|
25
|
+
return `${leading}${alias}${trailing}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Words that cannot be a named export binding (or are unsafe as one under ESM
|
|
29
|
+
* strict mode). Kept explicit so the policy is auditable rather than depending
|
|
30
|
+
* on engine behavior.
|
|
31
|
+
*/
|
|
32
|
+
const RESERVED_IDENTIFIERS = new Set([
|
|
33
|
+
"arguments",
|
|
34
|
+
"await",
|
|
35
|
+
"break",
|
|
36
|
+
"case",
|
|
37
|
+
"catch",
|
|
38
|
+
"class",
|
|
39
|
+
"const",
|
|
40
|
+
"continue",
|
|
41
|
+
"debugger",
|
|
42
|
+
"default",
|
|
43
|
+
"delete",
|
|
44
|
+
"do",
|
|
45
|
+
"else",
|
|
46
|
+
"enum",
|
|
47
|
+
"eval",
|
|
48
|
+
"export",
|
|
49
|
+
"extends",
|
|
50
|
+
"false",
|
|
51
|
+
"finally",
|
|
52
|
+
"for",
|
|
53
|
+
"function",
|
|
54
|
+
"if",
|
|
55
|
+
"implements",
|
|
56
|
+
"import",
|
|
57
|
+
"in",
|
|
58
|
+
"instanceof",
|
|
59
|
+
"interface",
|
|
60
|
+
"let",
|
|
61
|
+
"new",
|
|
62
|
+
"null",
|
|
63
|
+
"package",
|
|
64
|
+
"private",
|
|
65
|
+
"protected",
|
|
66
|
+
"public",
|
|
67
|
+
"return",
|
|
68
|
+
"static",
|
|
69
|
+
"super",
|
|
70
|
+
"switch",
|
|
71
|
+
"this",
|
|
72
|
+
"throw",
|
|
73
|
+
"true",
|
|
74
|
+
"try",
|
|
75
|
+
"typeof",
|
|
76
|
+
"var",
|
|
77
|
+
"void",
|
|
78
|
+
"while",
|
|
79
|
+
"with",
|
|
80
|
+
"yield",
|
|
81
|
+
]);
|
|
82
|
+
/** Quote a string as a JS/TS double-quoted literal. */
|
|
83
|
+
function quote(text) {
|
|
84
|
+
return JSON.stringify(text);
|
|
85
|
+
}
|
|
86
|
+
/** Base identifier for one class, before uniqueness suffixing. */
|
|
87
|
+
function baseIdentifier(name) {
|
|
88
|
+
const alias = camelCaseAlias(name);
|
|
89
|
+
let base = alias.replace(/[^\p{ID_Continue}$]/gu, "_");
|
|
90
|
+
let adjusted = base !== alias;
|
|
91
|
+
if (base === "") {
|
|
92
|
+
return { alias, base: "_", adjusted: true };
|
|
93
|
+
}
|
|
94
|
+
if (!isValidJsIdentifier(base) || RESERVED_IDENTIFIERS.has(base)) {
|
|
95
|
+
base = `_${base}`;
|
|
96
|
+
adjusted = true;
|
|
97
|
+
}
|
|
98
|
+
return { alias, base, adjusted };
|
|
99
|
+
}
|
|
100
|
+
/** Prepare export identifiers and collect CHIKX4001 warnings. */
|
|
101
|
+
function prepare(table, diagnostics) {
|
|
102
|
+
const exportable = table.entries.filter((entry) => !entry.global);
|
|
103
|
+
const owners = new Map();
|
|
104
|
+
const prepared = [];
|
|
105
|
+
for (const entry of exportable) {
|
|
106
|
+
const { alias, base, adjusted } = baseIdentifier(entry.name);
|
|
107
|
+
let identifier = base;
|
|
108
|
+
let suffix = 1;
|
|
109
|
+
while (owners.has(identifier)) {
|
|
110
|
+
suffix += 1;
|
|
111
|
+
identifier = `${base}_${suffix}`;
|
|
112
|
+
}
|
|
113
|
+
const owner = owners.get(base);
|
|
114
|
+
owners.set(identifier, entry.name);
|
|
115
|
+
if (owner === undefined && adjusted) {
|
|
116
|
+
diagnostics.push(warning("CHIKX4001", `Class "${entry.name}" maps to "${alias}", which is not a usable JavaScript export binding (reserved word or invalid identifier); it is exported as "${identifier}" (SPECIFICATION.md §8).`, entry.span));
|
|
117
|
+
}
|
|
118
|
+
else if (owner !== undefined) {
|
|
119
|
+
diagnostics.push(warning("CHIKX4001", `Class "${entry.name}" maps to the camelCase identifier "${alias}", which class "${owner}" already exports; it is exported as "${identifier}" (SPECIFICATION.md §8).`, entry.span));
|
|
120
|
+
}
|
|
121
|
+
prepared.push({ entry, identifier });
|
|
122
|
+
}
|
|
123
|
+
return prepared;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Generate the ESM class map and matching `.d.ts` text for one class table.
|
|
127
|
+
*
|
|
128
|
+
* Pure and deterministic: the same table and options always produce
|
|
129
|
+
* byte-identical text. Global classes are excluded; reserved identifiers and
|
|
130
|
+
* digit-leading names are prefixed with `_` and identifier collisions get a
|
|
131
|
+
* numeric suffix, each with one CHIKX4001 warning.
|
|
132
|
+
*
|
|
133
|
+
* @param classes Class table produced by `renameClasses`.
|
|
134
|
+
* @param options Optional stylesheet import (ADR-0021).
|
|
135
|
+
*/
|
|
136
|
+
export function generateClassMap(classes, options = {}) {
|
|
137
|
+
const diagnostics = [];
|
|
138
|
+
const prepared = prepare(classes, diagnostics);
|
|
139
|
+
const jsLines = [];
|
|
140
|
+
if (options.cssImport !== undefined && options.cssImport !== "") {
|
|
141
|
+
jsLines.push(`import ${quote(options.cssImport)};`);
|
|
142
|
+
}
|
|
143
|
+
for (const entry of prepared) {
|
|
144
|
+
jsLines.push(`export const ${entry.identifier} = ${quote(entry.entry.emitted)};`);
|
|
145
|
+
}
|
|
146
|
+
const typeLines = prepared.map((entry) => `export declare const ${entry.identifier}: ${quote(entry.entry.emitted)};`);
|
|
147
|
+
return {
|
|
148
|
+
js: jsLines.length === 0 ? "" : `${jsLines.join("\n")}\n`,
|
|
149
|
+
types: typeLines.length === 0 ? "" : `${typeLines.join("\n")}\n`,
|
|
150
|
+
diagnostics,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=mapgen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapgen.js","sourceRoot":"","sources":["../../src/naming/mapgen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AA6DlD,uEAAuE;AACvE,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,yCAAyC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,M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C;IACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,gBAAgB,KAAK,CAAC,UAAU,MAAM,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAC5B,CAAC,KAAK,EAAE,EAAE,CAAC,wBAAwB,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CACtF,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACzD,KAAK,EAAE,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAChE,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged class tables for rule-bearing (`styles`) imports (ADR-0014).
|
|
3
|
+
*
|
|
4
|
+
* A merged build has ONE class map and ONE `.d.ts` for the importing file,
|
|
5
|
+
* covering the entry's own classes plus every class contributed by
|
|
6
|
+
* style-imported modules. Each module was renamed with its OWN `@setup` prefix
|
|
7
|
+
* before merging, so the merge is a pure table union, not a re-naming pass.
|
|
8
|
+
*
|
|
9
|
+
* Policy (owner decision of 2026-11-25, strict):
|
|
10
|
+
*
|
|
11
|
+
* - The same original class name resolving to the same emitted name in several
|
|
12
|
+
* modules is allowed and unifies into one entry at its first position.
|
|
13
|
+
* - The same original class name resolving to different emitted names is
|
|
14
|
+
* CHIKX4001: a single map key cannot have two values, and silently picking one
|
|
15
|
+
* would make `className` usage wrong in one of the modules. The first
|
|
16
|
+
* occurrence wins for deterministic recovery after the error.
|
|
17
|
+
* - A `:global(...)` reference and a local class of the same name are not a
|
|
18
|
+
* conflict: the local definition upgrades the entry in place exactly as the
|
|
19
|
+
* single-module rewrite does, and globals still never reach the map.
|
|
20
|
+
* - camelCase named-export alias uniqueness across the merged table is enforced
|
|
21
|
+
* afterwards by `generateClassMap`, which sees the merged table as one table.
|
|
22
|
+
* - A module that authors `@setup { map-inherit: false; }` is skipped entirely:
|
|
23
|
+
* its CSS still merges in cascade order, but none of its bindings reach the
|
|
24
|
+
* map or `.d.ts`, and it can never raise CHIKX4001 (ADR-0020, the documented
|
|
25
|
+
* exception to the §3 one-table lockstep).
|
|
26
|
+
*
|
|
27
|
+
* The pass is pure, deterministic and never mutates its inputs.
|
|
28
|
+
*/
|
|
29
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
30
|
+
import type { ClassTable } from "./types.js";
|
|
31
|
+
/** One renamed module table plus an optional human label for diagnostics. */
|
|
32
|
+
export interface ClassTableSource {
|
|
33
|
+
/** Table produced by `renameClasses` for one module (or the entry). */
|
|
34
|
+
readonly table: ClassTable;
|
|
35
|
+
/**
|
|
36
|
+
* Module identity used in conflict messages, normally the workspace-relative
|
|
37
|
+
* POSIX source path. Omitted for synthetic tables.
|
|
38
|
+
*/
|
|
39
|
+
readonly label?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether this table's bindings join the merged build (ADR-0020). Omitted
|
|
42
|
+
* means `true` (the ADR-0014 default); `false` excludes a style-merged
|
|
43
|
+
* module's bindings while leaving its CSS in the imported-first IR.
|
|
44
|
+
*/
|
|
45
|
+
readonly mapInherit?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Result of {@link mergeClassTables}. */
|
|
48
|
+
export interface MergedClassTable {
|
|
49
|
+
/** Union table in first-appearance order: style modules first, then the entry. */
|
|
50
|
+
readonly table: ClassTable;
|
|
51
|
+
/** CHIKX4001 diagnostics for same-name/different-emitted conflicts. */
|
|
52
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Merge renamed class tables into the one table a merged build exports.
|
|
56
|
+
*
|
|
57
|
+
* @param sources Renamed tables in emission order (style-imported modules
|
|
58
|
+
* depth-first, then the importing entry).
|
|
59
|
+
* @returns The union table plus any CHIKX4001 conflicts.
|
|
60
|
+
*/
|
|
61
|
+
export declare function mergeClassTables(sources: readonly ClassTableSource[]): MergedClassTable;
|
|
62
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/naming/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,gBAAgB,CAgDvF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged class tables for rule-bearing (`styles`) imports (ADR-0014).
|
|
3
|
+
*
|
|
4
|
+
* A merged build has ONE class map and ONE `.d.ts` for the importing file,
|
|
5
|
+
* covering the entry's own classes plus every class contributed by
|
|
6
|
+
* style-imported modules. Each module was renamed with its OWN `@setup` prefix
|
|
7
|
+
* before merging, so the merge is a pure table union, not a re-naming pass.
|
|
8
|
+
*
|
|
9
|
+
* Policy (owner decision of 2026-11-25, strict):
|
|
10
|
+
*
|
|
11
|
+
* - The same original class name resolving to the same emitted name in several
|
|
12
|
+
* modules is allowed and unifies into one entry at its first position.
|
|
13
|
+
* - The same original class name resolving to different emitted names is
|
|
14
|
+
* CHIKX4001: a single map key cannot have two values, and silently picking one
|
|
15
|
+
* would make `className` usage wrong in one of the modules. The first
|
|
16
|
+
* occurrence wins for deterministic recovery after the error.
|
|
17
|
+
* - A `:global(...)` reference and a local class of the same name are not a
|
|
18
|
+
* conflict: the local definition upgrades the entry in place exactly as the
|
|
19
|
+
* single-module rewrite does, and globals still never reach the map.
|
|
20
|
+
* - camelCase named-export alias uniqueness across the merged table is enforced
|
|
21
|
+
* afterwards by `generateClassMap`, which sees the merged table as one table.
|
|
22
|
+
* - A module that authors `@setup { map-inherit: false; }` is skipped entirely:
|
|
23
|
+
* its CSS still merges in cascade order, but none of its bindings reach the
|
|
24
|
+
* map or `.d.ts`, and it can never raise CHIKX4001 (ADR-0020, the documented
|
|
25
|
+
* exception to the §3 one-table lockstep).
|
|
26
|
+
*
|
|
27
|
+
* The pass is pure, deterministic and never mutates its inputs.
|
|
28
|
+
*/
|
|
29
|
+
import { error } from "../types/diagnostics.js";
|
|
30
|
+
/**
|
|
31
|
+
* Merge renamed class tables into the one table a merged build exports.
|
|
32
|
+
*
|
|
33
|
+
* @param sources Renamed tables in emission order (style-imported modules
|
|
34
|
+
* depth-first, then the importing entry).
|
|
35
|
+
* @returns The union table plus any CHIKX4001 conflicts.
|
|
36
|
+
*/
|
|
37
|
+
export function mergeClassTables(sources) {
|
|
38
|
+
const entries = [];
|
|
39
|
+
const indexes = new Map();
|
|
40
|
+
const owners = new Map();
|
|
41
|
+
const diagnostics = [];
|
|
42
|
+
for (const source of sources) {
|
|
43
|
+
// An opted-out module (ADR-0020) contributes rules to the stylesheet but no
|
|
44
|
+
// bindings to the merged table, so it cannot collide either.
|
|
45
|
+
if (source.mapInherit === false)
|
|
46
|
+
continue;
|
|
47
|
+
const label = source.label ?? "an unnamed source";
|
|
48
|
+
for (const entry of source.table.entries) {
|
|
49
|
+
const existingIndex = indexes.get(entry.name);
|
|
50
|
+
if (existingIndex === undefined) {
|
|
51
|
+
indexes.set(entry.name, entries.length);
|
|
52
|
+
owners.set(entry.name, label);
|
|
53
|
+
entries.push(entry);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const existing = entries[existingIndex];
|
|
57
|
+
if (existing === undefined) {
|
|
58
|
+
throw new Error("merged class table index out of range");
|
|
59
|
+
}
|
|
60
|
+
if (existing.global && !entry.global) {
|
|
61
|
+
// A local definition replaces a global-only reference in place: the
|
|
62
|
+
// class is exported once, from its first position (ADR-0010).
|
|
63
|
+
entries[existingIndex] = entry;
|
|
64
|
+
owners.set(entry.name, label);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (entry.global || existing.emitted === entry.emitted)
|
|
68
|
+
continue;
|
|
69
|
+
diagnostics.push(error("CHIKX4001", `Class "${entry.name}" is emitted as both "${existing.emitted}" (${owners.get(entry.name) ?? "an unnamed source"}) and "${entry.emitted}" (${label}); a merged build has one class map, so the first name wins (ADR-0014).`, entry.span));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
table: Object.freeze({ entries: Object.freeze(entries) }),
|
|
74
|
+
diagnostics,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/naming/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AA4BhD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAoC;IACnE,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,4EAA4E;QAC5E,6DAA6D;QAC7D,IAAI,MAAM,CAAC,UAAU,KAAK,KAAK;YAAE,SAAS;QAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,mBAAmB,CAAC;QAClD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACzC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC9C,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;gBACxC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACpB,SAAS;YACX,CAAC;YAED,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;YACxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YAED,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBACrC,oEAAoE;gBACpE,8DAA8D;gBAC9D,OAAO,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;gBAC/B,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC9B,SAAS;YACX,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;gBAAE,SAAS;YAEjE,WAAW,CAAC,IAAI,CACd,KAAK,CACH,WAAW,EACX,UAAU,KAAK,CAAC,IAAI,yBAAyB,QAAQ,CAAC,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,mBAAmB,UAAU,KAAK,CAAC,OAAO,MAAM,KAAK,yEAAyE,EAC3N,KAAK,CAAC,IAAI,CACX,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StylesheetIr } from "../ir/types.js";
|
|
2
|
+
import type { RenameOptions, RenameResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rename every local class token and unwrap `:global(...)` wrappers.
|
|
5
|
+
*
|
|
6
|
+
* @param ir Lowered (and normally substituted) stylesheet IR.
|
|
7
|
+
* @param options Effective prefix and strategy; `options.naming.prefix` wins
|
|
8
|
+
* over `options.prefix`, and the strategy defaults to `prefix`.
|
|
9
|
+
* @returns The rebuilt IR (the input instance when nothing changed), the
|
|
10
|
+
* first-appearance {@link ClassTable} and CHIKX4001 diagnostics for invalid
|
|
11
|
+
* prefix/result configurations.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renameClasses(ir: StylesheetIr, options?: RenameOptions): RenameResult;
|
|
14
|
+
//# sourceMappingURL=rewrite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/naming/rewrite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2C,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS5F,OAAO,KAAK,EAA0B,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA+PtF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CAkCzF"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { nativeBlockIr, ruleIr, stylesheetIr } from "../ir/factories.js";
|
|
2
|
+
import { flattenSelector } from "../selectors/index.js";
|
|
3
|
+
import { scanSelector } from "../selectors/scan.js";
|
|
4
|
+
import { error } from "../types/diagnostics.js";
|
|
5
|
+
import { applySelectorEdits, scanSelectorClasses } from "./scan.js";
|
|
6
|
+
import { isValidCssIdentifier, renameClassName } from "./table.js";
|
|
7
|
+
function computeEmitted(name, prefix, strategy, span, diagnostics, reported) {
|
|
8
|
+
const result = renameClassName(name, prefix, strategy);
|
|
9
|
+
if (!result.renamed) {
|
|
10
|
+
const applies = strategy === "prefix" && prefix !== "" && isValidCssIdentifier(prefix);
|
|
11
|
+
if (applies && !reported.has(name)) {
|
|
12
|
+
reported.add(name);
|
|
13
|
+
diagnostics.push(error("CHIKX4001", `Class "${name}" cannot be prefixed with "${prefix}": the result "${prefix}-${name}" is not a valid CSS identifier (SPECIFICATION.md §7.2). The class stays unprefixed.`, span));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function record(collector, token, span, prefix, strategy, diagnostics, reported) {
|
|
19
|
+
const existingIndex = collector.indexes.get(token.name);
|
|
20
|
+
if (existingIndex !== undefined) {
|
|
21
|
+
const existing = collector.entries[existingIndex];
|
|
22
|
+
if (existing === undefined) {
|
|
23
|
+
throw new Error("class table index out of range");
|
|
24
|
+
}
|
|
25
|
+
if (existing.global && !token.global) {
|
|
26
|
+
const computed = computeEmitted(token.name, prefix, strategy, span, diagnostics, reported);
|
|
27
|
+
const upgraded = Object.freeze({
|
|
28
|
+
name: token.name,
|
|
29
|
+
emitted: computed.emitted,
|
|
30
|
+
global: false,
|
|
31
|
+
renamed: computed.renamed,
|
|
32
|
+
span: existing.span,
|
|
33
|
+
});
|
|
34
|
+
collector.entries[existingIndex] = upgraded;
|
|
35
|
+
return upgraded;
|
|
36
|
+
}
|
|
37
|
+
return existing;
|
|
38
|
+
}
|
|
39
|
+
const computed = token.global
|
|
40
|
+
? { emitted: token.name, renamed: false }
|
|
41
|
+
: computeEmitted(token.name, prefix, strategy, span, diagnostics, reported);
|
|
42
|
+
const entry = Object.freeze({
|
|
43
|
+
name: token.name,
|
|
44
|
+
emitted: computed.emitted,
|
|
45
|
+
global: token.global,
|
|
46
|
+
renamed: computed.renamed,
|
|
47
|
+
span: Object.freeze(span),
|
|
48
|
+
});
|
|
49
|
+
collector.indexes.set(token.name, collector.entries.length);
|
|
50
|
+
collector.entries.push(entry);
|
|
51
|
+
return entry;
|
|
52
|
+
}
|
|
53
|
+
/** Rewrite one flat selector text and record its classes. */
|
|
54
|
+
function rewriteFlatSelector(text, span, collector, prefix, strategy, diagnostics, reported) {
|
|
55
|
+
if (!scanSelector(text).ok)
|
|
56
|
+
return text;
|
|
57
|
+
const scan = scanSelectorClasses(text);
|
|
58
|
+
if (!scan.ok)
|
|
59
|
+
return text;
|
|
60
|
+
const edits = [];
|
|
61
|
+
for (const global of scan.globals) {
|
|
62
|
+
const inner = text.slice(global.openEnd, global.closeStart).trim();
|
|
63
|
+
const contained = scan.classes.filter((token) => token.start >= global.openEnd && token.end <= global.closeStart);
|
|
64
|
+
// MVP supports a simple global class escape only (SPECIFICATION.md §7.2).
|
|
65
|
+
// A complex argument (comma list, combinator, several classes) is left
|
|
66
|
+
// wrapped and unrenamed rather than expanded into a selector whose meaning
|
|
67
|
+
// would change; its classes are still recorded as global.
|
|
68
|
+
const simple = contained.length === 1 && contained[0]?.raw === inner;
|
|
69
|
+
if (!simple)
|
|
70
|
+
continue;
|
|
71
|
+
edits.push({ start: global.start, end: global.openEnd, text: "" });
|
|
72
|
+
edits.push({ start: global.closeStart, end: global.end, text: "" });
|
|
73
|
+
}
|
|
74
|
+
for (const token of scan.classes) {
|
|
75
|
+
const entry = record(collector, token, span, prefix, strategy, diagnostics, reported);
|
|
76
|
+
if (!token.global && entry.renamed) {
|
|
77
|
+
edits.push({ start: token.start, end: token.end, text: `.${entry.emitted}` });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return applySelectorEdits(text, edits);
|
|
81
|
+
}
|
|
82
|
+
function rewriteRule(rule, collector, prefix, strategy, diagnostics, reported) {
|
|
83
|
+
const flattened = flattenSelector(rule.selector, rule.ancestors);
|
|
84
|
+
let selector;
|
|
85
|
+
let ancestors;
|
|
86
|
+
if (flattened.ok) {
|
|
87
|
+
selector = rewriteFlatSelector(flattened.selector, rule.span, collector, prefix, strategy, diagnostics, reported);
|
|
88
|
+
ancestors = [];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
selector = rewriteFlatSelector(rule.selector, rule.span, collector, prefix, strategy, diagnostics, reported);
|
|
92
|
+
ancestors = rule.ancestors.map((ancestor) => rewriteFlatSelector(ancestor, rule.span, collector, prefix, strategy, diagnostics, reported));
|
|
93
|
+
}
|
|
94
|
+
const ancestorsUnchanged = ancestors.length === rule.ancestors.length &&
|
|
95
|
+
ancestors.every((ancestor, index) => ancestor === rule.ancestors[index]);
|
|
96
|
+
if (selector === rule.selector && ancestorsUnchanged)
|
|
97
|
+
return rule;
|
|
98
|
+
return ruleIr({
|
|
99
|
+
selector,
|
|
100
|
+
ancestors,
|
|
101
|
+
declarations: rule.declarations,
|
|
102
|
+
condition: rule.condition,
|
|
103
|
+
context: rule.context,
|
|
104
|
+
span: rule.span,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function rewriteChild(child, collector, prefix, strategy, diagnostics, reported) {
|
|
108
|
+
if ("children" in child) {
|
|
109
|
+
return rewriteBlock(child, collector, prefix, strategy, diagnostics, reported);
|
|
110
|
+
}
|
|
111
|
+
if ("declarations" in child) {
|
|
112
|
+
return rewriteRule(child, collector, prefix, strategy, diagnostics, reported);
|
|
113
|
+
}
|
|
114
|
+
return child;
|
|
115
|
+
}
|
|
116
|
+
function rewriteBlock(block, collector, prefix, strategy, diagnostics, reported) {
|
|
117
|
+
if (block.statement === true)
|
|
118
|
+
return block;
|
|
119
|
+
const children = block.children.map((child) => rewriteChild(child, collector, prefix, strategy, diagnostics, reported));
|
|
120
|
+
if (children.every((child, index) => child === block.children[index]))
|
|
121
|
+
return block;
|
|
122
|
+
return nativeBlockIr({
|
|
123
|
+
name: block.name,
|
|
124
|
+
prelude: block.prelude,
|
|
125
|
+
children,
|
|
126
|
+
span: block.span,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function tableOf(collector) {
|
|
130
|
+
return Object.freeze({ entries: Object.freeze([...collector.entries]) });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Rename every local class token and unwrap `:global(...)` wrappers.
|
|
134
|
+
*
|
|
135
|
+
* @param ir Lowered (and normally substituted) stylesheet IR.
|
|
136
|
+
* @param options Effective prefix and strategy; `options.naming.prefix` wins
|
|
137
|
+
* over `options.prefix`, and the strategy defaults to `prefix`.
|
|
138
|
+
* @returns The rebuilt IR (the input instance when nothing changed), the
|
|
139
|
+
* first-appearance {@link ClassTable} and CHIKX4001 diagnostics for invalid
|
|
140
|
+
* prefix/result configurations.
|
|
141
|
+
*/
|
|
142
|
+
export function renameClasses(ir, options = {}) {
|
|
143
|
+
const strategy = options.naming?.strategy ?? "prefix";
|
|
144
|
+
const prefix = options.naming?.prefix ?? options.prefix ?? "";
|
|
145
|
+
const collector = { entries: [], indexes: new Map() };
|
|
146
|
+
const diagnostics = [];
|
|
147
|
+
const reported = new Set();
|
|
148
|
+
if (strategy === "prefix" && prefix !== "" && !isValidCssIdentifier(prefix)) {
|
|
149
|
+
// Report once, at the first class we can point at; if the stylesheet has no
|
|
150
|
+
// classes the invalid prefix is inert and reporting would have no location.
|
|
151
|
+
const firstRule = findFirstRuleSpan(ir);
|
|
152
|
+
if (firstRule !== null) {
|
|
153
|
+
diagnostics.push(error("CHIKX4001", `Invalid class prefix "${prefix}": it is not a valid CSS identifier, so classes stay unprefixed (SPECIFICATION.md §7.2).`, firstRule));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const rules = ir.rules.map((node) => "declarations" in node
|
|
157
|
+
? rewriteRule(node, collector, prefix, strategy, diagnostics, reported)
|
|
158
|
+
: rewriteBlock(node, collector, prefix, strategy, diagnostics, reported));
|
|
159
|
+
const changed = rules.every((node, index) => node === ir.rules[index]) === false;
|
|
160
|
+
return {
|
|
161
|
+
ir: changed ? stylesheetIr(rules) : ir,
|
|
162
|
+
classes: tableOf(collector),
|
|
163
|
+
diagnostics,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Span of the first rule node, or `null` for an empty stylesheet. */
|
|
167
|
+
function findFirstRuleSpan(ir) {
|
|
168
|
+
for (const node of ir.rules) {
|
|
169
|
+
if ("declarations" in node)
|
|
170
|
+
return node.span;
|
|
171
|
+
if (node.statement !== true) {
|
|
172
|
+
const found = findFirstRuleInChildren(node.children);
|
|
173
|
+
if (found !== null)
|
|
174
|
+
return found;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
function findFirstRuleInChildren(children) {
|
|
180
|
+
for (const child of children) {
|
|
181
|
+
if ("declarations" in child)
|
|
182
|
+
return child.span;
|
|
183
|
+
if ("children" in child) {
|
|
184
|
+
const found = findFirstRuleInChildren(child.children);
|
|
185
|
+
if (found !== null)
|
|
186
|
+
return found;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=rewrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite.js","sourceRoot":"","sources":["../../src/naming/rewrite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmDnE,SAAS,cAAc,CACrB,IAAY,EACZ,MAAc,EACd,QAA2B,EAC3B,IAAU,EACV,WAAyB,EACzB,QAAqB;IAErB,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,QAAQ,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACvF,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACnB,WAAW,CAAC,IAAI,CACd,KAAK,C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