Skip to content

Commit

Permalink
fix(formats): fix max call stack issue on json/nested format (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanksdesign committed Oct 8, 2020
1 parent fa82002 commit 67fb361
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions __tests__/formats/jsonNested.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var dictionary = {
properties: {
color: {
base: {
comment: 'This is a comment',
metadata: [1,2,3],
red: {
primary: { value: '#611D1C' },
secondary: {
Expand Down Expand Up @@ -55,5 +57,17 @@ describe('formats', function() {
expect(test.color.base.red.secondary.inverse)
.toEqual(dictionary.properties.color.base.red.secondary.inverse.value);
});

it('should handle non-token data', function() {
// non-token data is anything in the dictionary object that is not a token object
// i.e. anything in the rest of the object that doesn't have a 'value'

fs.writeFileSync('./__tests__/__output/json-nested.json', formatter(dictionary));
var test = require('../__output/json-nested.json');
expect(test.color.base.comment)
.toEqual(dictionary.properties.color.base.comment);
expect(test.color.base.metadata)
.toEqual(dictionary.properties.color.base.metadata);
})
});
});
11 changes: 8 additions & 3 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ function iconsWithPrefix(prefix, properties, config) {
}

function minifyDictionary(obj) {
if (typeof obj !== 'object' || Array.isArray(obj)) {
return obj;
}

var toRet = {};

if (obj.hasOwnProperty('value')) {
return obj.value;
} else {
Expand Down Expand Up @@ -809,14 +814,14 @@ module.exports = {
* @example
* ```dart
* import 'package:flutter/material.dart';
*
*
* class StyleDictionary {
* StyleDictionary._();
*
*
* static const colorBrandPrimary = Color(0x00ff5fff);
* static const sizeFontSizeMedium = 16.00;
* static const contentFontFamily1 = "NewJune";
* ```
* ```
*/
'flutter/class.dart': _.template(
fs.readFileSync(__dirname + '/templates/flutter/class.dart.template')
Expand Down

0 comments on commit 67fb361

Please sign in to comment.