Skip to content

Commit 90dd5dd

Browse files
authored
Merge pull request #9 from styled-components/fix-decimal-numbers
Fix numbers with decimals
2 parents 390e15d + 79589b2 commit 90dd5dd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/grammar.ne

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
};
5050
%}
5151

52-
number -> ([0-9]:+) {% d => Number(text(d)) %}
52+
number
53+
-> "-":? ([0-9]:? "." [0-9]:+ | [1-9] [0-9]:* | "0") {% d => Number(text(d)) %}
5354

5455
angle -> number ("deg" | "rad") {% text %}
5556

src/index.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ it('allows decimal values', () => runTest([
1717
['top', '1.5'],
1818
], { top: 1.5 }));
1919

20+
it('allows decimal values in transformed values', () => runTest([
21+
['border-radius', '1.5'],
22+
], {
23+
borderTopLeftRadius: 1.5,
24+
borderTopRightRadius: 1.5,
25+
borderBottomRightRadius: 1.5,
26+
borderBottomLeftRadius: 1.5,
27+
}));
28+
29+
it('allows negative values in transformed values', () => runTest([
30+
['border-radius', '-1.5'],
31+
], {
32+
borderTopLeftRadius: -1.5,
33+
borderTopRightRadius: -1.5,
34+
borderBottomRightRadius: -1.5,
35+
borderBottomLeftRadius: -1.5,
36+
}));
37+
2038
it('transforms strings', () => runTest([
2139
['color', 'red'],
2240
], { color: 'red' }));

0 commit comments

Comments
 (0)