Skip to content

Commit

Permalink
fix: missing filepath in falsy token values (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-richter authored Jul 6, 2024
1 parent 3ae67e3 commit 61b6984
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tender-carrots-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Fix 'filePath' missing from falsy token values
2 changes: 2 additions & 0 deletions __tests__/__json_files/not_circular.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"prop0" : { "value": 0 },
"prop01" : { "value": "" },
"prop1" : { "value": "test1 value" },
"prop2" : { "value": "test2 value" },
"prop3" : { "value": "{prop1.value}" },
Expand Down
14 changes: 14 additions & 0 deletions __tests__/utils/combineJSON.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ describe('utils', () => {
expect(tokens).to.have.nested.property('d.e.f.h', 2);
});

it('should apply filePath for "falsy" values', async () => {
const { tokens } = await combineJSON(['__tests__/__json_files/not_circular.json']);
expect(tokens).to.have.deep.property('prop0', {
value: 0,
filePath: '__tests__/__json_files/not_circular.json',
isSource: true,
});
expect(tokens).to.have.deep.property('prop01', {
value: '',
filePath: '__tests__/__json_files/not_circular.json',
isSource: true,
});
});

it('should fail on invalid JSON', async () => {
await expectThrowsAsync(
() => combineJSON(['__tests__/__json_files/broken/*.json']),
Expand Down
2 changes: 2 additions & 0 deletions __tests__/utils/resolveObject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ describe('utils', () => {
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).to.equal(0);
expect(JSON.stringify(obj)).to.equal(
JSON.stringify({
prop0: { value: 0 },
prop01: { value: '' },
prop1: { value: 'test1 value' },
prop2: { value: 'test2 value' },
prop3: { value: 'test1 value' },
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/combineJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { detectDtcgSyntax } from './detectDtcgSyntax.js';
function traverseObj(obj, fn) {
for (let key in obj) {
const prop = obj[key];
if (prop) {
if (prop != null) {
fn.apply(null, [obj, key, prop]);
if (typeof prop === 'object') {
traverseObj(prop, fn);
Expand Down

0 comments on commit 61b6984

Please sign in to comment.