Skip to content

fix: apply transform visitors to resolver-loaded tokens#730

Open
avasis-ai wants to merge 5 commits intoterrazzoapp:mainfrom
avasis-ai:fix/653-resolver-transforms
Open

fix: apply transform visitors to resolver-loaded tokens#730
avasis-ai wants to merge 5 commits intoterrazzoapp:mainfrom
avasis-ai:fix/653-resolver-transforms

Conversation

@avasis-ai
Copy link
Copy Markdown
Contributor

Fixes #653

Summary

When using transform option with resolvers, the transform visitors were only applied during the initial parse and not when resolvers expanded into sub-sources.

Root Cause

transform was applied in loadSources → bundle() but never threaded into loadResolver → createResolver().apply(). Resolvers built a momoa AST from merged JS objects and skipped the transform step entirely.

Changes

  • packages/parser/src/parse/index.ts: Pass transform to loadResolver()
  • packages/parser/src/parse/load.ts: Extract applyTransformVisitors() from transformer() for reuse
  • packages/parser/src/resolver/load.ts: Thread transform through the resolver pipeline; apply visitors to momoa AST before processTokens()
  • packages/parser/test/resolver.test.ts: 2 new tests: visitors fire for resolver-loaded tokens; visitors can modify/delete tokens

Test plan

  • 262 parser tests pass (25 files, 0 failures)
  • New tests verify transform visitors apply to resolver-loaded tokens
  • No regressions

…razzoapp#546)

When a Buffer or other binary object is passed to the parser, it now
throws a clear error instead of silently finding 0 tokens.

Also updates JS API docs to use fs.readFile(filename, 'utf-8').
…pp#653)

Thread the transform option through the resolver path so that transform
visitors (group, token, type-specific) are applied to tokens loaded via
resolver documents. Previously transforms were only applied in the
non-resolver (direct token file) code path.

- Extract applyTransformVisitors() from transformer() in parse/load.ts
- Pass transform through loadResolver → createResolver → apply()
- Apply transforms to the momoa AST in createResolver().apply() before
  processTokens is called
- Add tests verifying visitors fire and can modify tokens via resolver
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: de6eeb1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@terrazzo/parser Patch
@terrazzo/cli Patch
@terrazzo/plugin-css-in-js Patch
@terrazzo/plugin-css Patch
@terrazzo/plugin-js Patch
@terrazzo/plugin-sass Patch
@terrazzo/plugin-swift Patch
@terrazzo/plugin-tailwind Patch
@terrazzo/plugin-token-listing Patch
@terrazzo/plugin-vanilla-extract Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transform in parse not applied when using resolvers

2 participants