Skip to content

Commit b744210

Browse files
committed
Add support for text-decoration-line
1 parent f91597d commit b744210

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

src/index.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,21 @@ it('does not transform text-decoration if multiple colors are used', () => {
612612
).toThrow()
613613
})
614614

615+
it('transforms text-decoration-line with underline line-through', () =>
616+
runTest([['text-decoration-line', 'underline line-through']], {
617+
textDecorationLine: 'underline line-through',
618+
}))
619+
620+
it('transforms text-decoration-line with line-through underline', () =>
621+
runTest([['text-decoration-line', 'line-through underline']], {
622+
textDecorationLine: 'underline line-through',
623+
}))
624+
625+
it('transforms text-decoration-line with none', () =>
626+
runTest([['text-decoration-line', 'none']], {
627+
textDecorationLine: 'none',
628+
}))
629+
615630
it('allows blacklisting shorthands', () => {
616631
const actualStyles = transformCss([['border-radius', '50']], ['borderRadius'])
617632
expect(actualStyles).toEqual({ borderRadius: 50 })

src/tokenTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ module.exports.tokens = {
6767
IDENT: regExpToken(identRe),
6868
STRING: matchString,
6969
COLOR: matchColor,
70+
LINE: regExpToken(/^(none|underline|line-through)$/),
7071
}

src/transforms/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const flex = require('./flex')
44
const font = require('./font')
55
const fontFamily = require('./fontFamily')
66
const textDecoration = require('./textDecoration')
7+
const textDecorationLine = require('./textDecorationLine')
78
const transform = require('./transform')
89
const {
910
directionFactory,
@@ -76,5 +77,6 @@ module.exports = {
7677
shadowOffset,
7778
textShadowOffset,
7879
textDecoration,
80+
textDecorationLine,
7981
transform,
8082
}

src/transforms/textDecoration.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { regExpToken, tokens } from '../tokenTypes'
22

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

55
const STYLE = regExpToken(/^(solid|double|dotted|dashed)$/)
6-
const LINE = regExpToken(/^(none|underline|line-through)$/)
76

87
const defaultTextDecorationLine = 'none'
98
const defaultTextDecorationStyle = 'solid'

src/transforms/textDecorationLine.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { tokens } = require('../tokenTypes')
2+
3+
const { SPACE, LINE } = tokens
4+
5+
module.exports = tokenStream => {
6+
const lines = []
7+
8+
let didParseFirst = false
9+
while (tokenStream.hasTokens()) {
10+
if (didParseFirst) tokenStream.expect(SPACE)
11+
12+
lines.push(tokenStream.expect(LINE))
13+
14+
didParseFirst = true
15+
}
16+
17+
lines.sort().reverse()
18+
19+
return lines.join(' ')
20+
}

0 commit comments

Comments
 (0)