|
1 | 1 | import { |
2 | 2 | parse, |
3 | | - NODE_TYPES as NODE, |
4 | 3 | is_function, |
5 | 4 | is_dimension, |
6 | 5 | is_parenthesis, |
@@ -32,6 +31,9 @@ import { |
32 | 31 | is_nth_selector, |
33 | 32 | is_nth_of_selector, |
34 | 33 | is_lang_selector, |
| 34 | + is_declaration, |
| 35 | + is_rule, |
| 36 | + is_atrule, |
35 | 37 | } from '@projectwallace/css-parser' |
36 | 38 |
|
37 | 39 | const SPACE = ' ' |
@@ -171,7 +173,7 @@ export function format( |
171 | 173 |
|
172 | 174 | if (!is_operator(node)) { |
173 | 175 | if (node.has_next) { |
174 | | - if (node.next_sibling?.type !== NODE.OPERATOR) { |
| 176 | + if (!is_operator(node.next_sibling)) { |
175 | 177 | parts.push(SPACE) |
176 | 178 | } |
177 | 179 | } |
@@ -259,7 +261,7 @@ export function format( |
259 | 261 | let name = node.name.toLowerCase() |
260 | 262 |
|
261 | 263 | // Legacy pseudo-elements or actual pseudo-elements use double colon |
262 | | - if (name === 'before' || name === 'after' || node.type === NODE.PSEUDO_ELEMENT_SELECTOR) { |
| 264 | + if (name === 'before' || name === 'after' || is_pseudo_element_selector(node)) { |
263 | 265 | parts.push(COLON) |
264 | 266 | } |
265 | 267 |
|
@@ -387,18 +389,17 @@ export function format( |
387 | 389 | } |
388 | 390 | } |
389 | 391 |
|
390 | | - let is_last = child.next_sibling?.type !== NODE.DECLARATION |
391 | | - |
392 | | - if (child.type === NODE.DECLARATION) { |
| 392 | + if (is_declaration(child)) { |
| 393 | + let is_last = !child.has_next || !is_declaration(child.next_sibling) |
393 | 394 | let declaration = print_declaration(child) |
394 | 395 | let semi = is_last ? LAST_SEMICOLON : SEMICOLON |
395 | 396 | lines.push(indent(depth) + declaration + semi) |
396 | | - } else if (child.type === NODE.STYLE_RULE) { |
| 397 | + } else if (is_rule(child)) { |
397 | 398 | if (prev_end !== undefined && lines.length !== 0) { |
398 | 399 | lines.push(EMPTY_STRING) |
399 | 400 | } |
400 | 401 | lines.push(print_rule(child)) |
401 | | - } else if (child.type === NODE.AT_RULE) { |
| 402 | + } else if (is_atrule(child)) { |
402 | 403 | if (prev_end !== undefined && lines.length !== 0) { |
403 | 404 | lines.push(EMPTY_STRING) |
404 | 405 | } |
@@ -517,9 +518,9 @@ export function format( |
517 | 518 | } |
518 | 519 | } |
519 | 520 |
|
520 | | - if (child.type === NODE.STYLE_RULE) { |
| 521 | + if (is_rule(child)) { |
521 | 522 | lines.push(print_rule(child)) |
522 | | - } else if (child.type === NODE.AT_RULE) { |
| 523 | + } else if (is_atrule(child)) { |
523 | 524 | lines.push(print_atrule(child)) |
524 | 525 | } |
525 | 526 |
|
|
0 commit comments