From d0e6c246160e21f6615c6e16e2e5e99e5f4eb93c Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sun, 10 Jan 2016 13:25:58 +0100 Subject: [PATCH] Fails when radial-gradient shape is omitted but a size is provided --- Makefile | 3 +++ build/node.js | 30 +++++++++++++++++++++++------- build/web.js | 30 +++++++++++++++++++++++------- lib/parser.js | 21 +++++++++++++++------ lib/stringify.js | 9 ++++++++- spec/parser.spec.js | 5 ++++- spec/stringify.spec.js | 4 +++- 7 files changed, 79 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 8ab60dc..2c7b7f5 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ all: python -m SimpleHTTPServer 3000 + +test: + grunt diff --git a/build/node.js b/build/node.js index 63cf3ed..b19e20a 100644 --- a/build/node.js +++ b/build/node.js @@ -60,7 +60,14 @@ GradientParser.stringify = (function() { }, 'visit_extent-keyword': function(node) { - return node.value; + var result = node.value, + at = visitor.visit(node.at); + + if (at) { + result += ' at ' + at; + } + + return result; }, 'visit_position-keyword': function(node) { @@ -310,12 +317,21 @@ GradientParser.parse = (function() { if (radialType) { radialType.at = matchAtPosition(); } else { - var defaultPosition = matchPositioning(); - if (defaultPosition) { - radialType = { - type: 'default-radial', - at: defaultPosition - }; + var extent = matchExtentKeyword(); + if (extent) { + radialType = extent; + var positionAt = matchAtPosition(); + if (positionAt) { + radialType.at = positionAt; + } + } else { + var defaultPosition = matchPositioning(); + if (defaultPosition) { + radialType = { + type: 'default-radial', + at: defaultPosition + }; + } } } diff --git a/build/web.js b/build/web.js index bb71866..94fa388 100644 --- a/build/web.js +++ b/build/web.js @@ -153,12 +153,21 @@ GradientParser.parse = (function() { if (radialType) { radialType.at = matchAtPosition(); } else { - var defaultPosition = matchPositioning(); - if (defaultPosition) { - radialType = { - type: 'default-radial', - at: defaultPosition - }; + var extent = matchExtentKeyword(); + if (extent) { + radialType = extent; + var positionAt = matchAtPosition(); + if (positionAt) { + radialType.at = positionAt; + } + } else { + var defaultPosition = matchPositioning(); + if (defaultPosition) { + radialType = { + type: 'default-radial', + at: defaultPosition + }; + } } } @@ -400,7 +409,14 @@ GradientParser.stringify = (function() { }, 'visit_extent-keyword': function(node) { - return node.value; + var result = node.value, + at = visitor.visit(node.at); + + if (at) { + result += ' at ' + at; + } + + return result; }, 'visit_position-keyword': function(node) { diff --git a/lib/parser.js b/lib/parser.js index e8df197..87e3340 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -151,12 +151,21 @@ GradientParser.parse = (function() { if (radialType) { radialType.at = matchAtPosition(); } else { - var defaultPosition = matchPositioning(); - if (defaultPosition) { - radialType = { - type: 'default-radial', - at: defaultPosition - }; + var extent = matchExtentKeyword(); + if (extent) { + radialType = extent; + var positionAt = matchAtPosition(); + if (positionAt) { + radialType.at = positionAt; + } + } else { + var defaultPosition = matchPositioning(); + if (defaultPosition) { + radialType = { + type: 'default-radial', + at: defaultPosition + }; + } } } diff --git a/lib/stringify.js b/lib/stringify.js index 0f3b300..beb0915 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -60,7 +60,14 @@ GradientParser.stringify = (function() { }, 'visit_extent-keyword': function(node) { - return node.value; + var result = node.value, + at = visitor.visit(node.at); + + if (at) { + result += ' at ' + at; + } + + return result; }, 'visit_position-keyword': function(node) { diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 4eda773..e58410d 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -197,7 +197,10 @@ describe('lib/parser.js', function () { 'ellipse cover', 'circle cover', 'center bottom, ellipse cover', - 'circle at 87.23px -58.3px' + 'circle at 87.23px -58.3px', + 'farthest-side, red, blue', + 'farthest-corner, red, blue', + 'farthest-corner at 87.23px -58.3px, red, blue' ].forEach(function(declaration) { it('should parse ' + declaration + ' declaration', function() { diff --git a/spec/stringify.spec.js b/spec/stringify.spec.js index cda09c4..e968119 100644 --- a/spec/stringify.spec.js +++ b/spec/stringify.spec.js @@ -79,7 +79,9 @@ describe('lib/stringify.js', function () { 'ellipse cover', 'circle cover', 'center bottom, ellipse cover', - 'circle at 87.23px -58.3px' + 'circle at 87.23px -58.3px', + 'farthest-corner, red, blue', + 'farthest-corner at 87.23px -58.3px, red, blue' ].forEach(function(declaration) { it('should parse ' + declaration + ' declaration', function() {