From cc3afcedac736bbbb340f2ef96b820de3e72c486 Mon Sep 17 00:00:00 2001 From: Alexey Plutalov Date: Tue, 7 Jul 2015 20:56:38 +0300 Subject: [PATCH] Fix search color function calling in decl value --- index.js | 9 +++++++-- test/fixtures/color.css | 4 ++++ test/fixtures/color.expected.css | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 45382df..83cf8c9 100755 --- a/index.js +++ b/index.js @@ -30,11 +30,16 @@ module.exports = postcss.plugin("postcss-color-function", function() { * @return {String} converted declaration value to rgba() */ function transformColor(string, source) { - var index = string.indexOf("color(") - if (index == -1) { + var index = string.search(/(^|[^\w\-])color\(/) + + if (index === -1) { return string } + // NOTE: regexp search beginning of line of non char symbol before `color(`. + // Offset used for second case. + index = index === 0 ? index : index + 1 + var fn = string.slice(index) var balancedMatches = balanced("(", ")", fn) if (!balancedMatches) { diff --git a/test/fixtures/color.css b/test/fixtures/color.css index 69217e8..08870ac 100644 --- a/test/fixtures/color.css +++ b/test/fixtures/color.css @@ -3,4 +3,8 @@ body { background-color: color(red tint(50%)); border-color: color(hsla(125, 50%, 50%, .4) hue(200)); border-top-color: color(hwb(270, 10%, 0%) contrast(50%)); + + border-bottom-color: hover-color(red); + + border-right-color: hover-color(color(red tint(50%))); } diff --git a/test/fixtures/color.expected.css b/test/fixtures/color.expected.css index 8153ec6..c1363d4 100644 --- a/test/fixtures/color.expected.css +++ b/test/fixtures/color.expected.css @@ -3,4 +3,8 @@ body { background-color: rgb(255, 128, 128); border-color: rgba(64, 149, 191, 0.4); border-top-color: rgb(248, 240, 255); + + border-bottom-color: hover-color(red); + + border-right-color: hover-color(rgb(255, 128, 128)); }