Skip to content

Commit 1ee0011

Browse files
committed
box-shadow transform: fix rgb(a) and hsl(a) color values being transformed to null
1 parent 7347065 commit 1ee0011

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/index.test.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@ it('transforms box-shadow without blur-radius', () => runTest([
475475
}));
476476

477477
it('transforms box-shadow without color', () => runTest([
478-
['box-shadow', '10px 20px red'],
478+
['box-shadow', '10px 20px 30px'],
479479
], {
480480
shadowOffset: { width: 10, height: 20 },
481-
shadowRadius: 0,
482-
shadowColor: 'red',
481+
shadowRadius: 30,
482+
shadowColor: 'black',
483483
}));
484484

485485
it('transforms box-shadow without blur-radius, color', () => runTest([
@@ -490,6 +490,38 @@ it('transforms box-shadow without blur-radius, color', () => runTest([
490490
shadowColor: 'black',
491491
}));
492492

493+
it('transforms box-shadow with rgb color', () => runTest([
494+
['box-shadow', '10px 20px rgb(100, 100, 100)'],
495+
], {
496+
shadowOffset: { width: 10, height: 20 },
497+
shadowRadius: 0,
498+
shadowColor: 'rgb(100, 100, 100)',
499+
}));
500+
501+
it('transforms box-shadow with rgba color', () => runTest([
502+
['box-shadow', '10px 20px rgba(100, 100, 100, 0.5)'],
503+
], {
504+
shadowOffset: { width: 10, height: 20 },
505+
shadowRadius: 0,
506+
shadowColor: 'rgba(100, 100, 100, 0.5)',
507+
}));
508+
509+
it('transforms box-shadow with hsl color', () => runTest([
510+
['box-shadow', '10px 20px hsl(120, 100%, 50%)'],
511+
], {
512+
shadowOffset: { width: 10, height: 20 },
513+
shadowRadius: 0,
514+
shadowColor: 'hsl(120, 100%, 50%)',
515+
}));
516+
517+
it('transforms box-shadow with hsla color', () => runTest([
518+
['box-shadow', '10px 20px hsla(120, 100%, 50%, 0.7)'],
519+
], {
520+
shadowOffset: { width: 10, height: 20 },
521+
shadowRadius: 0,
522+
shadowColor: 'hsla(120, 100%, 50%, 0.7)',
523+
}));
524+
493525
it('transforms box-shadow enforces offset to be present', () => {
494526
expect(() => transformCss([['box-shadow', 'red']]))
495527
.toThrow('Failed to parse declaration "boxShadow: red"');

src/transforms/boxShadow.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { tokens } = require('../tokenTypes');
22

3-
const { NONE, SPACE, WORD, LENGTH } = tokens;
3+
const { NONE, SPACE, COLOR, LENGTH } = tokens;
44

55
module.exports = (tokenStream) => {
66
let offsetX;
@@ -28,10 +28,8 @@ module.exports = (tokenStream) => {
2828
tokenStream.expect(SPACE);
2929
blurRadius = tokenStream.expect(LENGTH);
3030
}
31-
} else if (color === undefined && (
32-
tokenStream.matchesFunction() || tokenStream.matches(WORD)
33-
)) {
34-
color = String(tokenStream.lastValue);
31+
} else if (tokenStream.matches(COLOR)) {
32+
color = tokenStream.lastValue;
3533
} else {
3634
tokenStream.throw();
3735
}

0 commit comments

Comments
 (0)