Skip to content
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ The package also exports lower-level formatters for individual CSS constructs:

```js
import {
format_value,
format_declaration,
format_selector,
format_atrule_prelude,
format_value,
format_declaration,
format_selector,
format_atrule_prelude,
} from '@projectwallace/format-css'

// Format a CSS value (e.g. the right-hand side of a declaration)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ export function format_atrule_prelude(
.replace(/\)([a-zA-Z])/g, ') $1') // force whitespace between closing parenthesis and following text (usually and|or)
.replace(/\s*(=>|>=|<=)\s*/g, `${optional_space}$1${optional_space}`) // add optional spacing around =>, >= and <=
.replace(/([^<>=\s])([<>])([^<>=\s])/g, `$1${optional_space}$2${optional_space}$3`) // add spacing around < or > except when it's part of <=, >=, =>
.replace(/\s+/g, optional_space) // collapse multiple whitespaces into one
.replace(/([^<>=\s])\s+([<>])\s+([^<>=\s])/g, `$1${optional_space}$2${optional_space}$3`) // handle spaces around < or > when they already have surrounding whitespace
.replace(/\s+/g, SPACE) // collapse multiple whitespaces into one
.replace(/([:,]) /g, minify ? '$1' : '$1 ') // in minify mode, remove optional spaces after : and ,
.replace(
/calc\(\s*([^()+\-*/]+)\s*([*/+-])\s*([^()+\-*/]+)\s*\)/g,
(_, left, operator, right) => {
Expand Down
6 changes: 6 additions & 0 deletions test/atrules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ test('minify: new-fangled comparators (width > 1000px)', () => {
expect(actual).toEqual(expected)
})

test('minify: keeps necessary whitespace between keywords', () => {
let actual = minify(`@media screen or print {}`)
let expected = `@media screen or print{}`
expect(actual).toEqual(expected)
})

test.skip('preserves comments', () => {
let actual = format(`
@media /* comment */ all {}
Expand Down
Loading