@aestheticfunction/dspack-emit 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +1004 -222
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +66 -2
- package/dist/transform/model.d.ts +368 -0
- package/dist/transform/model.js +169 -0
- package/dist/transform/parse-v2.d.ts +109 -0
- package/dist/transform/parse-v2.js +479 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +608 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
- package/dist/transform/shadcn-v2-respelling.js +456 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +136 -0
- package/dist/types.d.ts +23 -0
- package/dist/validate/ajv.js +96 -25
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/a0.test.ts +235 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +102 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +369 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/t1.test.ts +369 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +1468 -235
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +60 -2
- package/src/transform/model.ts +427 -0
- package/src/transform/parse-v2.ts +608 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +608 -0
- package/src/transform/profile.v2.schema.json +600 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +475 -0
- package/src/transform/validate-v2.ts +174 -0
- package/src/types.ts +32 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ordered surface diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* The v1 engine emitted warnings by pushing them onto an array wherever it
|
|
5
|
+
* happened to be. That made the emitted order an ACCIDENT of method order and
|
|
6
|
+
* traversal — invisible while one implementation existed, and load-bearing the
|
|
7
|
+
* moment a second one appeared, because the byte gate hashes warnings.
|
|
8
|
+
*
|
|
9
|
+
* An engine driven by routes and collects resolves work in declaration order,
|
|
10
|
+
* which is NOT v1's method order. Left implicit, the rewrite would emit the
|
|
11
|
+
* same warnings in a different sequence and fail the gate for a reason that has
|
|
12
|
+
* nothing to do with correctness — and the temptation would be to "fix" it by
|
|
13
|
+
* re-baselining the hashes, which would silently discard the guarantee.
|
|
14
|
+
*
|
|
15
|
+
* So order becomes explicit data. Every diagnostic carries a sort key; the
|
|
16
|
+
* engine collects them in whatever order it likes and sorts once at the end.
|
|
17
|
+
* The key reproduces v1 exactly, and — because it is declared rather than
|
|
18
|
+
* emergent — keeps reproducing it under later refactors.
|
|
19
|
+
*
|
|
20
|
+
* The phases below are DERIVED from the v1 engine, not designed: each is the
|
|
21
|
+
* point in `emitNode` where that warning was pushed. They are numbered in that
|
|
22
|
+
* method's execution order, and the numbering is the compatibility contract.
|
|
23
|
+
*/
|
|
24
|
+
import type { SurfaceFidelityEntry, Warning } from "../../types.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Legacy emission phases, in v1 `emitNode` execution order.
|
|
28
|
+
*
|
|
29
|
+
* Read alongside the pre-rewrite `emitNode`: id allocation happened first, then
|
|
30
|
+
* prop projection, then the two consuming strategies (each ending with its own
|
|
31
|
+
* composition warning), then text-child synthesis, then the synthesized action,
|
|
32
|
+
* then the child-list rewrite — and only after every child had emitted did the
|
|
33
|
+
* single-slot wrap run.
|
|
34
|
+
*/
|
|
35
|
+
export enum Phase {
|
|
36
|
+
/** `allocateId` for this node — v1 allocated before any projection. */
|
|
37
|
+
IdAllocation = 0,
|
|
38
|
+
/** `applyPropMap`: dropped props and unprojectable values. */
|
|
39
|
+
PropMap = 1,
|
|
40
|
+
/** `applySubContent`'s audited label lift. */
|
|
41
|
+
LabelLift = 2,
|
|
42
|
+
/** `applySubContent`'s closing composition-flattened warning. */
|
|
43
|
+
SubContentFlatten = 3,
|
|
44
|
+
/** `applySubTable`'s per-cell flattening and per-sub drops. */
|
|
45
|
+
TableBody = 4,
|
|
46
|
+
/** `applySubTable`'s closing composition-flattened warning. */
|
|
47
|
+
TableFlatten = 5,
|
|
48
|
+
/** `emitTextPrimitive` invoked by the text-child route. */
|
|
49
|
+
TextChild = 6,
|
|
50
|
+
/** The synthesized declarative action. */
|
|
51
|
+
Action = 7,
|
|
52
|
+
/** `flattenSubs` rewriting the child list before children emit. */
|
|
53
|
+
ChildRewrite = 8,
|
|
54
|
+
/** `wrapInColumn` — runs AFTER every child has emitted. */
|
|
55
|
+
Wrap = 9,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Where a diagnostic sits relative to this node's children. v1's array order is
|
|
60
|
+
* a pre-order walk in which a parent's pre-child warnings precede all of its
|
|
61
|
+
* descendants' warnings, and its post-child warnings follow all of them — so a
|
|
62
|
+
* flat `(node, phase)` sort would wrongly hoist the wrap warning above the
|
|
63
|
+
* children it wraps.
|
|
64
|
+
*/
|
|
65
|
+
export enum Band {
|
|
66
|
+
BeforeChildren = 0,
|
|
67
|
+
Children = 1,
|
|
68
|
+
AfterChildren = 2,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Diagnostic {
|
|
72
|
+
warning: Warning;
|
|
73
|
+
/**
|
|
74
|
+
* Lexicographically ordered key. Shape, per tree level:
|
|
75
|
+
* [...ancestorPath, Band.Children, childIndex] repeated to reach the node,
|
|
76
|
+
* then [band, phase, rule, seq].
|
|
77
|
+
* Nesting bands this way is what makes a parent's post-child diagnostics sort
|
|
78
|
+
* after its whole subtree without any special case.
|
|
79
|
+
*/
|
|
80
|
+
key: number[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Compares two diagnostic keys lexicographically; shorter sorts first on a tie. */
|
|
84
|
+
export function compareKeys(a: number[], b: number[]): number {
|
|
85
|
+
const n = Math.min(a.length, b.length);
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
if (a[i] !== b[i]) return a[i] - b[i];
|
|
88
|
+
}
|
|
89
|
+
return a.length - b.length;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Collects diagnostics with explicit ordering and returns them in legacy order.
|
|
94
|
+
*
|
|
95
|
+
* `seq` is a monotonic counter used only as the final tie-breaker, so two
|
|
96
|
+
* diagnostics identical in every declared dimension still order deterministically
|
|
97
|
+
* — by the order the engine produced them, which is itself deterministic.
|
|
98
|
+
*/
|
|
99
|
+
export class Diagnostics {
|
|
100
|
+
private readonly items: Diagnostic[] = [];
|
|
101
|
+
private readonly fidelityItems: Array<{ entry: SurfaceFidelityEntry; key: number[] }> = [];
|
|
102
|
+
private seq = 0;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param path the node's tree path (alternating Band.Children / child index)
|
|
106
|
+
* @param band where this sits relative to the node's children
|
|
107
|
+
* @param phase the legacy emission phase
|
|
108
|
+
* @param rule index of the desugared rule that produced it, for stable order
|
|
109
|
+
* among several routes writing in the same phase
|
|
110
|
+
*/
|
|
111
|
+
push(warning: Warning, path: readonly number[], band: Band, phase: Phase, rule = 0): void {
|
|
112
|
+
this.items.push({ warning, key: [...path, band, phase, rule, this.seq++] });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Legacy-ordered warnings. Sorting once at the end is the whole point. */
|
|
116
|
+
ordered(): Warning[] {
|
|
117
|
+
return [...this.items].sort((a, b) => compareKeys(a.key, b.key)).map((d) => d.warning);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The fidelity ledger rides the same ordering discipline as the warnings —
|
|
122
|
+
* an entry's position is declared by (path, band, phase, rule), never by
|
|
123
|
+
* when the engine happened to record it.
|
|
124
|
+
*/
|
|
125
|
+
pushFidelity(entry: SurfaceFidelityEntry, path: readonly number[], band: Band, phase: Phase, rule = 0): void {
|
|
126
|
+
this.fidelityItems.push({ entry, key: [...path, band, phase, rule, this.seq++] });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
orderedFidelity(): SurfaceFidelityEntry[] {
|
|
130
|
+
return [...this.fidelityItems].sort((a, b) => compareKeys(a.key, b.key)).map((d) => d.entry);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get length(): number {
|
|
134
|
+
return this.items.length;
|
|
135
|
+
}
|
|
136
|
+
}
|