Skip to content

Commit 557509f

Browse files
committed
Fix transparent not working as a color value for shorthands
1 parent 453b416 commit 557509f

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/__tests__/colors.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import transformCss from '..'
2+
3+
it('transforms hex colors', () => {
4+
expect(transformCss([['color', '#f00']])).toEqual({ color: '#f00' })
5+
})
6+
7+
it('transforms rgb colors', () => {
8+
expect(transformCss([['color', 'rgb(255, 0, 0)']])).toEqual({
9+
color: 'rgb(255, 0, 0)',
10+
})
11+
})
12+
13+
it('transforms transparent color', () => {
14+
expect(transformCss([['color', 'transparent']])).toEqual({
15+
color: 'transparent',
16+
})
17+
})
18+
19+
it('transforms border shorthand with transparent color', () => {
20+
expect(transformCss([['border', '2px dashed transparent']])).toEqual({
21+
borderColor: 'transparent',
22+
borderStyle: 'dashed',
23+
borderWidth: 2,
24+
})
25+
})
26+
27+
it('transforms background shorthand with transparent color', () => {
28+
expect(transformCss([['background', 'transparent']])).toEqual({
29+
backgroundColor: 'transparent',
30+
})
31+
})

src/__tests__/index.js

-10
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ it('transforms strings', () => {
117117
expect(transformCss([['color', 'red']])).toEqual({ color: 'red' })
118118
})
119119

120-
it('transforms hex colors', () => {
121-
expect(transformCss([['color', '#f00']])).toEqual({ color: '#f00' })
122-
})
123-
124-
it('transforms rgb colors', () => {
125-
expect(transformCss([['color', 'rgb(255, 0, 0)']])).toEqual({
126-
color: 'rgb(255, 0, 0)',
127-
})
128-
})
129-
130120
it('converts to camel-case', () => {
131121
expect(transformCss([['background-color', 'red']])).toEqual({
132122
backgroundColor: 'red',

src/tokenTypes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/
1616
const matchColor = node => {
1717
if (
1818
node.type === 'word' &&
19-
(hexColorRe.test(node.value) || node.value in cssColorKeywords)
19+
(hexColorRe.test(node.value) ||
20+
node.value in cssColorKeywords ||
21+
node.value === 'transparent')
2022
) {
2123
return node.value
2224
} else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {

0 commit comments

Comments
 (0)