From 3d401e9167e767705c5f9aeee5eedcfb8da75cdb Mon Sep 17 00:00:00 2001 From: amin roosta Date: Wed, 21 Jun 2017 02:40:31 +0430 Subject: [PATCH 1/2] Fix DirectionFactory to support shorthand syntax without unit (margin: 2 5;) --- src/index.test.js | 10 +++++----- src/transforms/util.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index 436dd8d..1b95167 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -83,12 +83,12 @@ it('allows color values in transformed border-color values', () => runTest([ })); it('allows omitting units for 0', () => runTest([ - ['margin', '10px 0'], + ['margin', '10 5'], ], { marginTop: 10, - marginRight: 0, + marginRight: 5, marginBottom: 10, - marginLeft: 0, + marginLeft: 5, })); it('transforms strings', () => runTest([ @@ -432,6 +432,6 @@ it('allows blacklisting shorthands', () => { }); it('throws useful errors', () => { - expect(() => transformCss([['margin', '10']])) - .toThrow('Failed to parse declaration "margin: 10"'); + expect(() => transformCss([['margin', '#fff']])) + .toThrow('Failed to parse declaration "margin: #fff'); }); diff --git a/src/transforms/util.js b/src/transforms/util.js index 03bdcf1..bafe5a1 100644 --- a/src/transforms/util.js +++ b/src/transforms/util.js @@ -1,9 +1,9 @@ const { tokens } = require('../tokenTypes'); -const { LENGTH, PERCENT, SPACE } = tokens; +const { LENGTH, PERCENT, NUMBER, SPACE } = tokens; module.exports.directionFactory = ({ - types = [LENGTH, PERCENT], + types = [LENGTH, PERCENT, NUMBER], directions = ['Top', 'Right', 'Bottom', 'Left'], prefix = '', suffix = '', From aa5679c4d95d6159b201084ca400b1067229e03b Mon Sep 17 00:00:00 2001 From: amin roosta Date: Wed, 21 Jun 2017 02:45:39 +0430 Subject: [PATCH 2/2] better test cases --- src/index.test.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index 1b95167..f871ccf 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -83,12 +83,21 @@ it('allows color values in transformed border-color values', () => runTest([ })); it('allows omitting units for 0', () => runTest([ - ['margin', '10 5'], + ['margin', '10px 0'], ], { marginTop: 10, - marginRight: 5, + marginRight: 0, marginBottom: 10, - marginLeft: 5, + marginLeft: 0, +})); + +it('allows omitting units for margin shorthand', () => runTest([ + ['margin', '6 9'], +], { + marginTop: 6, + marginRight: 9, + marginBottom: 6, + marginLeft: 9, })); it('transforms strings', () => runTest([