Skip to content

Commit b47345b

Browse files
committed
refactor: simplify print_url, the url( prefix check is always true
A Url node's text always starts with url( (any casing) by construction -- that's what makes the parser tag it as a Url node in the first place, confirmed empirically across url(), URL(), quoted and unquoted forms. The regex test guarding the slice was dead code.
1 parent 6fb1237 commit b47345b

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/lib/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,11 @@ function print_string(str: string | number | null, quote?: '"' | "'"): string {
9292
return quote + inner + quote
9393
}
9494

95-
/** Prints a `url(...)`: lowercases a leading `url(` keyword but leaves quote
96-
* style untouched. */
95+
/** Prints a `url(...)`: lowercases the `url(` keyword but leaves quote style
96+
* untouched. A Url node's text always starts with `url(` (any casing) — it's
97+
* how the parser identifies the node as a Url in the first place. */
9798
function print_url(node: Url): string {
98-
let text = node.text
99-
if (/^url\(/i.test(text)) {
100-
return 'url(' + text.slice(4)
101-
}
102-
return text
99+
return 'url(' + node.text.slice(4)
103100
}
104101

105102
function print_operator(node: Operator, optional_space = SPACE): string {

0 commit comments

Comments
 (0)