diff --git a/.changeset/tender-carrots-accept.md b/.changeset/tender-carrots-accept.md new file mode 100644 index 000000000..7d7338e11 --- /dev/null +++ b/.changeset/tender-carrots-accept.md @@ -0,0 +1,5 @@ +--- +'style-dictionary': patch +--- + +Fix 'filePath' missing from falsy token values diff --git a/__tests__/__json_files/not_circular.json b/__tests__/__json_files/not_circular.json index c74c79eb1..c8b0e4cd1 100644 --- a/__tests__/__json_files/not_circular.json +++ b/__tests__/__json_files/not_circular.json @@ -1,4 +1,6 @@ { + "prop0" : { "value": 0 }, + "prop01" : { "value": "" }, "prop1" : { "value": "test1 value" }, "prop2" : { "value": "test2 value" }, "prop3" : { "value": "{prop1.value}" }, diff --git a/__tests__/utils/combineJSON.test.js b/__tests__/utils/combineJSON.test.js index ea3361678..28d38b616 100644 --- a/__tests__/utils/combineJSON.test.js +++ b/__tests__/utils/combineJSON.test.js @@ -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']), diff --git a/__tests__/utils/resolveObject.test.js b/__tests__/utils/resolveObject.test.js index f4fd59b5e..0df0ca8bc 100644 --- a/__tests__/utils/resolveObject.test.js +++ b/__tests__/utils/resolveObject.test.js @@ -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' }, diff --git a/lib/utils/combineJSON.js b/lib/utils/combineJSON.js index e271c870b..334a45bab 100644 --- a/lib/utils/combineJSON.js +++ b/lib/utils/combineJSON.js @@ -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);