Skip to content

Commit c355835

Browse files
authored
Handle object or undefined values (#263)
`tailwindcss-intellisense` passes in object and undefined values so now this handles those cases so things don't break. Fixes #260
1 parent befe458 commit c355835

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

.changeset/sad-rabbits-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tailwindcss-capsize': patch
3+
---
4+
5+
Handle anomalous values from Tailwind language server

src/plugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ const thisPlugin: PluginType = createPlugin.withOptions<CapsizePluginOptions>(
7777
// Font-size
7878
matchUtilities(
7979
{
80-
// @ts-expect-error -- Extra custom properties mismatches base type.
8180
text(value: string | [string, string | FontSizeOptions]) {
81+
/**
82+
* For some reason, tailwindcss-intellisense passes
83+
* object and undefined values in here, so we handle
84+
* those cases so it doesn't break IDE plugins.
85+
*/
86+
if (!value || isPlainObject(value)) return {}
87+
8288
let [fontSize, options] = Array.isArray(value) ? value : [value]
8389
let fontSizeActual = normalizeValue(fontSize, rootSize)
8490
let { lineHeight } = (
@@ -87,7 +93,7 @@ const thisPlugin: PluginType = createPlugin.withOptions<CapsizePluginOptions>(
8793

8894
return {
8995
'--font-size-px': String(fontSizeActual),
90-
...lineHeightProperties(lineHeight, rootSize),
96+
...(lineHeight ? lineHeightProperties(lineHeight, rootSize) : {}),
9197
}
9298
},
9399
},
@@ -100,11 +106,10 @@ const thisPlugin: PluginType = createPlugin.withOptions<CapsizePluginOptions>(
100106
// Line-height
101107
matchUtilities(
102108
{
103-
// @ts-expect-error -- Extra custom properties mismatches base type.
104109
leading(value: string | string[]) {
105110
let lineHeight = normalizeThemeValue('lineHeight', value) as string
106111

107-
return lineHeightProperties(lineHeight, rootSize)
112+
return lineHeight ? lineHeightProperties(lineHeight, rootSize) : {}
108113
},
109114
},
110115
{

src/utilities.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ export function round(value: number) {
8383
* Takes a theme value for lineHeight and returns the `--line-height-offset`
8484
* custom property.
8585
*/
86-
export function lineHeightProperties(lineHeight?: string, rootSize = 16) {
87-
if (lineHeight === undefined) return {}
88-
86+
export function lineHeightProperties(lineHeight: string, rootSize = 16) {
8987
let lineHeightActual = isRelativeValue(lineHeight)
9088
? `calc(${getRelativeValue(lineHeight).toString()} * var(--font-size-px))`
9189
: normalizeValue(lineHeight, rootSize).toString()

0 commit comments

Comments
 (0)