@terrazzo/parser 0.10.3 → 0.10.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrazzo/parser",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "Parser/validator for the Design Tokens Community Group (DTCG) standard.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,9 +34,9 @@
34
34
  "directory": "./packages/parser/"
35
35
  },
36
36
  "dependencies": {
37
- "@humanwhocodes/momoa": "^3.3.8",
37
+ "@humanwhocodes/momoa": "^3.3.9",
38
38
  "@types/babel__code-frame": "^7.0.6",
39
- "@types/culori": "^4.0.0",
39
+ "@types/culori": "^4.0.1",
40
40
  "culori": "^4.0.2",
41
41
  "merge-anything": "^5.1.7",
42
42
  "picocolors": "^1.1.1",
@@ -45,7 +45,7 @@
45
45
  "@terrazzo/token-tools": "^0.10.3"
46
46
  },
47
47
  "devDependencies": {
48
- "yaml-to-momoa": "^0.0.3"
48
+ "yaml-to-momoa": "^0.0.6"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rolldown -c && attw --profile esm-only --pack .",
@@ -62,9 +62,9 @@ export interface Options {
62
62
  */
63
63
  function getMarkerLines(loc: NodeLocation, source: string[], opts: Options = {} as Options) {
64
64
  const startLoc = {
65
- // @ts-ignore this is fine
65
+ // @ts-expect-error this is fine
66
66
  column: 0,
67
- // @ts-ignore this is fine
67
+ // @ts-expect-error this is fine
68
68
  line: -1,
69
69
  ...loc.start,
70
70
  } as Location;
@@ -256,8 +256,18 @@ async function parseSingle(
256
256
  const inheritedTypeNode = computeInheritedProperty(node, '$type', { subpath, inherited: $typeInheritance });
257
257
  if (node.value.type === 'Object') {
258
258
  const $value = node.value.members.find((m) => m.name.type === 'String' && m.name.value === '$value');
259
- if ($value && inheritedTypeNode?.value.type === 'String' && transform?.[inheritedTypeNode.value.value]) {
260
- const result = transform[inheritedTypeNode.value.value]?.(evaluate(node.value), subpath.join('.'), node);
259
+
260
+ // Call transform using either inherited type or token-level type
261
+ let typeNode = inheritedTypeNode;
262
+ if (!typeNode) {
263
+ const local$type = node.value.members.find((m) => m.name.type === 'String' && m.name.value === '$type');
264
+ if (local$type) {
265
+ typeNode = local$type as MemberNode;
266
+ }
267
+ }
268
+
269
+ if ($value && typeNode?.value.type === 'String' && transform?.[typeNode.value.value]) {
270
+ const result = transform[typeNode.value.value]?.(evaluate(node.value), subpath.join('.'), node);
261
271
  if (result) {
262
272
  node.value = parseJSON(result).body;
263
273
  }