Skip to content

Commit e430e3c

Browse files
committed
Merge remote-tracking branch 'origin/text-decoration-line' into organise-tests
2 parents aa32526 + e424f89 commit e430e3c

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

src/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,41 @@ it('transforms text-decoration with none as part of multiple terms', () =>
603603
textDecorationColor: 'yellow',
604604
}))
605605

606+
it('transforms text-decoration with none in capitals', () =>
607+
runTest([['text-decoration', 'yellow NONE']], {
608+
textDecorationLine: 'none',
609+
textDecorationStyle: 'solid',
610+
textDecorationColor: 'yellow',
611+
}))
612+
613+
it('transforms text-decoration with style in capitals', () =>
614+
runTest([['text-decoration', 'yellow UNDERLINE LINE-THROUGH']], {
615+
textDecorationLine: 'underline line-through',
616+
textDecorationStyle: 'solid',
617+
textDecorationColor: 'yellow',
618+
}))
619+
606620
it('does not transform text-decoration if multiple colors are used', () => {
607621
expect(() =>
608622
transformCss([['text-decoration', 'underline red yellow']])
609623
).toThrow()
610624
})
611625

626+
it('transforms text-decoration-line with underline line-through', () =>
627+
runTest([['text-decoration-line', 'underline line-through']], {
628+
textDecorationLine: 'underline line-through',
629+
}))
630+
631+
it('transforms text-decoration-line with line-through underline', () =>
632+
runTest([['text-decoration-line', 'line-through underline']], {
633+
textDecorationLine: 'underline line-through',
634+
}))
635+
636+
it('transforms text-decoration-line with none', () =>
637+
runTest([['text-decoration-line', 'none']], {
638+
textDecorationLine: 'none',
639+
}))
640+
612641
it('allows blacklisting shorthands', () => {
613642
const actualStyles = transformCss([['border-radius', '50']], ['borderRadius'])
614643
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)$/i),
7071
}

src/transforms/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const font = require('./font')
55
const fontFamily = require('./fontFamily')
66
const textShadow = require('./textShadow')
77
const textDecoration = require('./textDecoration')
8+
const textDecorationLine = require('./textDecorationLine')
89
const transform = require('./transform')
910
const {
1011
directionFactory,
@@ -78,5 +79,6 @@ module.exports = {
7879
textShadow,
7980
textShadowOffset,
8081
textDecoration,
82+
textDecorationLine,
8183
transform,
8284
}

src/transforms/textDecoration.js

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

3-
const { SPACE, COLOR } = tokens
3+
const { 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'
@@ -19,15 +18,15 @@ module.exports = tokenStream => {
1918
if (didParseFirst) tokenStream.expect(SPACE)
2019

2120
if (line === undefined && tokenStream.matches(LINE)) {
22-
const lines = [tokenStream.lastValue]
21+
const lines = [tokenStream.lastValue.toLowerCase()]
2322

2423
tokenStream.saveRewindPoint()
2524
if (
2625
lines[0] !== 'none' &&
2726
tokenStream.matches(SPACE) &&
2827
tokenStream.matches(LINE)
2928
) {
30-
lines.push(tokenStream.lastValue)
29+
lines.push(tokenStream.lastValue.toLowerCase())
3130
// Underline comes before line-through
3231
lines.sort().reverse()
3332
} else {

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).toLowerCase())
13+
14+
didParseFirst = true
15+
}
16+
17+
lines.sort().reverse()
18+
19+
return lines.join(' ')
20+
}

0 commit comments

Comments
 (0)