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
14 changes: 7 additions & 7 deletions src/destructure-font-family.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ test('multiple font-family with spaces and quotes', () => {
expect.soft(destructure_font_family('"Arial Black", sans-serif')).toEqual(['Arial Black', 'sans-serif'])
})

test('with emoji name', () => {
expect.soft(destructure_font_family('💪')).toEqual(['💪'])
})

test('single var()', () => {
expect.soft(destructure_font_family('var(--family)')).toEqual(['var(--family)'])
expect.soft(destructure_font_family('var(--family)')).toBeUndefined()
})

test('multiple var()', () => {
expect.soft(destructure_font_family('var(--family), var(--family2)')).toEqual(['var(--family)', 'var(--family2)'])
expect.soft(destructure_font_family('var(--family), var(--family2)')).toBeUndefined()
})

test('var() with fallback', () => {
expect.soft(destructure_font_family('var(--family, Arial)')).toEqual(['var(--family, Arial)'])
})

test('with emoji name', () => {
expect.soft(destructure_font_family('💪')).toEqual(['💪'])
expect.soft(destructure_font_family('var(--family, Arial)')).toBeUndefined()
})
8 changes: 6 additions & 2 deletions src/destructure-font-family.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { parse, type Value, type CssNode } from 'css-tree'
import { unquote } from './unquote.js'

export function destructure_font_family(value: string): string[] {
export function destructure_font_family(value: string): string[] | undefined {
if (value.toLowerCase().includes('var(')) {
return undefined
}

let ast = parse(value, {
context: 'value',
positions: true
positions: true,
}) as Value

function generate(node: CssNode) {
Expand Down
Loading