Skip to content

Commit 74d9fb9

Browse files
authored
fix: do not crash on weird font-family (#454)
closes #453
1 parent 5bba11d commit 74d9fb9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/values/destructure-font-shorthand.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export function destructure(value, stringifyNode, cb) {
122122
offset: (font_family[0] || font_family[1]).loc.start.offset,
123123
},
124124
end: {
125-
offset: font_family[1].loc.end.offset,
125+
// Either the node we detected as the last node, or the end of the whole value
126+
// It's never 0 because the first node is always a font-size or font-style
127+
offset: font_family[1]?.loc.end.offset || value.loc.end.offset,
126128
},
127129
},
128130
})

src/values/font-families.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ FontFamilies('does not crash on `12px var(...)', () => {
9191
})
9292
})
9393

94+
FontFamilies('does not crash on 14px "Inter Var", sans-serif, 700', () => {
95+
const fixture = `
96+
test {
97+
font: 14px "Inter Var", sans-serif, 700;
98+
}
99+
`
100+
assert.not.throws(() => {
101+
analyze(fixture).values.fontFamilies
102+
})
103+
let { fontFamilies, fontSizes } = analyze(fixture).values
104+
assert.equal(fontFamilies.unique, {
105+
'"Inter Var", sans-serif, 700': 1,
106+
})
107+
assert.equal(fontSizes.unique, {
108+
'14px': 1,
109+
})
110+
})
111+
94112
FontFamilies('handles system fonts', () => {
95113
// Source: https://drafts.csswg.org/css-fonts-3/#font-prop
96114
const fixture = `

0 commit comments

Comments
 (0)