Skip to content

Commit 0559ff2

Browse files
committed
Improve spec compliance for text-decoration
1 parent f91597d commit 0559ff2

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,27 @@ it('transforms text-decoration in different order', () =>
599599
textDecorationColor: 'red',
600600
}))
601601

602+
it('transforms text-decoration with ine in different order', () =>
603+
runTest([['text-decoration', 'line-through underline']], {
604+
textDecorationLine: 'underline line-through',
605+
textDecorationStyle: 'solid',
606+
textDecorationColor: 'black',
607+
}))
608+
602609
it('transforms text-decoration with none', () =>
603610
runTest([['text-decoration', 'none']], {
604611
textDecorationLine: 'none',
605612
textDecorationStyle: 'solid',
606613
textDecorationColor: 'black',
607614
}))
608615

616+
it('transforms text-decoration with none as part of multiple terms', () =>
617+
runTest([['text-decoration', 'yellow none']], {
618+
textDecorationLine: 'none',
619+
textDecorationStyle: 'solid',
620+
textDecorationColor: 'yellow',
621+
}))
622+
609623
it('does not transform text-decoration if multiple colors are used', () => {
610624
expect(() =>
611625
transformCss([['text-decoration', 'underline red yellow']])

src/transforms/textDecoration.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { regExpToken, tokens } from '../tokenTypes'
22

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

55
const STYLE = regExpToken(/^(solid|double|dotted|dashed)$/)
66
const LINE = regExpToken(/^(none|underline|line-through)$/)
@@ -14,30 +14,30 @@ module.exports = tokenStream => {
1414
let style
1515
let color
1616

17-
if (tokenStream.matches(NONE)) {
18-
tokenStream.expectEmpty()
19-
return {
20-
$merge: {
21-
textDecorationLine: defaultTextDecorationLine,
22-
textDecorationStyle: defaultTextDecorationStyle,
23-
textDecorationColor: defaultTextDecorationColor,
24-
},
25-
}
26-
}
27-
2817
let didParseFirst = false
2918
while (tokenStream.hasTokens()) {
3019
if (didParseFirst) tokenStream.expect(SPACE)
3120

3221
if (line === undefined && tokenStream.matches(LINE)) {
33-
line = tokenStream.lastValue
22+
const lines = [tokenStream.lastValue]
3423

3524
tokenStream.saveRewindPoint()
36-
if (tokenStream.matches(SPACE) && tokenStream.matches(LINE)) {
37-
line += ` ${tokenStream.lastValue}`
25+
if (
26+
lines[0] !== 'none' &&
27+
tokenStream.matches(SPACE) &&
28+
tokenStream.matches(LINE)
29+
) {
30+
lines.push(tokenStream.lastValue)
31+
if (lines[0] === lines[1]) {
32+
throw new Error('Expected two different text decoration line styles')
33+
}
34+
// Underline comes before line-through
35+
lines.sort().reverse()
3836
} else {
3937
tokenStream.rewind()
4038
}
39+
40+
line = lines.join(' ')
4141
} else if (style === undefined && tokenStream.matches(STYLE)) {
4242
style = tokenStream.lastValue
4343
} else if (color === undefined && tokenStream.matches(COLOR)) {

0 commit comments

Comments
 (0)