Skip to content

Commit b4d536f

Browse files
authored
fix: also render !important (#111)
closes #110
1 parent c2745f2 commit b4d536f

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ export function format(css, { minify = false } = {}) {
428428
value += SPACE
429429
}
430430

431+
if (node.important) {
432+
value += OPTIONAL_SPACE + '!important'
433+
}
434+
431435
return indent(indent_level) + property + COLON + OPTIONAL_SPACE + value
432436
}
433437

test/declarations.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,18 @@ test('does not lowercase custom properties', () => {
7373
assert.is(actual, expected)
7474
})
7575

76-
test.skip('preserves comments', () => {
77-
let actual = format(`a {
78-
/* comment */color: green;
79-
color/* comment */: green;
80-
}`)
76+
test('!important is added', () => {
77+
let actual = format(`a { color: green !important}`)
78+
let expected = `a {
79+
color: green !important;
80+
}`
81+
assert.is(actual, expected)
82+
})
83+
84+
test('!important is lowercase', () => {
85+
let actual = format(`a { color: green !IMPORTANT }`)
8186
let expected = `a {
82-
/* comment */color: green;
83-
color/* comment */: green;
87+
color: green !important;
8488
}`
8589
assert.is(actual, expected)
8690
})

test/minify.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@ test('minified Vadims example', () => {
7777
assert.equal(actual, expected)
7878
})
7979

80+
test('removes whitespace before !important', () => {
81+
let actual = minify(`a { color: green !important }`)
82+
let expected = `a{color:green!important}`
83+
assert.equal(actual, expected)
84+
})
85+
8086
test.run()

0 commit comments

Comments
 (0)