diff --git a/src/grammar.ne b/src/grammar.ne index f38efe7..50ee2e3 100644 --- a/src/grammar.ne +++ b/src/grammar.ne @@ -49,7 +49,8 @@ }; %} -number -> ([0-9]:+) {% d => Number(text(d)) %} +number + -> "-":? ([0-9]:? "." [0-9]:+ | [1-9] [0-9]:* | "0") {% d => Number(text(d)) %} angle -> number ("deg" | "rad") {% text %} diff --git a/src/index.test.js b/src/index.test.js index f26d4eb..fd83e8f 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -17,6 +17,24 @@ it('allows decimal values', () => runTest([ ['top', '1.5'], ], { top: 1.5 })); +it('allows decimal values in transformed values', () => runTest([ + ['border-radius', '1.5'], +], { + borderTopLeftRadius: 1.5, + borderTopRightRadius: 1.5, + borderBottomRightRadius: 1.5, + borderBottomLeftRadius: 1.5, +})); + +it('allows negative values in transformed values', () => runTest([ + ['border-radius', '-1.5'], +], { + borderTopLeftRadius: -1.5, + borderTopRightRadius: -1.5, + borderBottomRightRadius: -1.5, + borderBottomLeftRadius: -1.5, +})); + it('transforms strings', () => runTest([ ['color', 'red'], ], { color: 'red' }));