Skip to content

Commit

Permalink
Merge pull request #65 from danieldelcore/fix-object-parsing
Browse files Browse the repository at this point in the history
🐛 Fixes object style parsing with numbers
  • Loading branch information
danieldelcore authored May 25, 2020
2 parents 6cb9544 + c2853fb commit b58d88f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/loud-clocks-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@trousers/parser': patch
---

Object styles containing mixed value types (string/number) will now be parsed correectly
9 changes: 9 additions & 0 deletions packages/parser/src/parse-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ describe('parseObject', () => {
);
});

it('correctly converts a mixed-unit style object', () => {
const result = parseObject({
width: '2px',
height: 0,
});

expect(result).toEqual('width: 2px;\nheight: 0;');
});

it('correctly converts style object with a nested selector', () => {
const result = parseObject({
':hover': {
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/src/parse-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const parseObject = (
): string =>
Object.keys(styleObj)
.map(property =>
typeof styleObj[property] === 'string'
typeof styleObj[property] === 'string' ||
typeof styleObj[property] === 'number'
? `${parser(property)}: ${styleObj[property]};`
: `${parser(property)} {\n${parseObject(
styleObj[property],
Expand Down

0 comments on commit b58d88f

Please sign in to comment.