Skip to content

Commit 1c0abd2

Browse files
authored
Merge pull request styled-components#65 from styled-components/text-decoration-fixes
Improve spec compliance for text-decoration
2 parents f91597d + 9c729d4 commit 1c0abd2

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-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: 12 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,27 @@ 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+
// Underline comes before line-through
32+
lines.sort().reverse()
3833
} else {
3934
tokenStream.rewind()
4035
}
36+
37+
line = lines.join(' ')
4138
} else if (style === undefined && tokenStream.matches(STYLE)) {
4239
style = tokenStream.lastValue
4340
} else if (color === undefined && tokenStream.matches(COLOR)) {

0 commit comments

Comments
 (0)