From f2e77a9a6f2dfc4eeb280df92c9a97b9ffcd329e Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Sat, 21 Dec 2024 23:44:10 +0100 Subject: [PATCH] fix: also render `!important` --- index.js | 4 ++++ test/declarations.test.js | 18 +++++++++++------- test/minify.test.js | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 1c8b67b..cc274bd 100644 --- a/index.js +++ b/index.js @@ -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 } diff --git a/test/declarations.test.js b/test/declarations.test.js index ff7446c..d987dab 100644 --- a/test/declarations.test.js +++ b/test/declarations.test.js @@ -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) }) diff --git a/test/minify.test.js b/test/minify.test.js index cfc774c..026bd7b 100644 --- a/test/minify.test.js +++ b/test/minify.test.js @@ -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()