Skip to content

Commit

Permalink
fix(parse): use buffer strategy for parsing downloaded css
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 22, 2024
1 parent 5b72725 commit 362e2d4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/css/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function extractCSSValue (node: Declaration) {
}

const values = [] as Array<string | number | RemoteFontSource | LocalFontSource>
let buffer = ''
for (const child of node.value.children) {
if (child.type === 'Function') {
if (child.name === 'local' && child.children.first?.type === 'String') {
Expand All @@ -55,11 +56,15 @@ function extractCSSValue (node: Declaration) {
values.push({ url: child.value })
}
if (child.type === 'Identifier') {
values.push(child.name)
buffer = buffer ? `${buffer} ${child.name}` : child.name
}
if (child.type === 'String') {
values.push(child.value)
}
if (child.type === 'Operator' && child.value === ',' && buffer) {
values.push(buffer)
buffer = ''
}
if (child.type === 'UnicodeRange') {
values.push(child.value)
}
Expand All @@ -68,6 +73,10 @@ function extractCSSValue (node: Declaration) {
}
}

if (buffer) {
values.push(buffer)
}

if (values.length === 1) {
return values[0]
}
Expand Down

0 comments on commit 362e2d4

Please sign in to comment.