Skip to content

Commit ed4fce6

Browse files
committed
Merge pull request postcss#12 from demiazz/hotfix/similar-names
Fix similar names conflicts
2 parents 4e06d1b + cc3afce commit ed4fce6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ module.exports = postcss.plugin("postcss-color-function", function() {
3030
* @return {String} converted declaration value to rgba()
3131
*/
3232
function transformColor(string, source) {
33-
var index = string.indexOf("color(")
34-
if (index == -1) {
33+
var index = string.search(/(^|[^\w\-])color\(/)
34+
35+
if (index === -1) {
3536
return string
3637
}
3738

39+
// NOTE: regexp search beginning of line of non char symbol before `color(`.
40+
// Offset used for second case.
41+
index = index === 0 ? index : index + 1
42+
3843
var fn = string.slice(index)
3944
var balancedMatches = balanced("(", ")", fn)
4045
if (!balancedMatches) {

test/fixtures/color.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ body {
33
background-color: color(red tint(50%));
44
border-color: color(hsla(125, 50%, 50%, .4) hue(200));
55
border-top-color: color(hwb(270, 10%, 0%) contrast(50%));
6+
7+
border-bottom-color: hover-color(red);
8+
9+
border-right-color: hover-color(color(red tint(50%)));
610
}

test/fixtures/color.expected.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ body {
33
background-color: rgb(255, 128, 128);
44
border-color: rgba(64, 149, 191, 0.4);
55
border-top-color: rgb(248, 240, 255);
6+
7+
border-bottom-color: hover-color(red);
8+
9+
border-right-color: hover-color(rgb(255, 128, 128));
610
}

0 commit comments

Comments
 (0)