Skip to content

Commit fd8cb2f

Browse files
committed
checkpoint
1 parent ee394f8 commit fd8cb2f

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/loader/merge.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,18 @@ export const mergeFormats = (formats: Format[], root?: RawObject, inheritedType?
7373
// Do NOT pass it into $value content — type is DTCG metadata on the token
7474
// node itself, not something that should bleed into value sub-objects.
7575
const sub = mergeFormats(subFormats as Format[], effectiveRoot, key === "$value" ? undefined : getNodeType()) as unknown as RawObject;
76-
// Leaf token: unwrap to the resolved value so callers get the value
77-
// directly (e.g. tokens["box-shadow"].panel → shadow array, not { $type, $value }).
78-
// Group nodes have no $value and pass through as-is.
79-
value = "$value" in sub ? sub.$value : sub;
76+
if ("$value" in sub) {
77+
// Leaf token: unwrap to the resolved value so callers get the value
78+
// directly (e.g. tokens["focus-ring"].dark → border object, not { $type, $value }).
79+
value = sub.$value;
80+
} else if (key === "$value") {
81+
// $value is a plain object (e.g. a border or color composite) — resolve
82+
// any alias strings or $ref objects inside it, same as the array branch.
83+
value = resolveDeep(sub, effectiveRoot);
84+
} else {
85+
// Group node: pass through as a navigable merged object.
86+
value = sub;
87+
}
8088
} else if (hasLeaf) {
8189
// Deeply resolve aliases and $ref objects inside $value.
8290
value = key === "$value" ? resolveDeep(leafValue, effectiveRoot) : leafValue;

src/scratch.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ const resolverURL = new URL("../src/test/example/design-tokens.resolver.json", i
44

55
const { tokens } = load(resolverURL);
66

7-
// Leaf token: should be the resolved value directly, no $type/$value wrapper
8-
console.log("panel shadow:", JSON.stringify((tokens as any)["box-shadow"].panel, null, 2));
7+
// focus-ring dark: alias "{color.blue.600.dark}" inside plain-object $value should resolve
8+
console.log("focus-ring dark:", JSON.stringify((tokens as any)["focus-ring"].dark, null, 2));
99

10-
// Group node: should still be a navigable object
11-
console.log("box-shadow group $type:", (tokens as any)["box-shadow"].$type);
12-
13-
// Alias resolution inside the value
14-
console.log("panel[0].offsetX:", (tokens as any)["box-shadow"].panel[0].offsetX);
10+
// focus-ring light: same for light
11+
console.log("focus-ring light color:", (tokens as any)["focus-ring"].light?.color);

0 commit comments

Comments
 (0)