From 83ae267960c43fd085a78127acce9c37c9f1bc49 Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Wed, 15 Apr 2020 08:39:53 -0400 Subject: [PATCH] Add hwb, lab, and lch to functions matching isColor --- lib/nodes/Func.js | 4 ++-- test/fixtures/func.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/nodes/Func.js b/lib/nodes/Func.js index a4433de..aee5cf1 100644 --- a/lib/nodes/Func.js +++ b/lib/nodes/Func.js @@ -12,7 +12,7 @@ const { registerWalker } = require('../walker'); const Container = require('./Container'); -const colorFunctions = ['hsl', 'hsla', 'rgb', 'rgba']; +const colorFunctionsLowerRegex = /^(hsla?|hwb|lab|lch|rgba?)$/; const reVar = /^--[^\s]+$/; class Func extends Container { @@ -105,7 +105,7 @@ class Func extends Container { const { lastNode } = parser; const lowerName = lastNode.name.toLowerCase(); const { nodes } = node; - lastNode.isColor = colorFunctions.includes(lowerName); + lastNode.isColor = colorFunctionsLowerRegex.test(lowerName); lastNode.isVar = lowerName === 'var' && nodes.length && reVar.test(nodes[0].value); } } diff --git a/test/fixtures/func.js b/test/fixtures/func.js index 05d1b0d..9d22405 100644 --- a/test/fixtures/func.js +++ b/test/fixtures/func.js @@ -25,6 +25,9 @@ module.exports = { 'rgba( 29, 439 , 29 )', 'RGBA( 29, 439 , 29 )', 'RgBa( 29, 439 , 29 )', + 'Lab( 40% 56.6 39 )', + 'lCH(40% 68.8 34.5 / 50%)', + 'hwb(90deg 0% 0% / 0.5)', 'calc(-0.5 * var(foo))', 'calc(1px + -2vw - 4px)', 'calc(((768px - 100vw) / 2) - 15px)',