Skip to content

Commit

Permalink
Don’t parse values in
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Nov 30, 2024
1 parent 7d12e94 commit db3fbbb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/cyan-ties-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@terrazzo/parser": patch
"@terrazzo/cli": patch
"@terrazzo/token-tools": patch
---

Ignore token-like structures inside $extensions
5 changes: 4 additions & 1 deletion packages/parser/src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ async function parseSingle(

const id = path.join('.');

if (members.$value) {
if (
members.$value &&
!path.includes('$extensions') // don’t validate anything in $extensions
) {
const extensions = members.$extensions ? getObjMembers(members.$extensions as ObjectNode) : undefined;
const sourceNode = structuredClone(node);

Expand Down
34 changes: 34 additions & 0 deletions packages/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2648,4 +2648,38 @@ describe('Additional cases', () => {
}
});
});

describe('$extensions', () => {
const tests: [string, { given: any; want: any }][] = [
[
'$value is ignored',
{
given: [
{
filename: DEFAULT_FILENAME,
src: {
emptyGroup: { $extensions: { foo: { $value: 'bar' } } },
color: {
$type: 'color',
blue: { $value: { colorSpace: 'srgb', channels: [0.2, 0.4, 0.8], alpha: 1 } },
$extensions: { fake: { $value: 'foo' } },
},
},
},
],
want: {
'color.blue': { alpha: 1, channels: [0.2, 0.4, 0.8], colorSpace: 'srgb' },
},
},
],
];

it.each(tests)('%s', async (_, { given, want }) => {
const config = defineConfig({}, { cwd });
const { tokens } = await parse(given, { config });
for (const id in want) {
expect(tokens[id]!.$value).toEqual(want[id]);
}
});
});
});

0 comments on commit db3fbbb

Please sign in to comment.