Skip to content

Commit 2b5ab0e

Browse files
authored
fix: do not mark invalid/non-primitive fontFamily tokens as fontFamily (#32)
1 parent 2b2105f commit 2b5ab0e

File tree

4 files changed

+139
-93
lines changed

4 files changed

+139
-93
lines changed

src/destructure-font-family.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ test('multiple font-family with spaces and quotes', () => {
2121
expect.soft(destructure_font_family('"Arial Black", sans-serif')).toEqual(['Arial Black', 'sans-serif'])
2222
})
2323

24+
test('with emoji name', () => {
25+
expect.soft(destructure_font_family('💪')).toEqual(['💪'])
26+
})
27+
2428
test('single var()', () => {
25-
expect.soft(destructure_font_family('var(--family)')).toEqual(['var(--family)'])
29+
expect.soft(destructure_font_family('var(--family)')).toBeUndefined()
2630
})
2731

2832
test('multiple var()', () => {
29-
expect.soft(destructure_font_family('var(--family), var(--family2)')).toEqual(['var(--family)', 'var(--family2)'])
33+
expect.soft(destructure_font_family('var(--family), var(--family2)')).toBeUndefined()
3034
})
3135

3236
test('var() with fallback', () => {
33-
expect.soft(destructure_font_family('var(--family, Arial)')).toEqual(['var(--family, Arial)'])
34-
})
35-
36-
test('with emoji name', () => {
37-
expect.soft(destructure_font_family('💪')).toEqual(['💪'])
37+
expect.soft(destructure_font_family('var(--family, Arial)')).toBeUndefined()
3838
})

src/destructure-font-family.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { parse, type Value, type CssNode } from 'css-tree'
22
import { unquote } from './unquote.js'
33

4-
export function destructure_font_family(value: string): string[] {
4+
export function destructure_font_family(value: string): string[] | undefined {
5+
if (value.toLowerCase().includes('var(')) {
6+
return undefined
7+
}
8+
59
let ast = parse(value, {
610
context: 'value',
7-
positions: true
11+
positions: true,
812
}) as Value
913

1014
function generate(node: CssNode) {

0 commit comments

Comments
 (0)