Skip to content

Commit

Permalink
fix: also render !important (#111)
Browse files Browse the repository at this point in the history
closes #110
  • Loading branch information
bartveneman authored Dec 21, 2024
1 parent c2745f2 commit b4d536f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ export function format(css, { minify = false } = {}) {
value += SPACE
}

if (node.important) {
value += OPTIONAL_SPACE + '!important'
}

return indent(indent_level) + property + COLON + OPTIONAL_SPACE + value
}

Expand Down
18 changes: 11 additions & 7 deletions test/declarations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ test('does not lowercase custom properties', () => {
assert.is(actual, expected)
})

test.skip('preserves comments', () => {
let actual = format(`a {
/* comment */color: green;
color/* comment */: green;
}`)
test('!important is added', () => {
let actual = format(`a { color: green !important}`)
let expected = `a {
color: green !important;
}`
assert.is(actual, expected)
})

test('!important is lowercase', () => {
let actual = format(`a { color: green !IMPORTANT }`)
let expected = `a {
/* comment */color: green;
color/* comment */: green;
color: green !important;
}`
assert.is(actual, expected)
})
Expand Down
6 changes: 6 additions & 0 deletions test/minify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ test('minified Vadims example', () => {
assert.equal(actual, expected)
})

test('removes whitespace before !important', () => {
let actual = minify(`a { color: green !important }`)
let expected = `a{color:green!important}`
assert.equal(actual, expected)
})

test.run()

0 comments on commit b4d536f

Please sign in to comment.