Skip to content

Improve spec compliance for text-decoration #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,27 @@ it('transforms text-decoration in different order', () =>
textDecorationColor: 'red',
}))

it('transforms text-decoration with ine in different order', () =>
runTest([['text-decoration', 'line-through underline']], {
textDecorationLine: 'underline line-through',
textDecorationStyle: 'solid',
textDecorationColor: 'black',
}))

it('transforms text-decoration with none', () =>
runTest([['text-decoration', 'none']], {
textDecorationLine: 'none',
textDecorationStyle: 'solid',
textDecorationColor: 'black',
}))

it('transforms text-decoration with none as part of multiple terms', () =>
runTest([['text-decoration', 'yellow none']], {
textDecorationLine: 'none',
textDecorationStyle: 'solid',
textDecorationColor: 'yellow',
}))

it('does not transform text-decoration if multiple colors are used', () => {
expect(() =>
transformCss([['text-decoration', 'underline red yellow']])
Expand Down
27 changes: 12 additions & 15 deletions src/transforms/textDecoration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { regExpToken, tokens } from '../tokenTypes'

const { NONE, SPACE, COLOR } = tokens
const { SPACE, COLOR } = tokens

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

if (tokenStream.matches(NONE)) {
tokenStream.expectEmpty()
return {
$merge: {
textDecorationLine: defaultTextDecorationLine,
textDecorationStyle: defaultTextDecorationStyle,
textDecorationColor: defaultTextDecorationColor,
},
}
}

let didParseFirst = false
while (tokenStream.hasTokens()) {
if (didParseFirst) tokenStream.expect(SPACE)

if (line === undefined && tokenStream.matches(LINE)) {
line = tokenStream.lastValue
const lines = [tokenStream.lastValue]

tokenStream.saveRewindPoint()
if (tokenStream.matches(SPACE) && tokenStream.matches(LINE)) {
line += ` ${tokenStream.lastValue}`
if (
lines[0] !== 'none' &&
tokenStream.matches(SPACE) &&
tokenStream.matches(LINE)
) {
lines.push(tokenStream.lastValue)
// Underline comes before line-through
lines.sort().reverse()
} else {
tokenStream.rewind()
}

line = lines.join(' ')
} else if (style === undefined && tokenStream.matches(STYLE)) {
style = tokenStream.lastValue
} else if (color === undefined && tokenStream.matches(COLOR)) {
Expand Down