diff --git a/src/values/destructure-font-shorthand.js b/src/values/destructure-font-shorthand.js index a07f6b7..71dae9d 100644 --- a/src/values/destructure-font-shorthand.js +++ b/src/values/destructure-font-shorthand.js @@ -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, }, }, }) diff --git a/src/values/font-families.test.js b/src/values/font-families.test.js index a4fac9b..94d49a1 100644 --- a/src/values/font-families.test.js +++ b/src/values/font-families.test.js @@ -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 = `