From 5dce7fe5089d821fe7016b5b00ef34a50011ce4a Mon Sep 17 00:00:00 2001 From: Jacob Parker Date: Mon, 21 Nov 2016 13:46:53 +0000 Subject: [PATCH 1/2] Fix numbers with decimals --- src/grammar.ne | 5 ++++- src/index.test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/grammar.ne b/src/grammar.ne index f38efe7..f1c10f3 100644 --- a/src/grammar.ne +++ b/src/grammar.ne @@ -49,7 +49,10 @@ }; %} -number -> ([0-9]:+) {% d => Number(text(d)) %} +number + -> ([0-9]:? "." [0-9]:+) {% d => Number(text(d)) %} + | ([1-9] [0-9]:*) {% d => Number(text(d)) %} + | "0" {% d => Number(text(d)) %} angle -> number ("deg" | "rad") {% text %} diff --git a/src/index.test.js b/src/index.test.js index f26d4eb..9f80945 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -17,6 +17,15 @@ 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('transforms strings', () => runTest([ ['color', 'red'], ], { color: 'red' })); From 79589b27e9d9d75f04e9005fa42b1b8f740fa5df Mon Sep 17 00:00:00 2001 From: Jacob Parker Date: Mon, 21 Nov 2016 13:51:40 +0000 Subject: [PATCH 2/2] Fix negative values --- src/grammar.ne | 4 +--- src/index.test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/grammar.ne b/src/grammar.ne index f1c10f3..50ee2e3 100644 --- a/src/grammar.ne +++ b/src/grammar.ne @@ -50,9 +50,7 @@ %} number - -> ([0-9]:? "." [0-9]:+) {% d => Number(text(d)) %} - | ([1-9] [0-9]:*) {% d => Number(text(d)) %} - | "0" {% d => Number(text(d)) %} + -> "-":? ([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 9f80945..fd83e8f 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -26,6 +26,15 @@ it('allows decimal values in transformed values', () => runTest([ 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' }));