Skip to content

Commit cf45ffc

Browse files
committed
Merge remote-tracking branch 'origin/master' into text-decoration-line
2 parents b744210 + 1c0abd2 commit cf45ffc

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, LINE, COLOR } = tokens
3+
const { SPACE, LINE, COLOR } = tokens
44

55
const STYLE = regExpToken(/^(solid|double|dotted|dashed)$/)
66

@@ -13,30 +13,27 @@ module.exports = tokenStream => {
1313
let style
1414
let color
1515

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

3120
if (line === undefined && tokenStream.matches(LINE)) {
32-
line = tokenStream.lastValue
21+
const lines = [tokenStream.lastValue]
3322

3423
tokenStream.saveRewindPoint()
35-
if (tokenStream.matches(SPACE) && tokenStream.matches(LINE)) {
36-
line += ` ${tokenStream.lastValue}`
24+
if (
25+
lines[0] !== 'none' &&
26+
tokenStream.matches(SPACE) &&
27+
tokenStream.matches(LINE)
28+
) {
29+
lines.push(tokenStream.lastValue)
30+
// Underline comes before line-through
31+
lines.sort().reverse()
3732
} else {
3833
tokenStream.rewind()
3934
}
35+
36+
line = lines.join(' ')
4037
} else if (style === undefined && tokenStream.matches(STYLE)) {
4138
style = tokenStream.lastValue
4239
} else if (color === undefined && tokenStream.matches(COLOR)) {

0 commit comments

Comments
 (0)