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
4 changes: 3 additions & 1 deletion src/values/destructure-font-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export function destructure(value, stringifyNode, cb) {
offset: (font_family[0] || font_family[1]).loc.start.offset,
},
end: {
offset: font_family[1].loc.end.offset,
// Either the node we detected as the last node, or the end of the whole value
// It's never 0 because the first node is always a font-size or font-style
offset: font_family[1]?.loc.end.offset || value.loc.end.offset,
},
},
})
Expand Down
18 changes: 18 additions & 0 deletions src/values/font-families.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ FontFamilies('does not crash on `12px var(...)', () => {
})
})

FontFamilies('does not crash on 14px "Inter Var", sans-serif, 700', () => {
const fixture = `
test {
font: 14px "Inter Var", sans-serif, 700;
}
`
assert.not.throws(() => {
analyze(fixture).values.fontFamilies
})
let { fontFamilies, fontSizes } = analyze(fixture).values
assert.equal(fontFamilies.unique, {
'"Inter Var", sans-serif, 700': 1,
})
assert.equal(fontSizes.unique, {
'14px': 1,
})
})

FontFamilies('handles system fonts', () => {
// Source: https://drafts.csswg.org/css-fonts-3/#font-prop
const fixture = `
Expand Down