Skip to content

Weak type checking in parser following JSON $refs update #559

@Sidnioulz

Description

@Sidnioulz

Versions

main as of 2025-10-05

Node.js version

24.4.1

OS + version

Linux 6.16.8-arch3-1

Description

In packages/parser/src/parse/token.ts:

  const $extensions = getObjMember(node, '$extensions');
  if ($extensions) {
    const modeNode = getObjMember($extensions as momoa.ObjectNode, 'mode') as momoa.ObjectNode;
    for (const mode of Object.keys((token.$extensions as any).mode)) {
      const modeValue = (token.$extensions as any).mode[mode];
      token.mode[mode] = {
        // ...
      };
    }
  }

(token.$extensions as any).mode can be undefined and is not guarded, causing an error when running TZ with an outdated tokens.json. The error is cryptic as it says "Cannot convert undefined or null to object".

Reproduction

Do a quick merge/rebase of the tokens listing branch, and without editing fixtures, run tests.

Expected result

I'd expect the parser to detect what exactly is missing and to provide a good error message.

Considering that $extensions.mode was previously assumed to exist when $extensions did, a message tailored at existing TZ users, telling them to update JSON files, could be relevant.

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