Skip to content

Commit 50f42e4

Browse files
authored
loop over AST directly instead of wrapping in function call (#105)
1 parent ac7f910 commit 50f42e4

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

index.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ export function format(css, { minify = false } = {}) {
319319
.replace(/calc\(([^*]*)\*([^*])/g, 'calc($1 * $2') // force correct whitespace around * in calc()
320320
.replace(/\s+/g, SPACE) // collapse multiple whitespaces into one
321321
.replace(/selector|url|supports|layer\(/ig, (match) => lowercase(match)) // lowercase function names
322-
323322
}
324323

325324
/** @param {import('css-tree').Declaration} node */
@@ -439,32 +438,26 @@ export function format(css, { minify = false } = {}) {
439438
return indent(indent_level) + substr(node).trim()
440439
}
441440

442-
/** @param {import('css-tree').CssNode} node */
443-
function print(node) {
444-
let buffer = EMPTY_STRING
445-
446-
/** @type {import('css-tree').List<import('css-tree').CssNode>} */
447-
// @ts-expect-error Property 'children' does not exist on type 'AnPlusB', but we're never using that
448-
let children = node.children
449-
450-
children.forEach((child, item) => {
451-
if (child.type === TYPE_RULE) {
452-
buffer += print_rule(child)
453-
} else if (child.type === TYPE_ATRULE) {
454-
buffer += print_atrule(child)
455-
} else {
456-
buffer += print_unknown(child, indent_level)
457-
}
441+
/** @type {import('css-tree').List<import('css-tree').CssNode>} */
442+
// @ts-expect-error Property 'children' does not exist on type 'AnPlusB', but we're never using that
443+
let children = ast.children
444+
let buffer = EMPTY_STRING
458445

459-
if (item.next !== null) {
460-
buffer += NEWLINE + NEWLINE
461-
}
462-
})
446+
children.forEach((child, item) => {
447+
if (child.type === TYPE_RULE) {
448+
buffer += print_rule(child)
449+
} else if (child.type === TYPE_ATRULE) {
450+
buffer += print_atrule(child)
451+
} else {
452+
buffer += print_unknown(child, indent_level)
453+
}
463454

464-
return buffer
465-
}
455+
if (item.next !== null) {
456+
buffer += NEWLINE + NEWLINE
457+
}
458+
})
466459

467-
return print(ast)
460+
return buffer
468461
}
469462

470463
/**

0 commit comments

Comments
 (0)