Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(formats): fix max call stack issue on json/nested format #465

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -71,7 +71,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 @@ -784,14 +789,14 @@ module.exports = {
* @example
* ```dart
* import 'package:flutter/material.dart';
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

*
* class StyleDictionary {
* StyleDictionary._();
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

*
* static const colorBrandPrimary = Color(0x00ff5fff);
* static const sizeFontSizeMedium = 16.00;
* static const contentFontFamily1 = "NewJune";
* ```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

* ```
*/
'flutter/class.dart': _.template(
fs.readFileSync(__dirname + '/templates/flutter/class.dart.template')
Expand Down