Skip to content

Transform in parse not applied when using resolvers #653

@dgtlntv

Description

@dgtlntv

Versions

  • @terrazzo/parser: 2.0.0-beta.2

Node.js version

v25.2.1

OS + version

macOS Darwin 24.1.0 arm64

Description

When attempting to use the Transform API with the parser for preprocessing tokens, the transformation seems to be ignored when resolvers (instead of simple files) are used.

Reproduction

// foundation.tokens.json
{
  "color": {
    "$type": "color",
    "$description": "Foundation colors"
  }
}
// tokens.resolver.json
{
  "$schema": "https://designtokens.org/schemas/2025.10/resolver.json",
  "version": "2025.10",
  "sets": {
    "foundation": {
      "sources": [{ "$ref": "./foundation.tokens.json" }]
    }
  },
  "resolutionOrder": [
    { "$ref": "#/sets/foundation" }
  ]
}
// index.ts
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig, parse, type TransformVisitors } from "@terrazzo/parser";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const config = defineConfig({}, { cwd: new URL(`file://${__dirname}/`) });

const transform: TransformVisitors = {
  group(_node, ctx) {
    console.log(`  [transform] visited group at path: ${ctx.path.join(".")}`);
  },
};

const tokenFile = path.join(__dirname, "foundation.tokens.json");
const resolverFile = path.join(__dirname, "tokens.resolver.json");

// ── Test 1: Plain token file ─────────────────────────────────────────────
console.log("TEST 1: Plain token file with transform\n");
try {
  await parse(
    [{ filename: new URL(`file://${tokenFile}`), src: fs.readFileSync(tokenFile, "utf8") }],
    { config, transform },
  );
} catch {}

// ── Test 2: Resolver file ────────────────────────────────────────────────
console.log("\nTEST 2: Resolver file with transform\n");
try {
  await parse(
    [{ filename: new URL(`file://${resolverFile}`), src: fs.readFileSync(resolverFile, "utf8") }],
    { config, transform },
  );
} catch {}

Output:

TEST 1: Plain token file with transform

  [transform] visited group at path: color

TEST 2: Resolver file with transform

Expected result

That transform can also be used when using resolvers. (Unless preprocessing should be done differently when using resolvers?)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparser@terrazzo/parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions