@@ -4,7 +4,6 @@ import {type FunctionalPlugin, functionalPlugins, namedPlugins, type Variant} fr
4
4
import { parseVariant } from "./parse-variant" ;
5
5
import { inferDataType } from "./utils/infer-data-type" ;
6
6
import { getValue , type Value } from "./utils/value" ;
7
- import { PluginNotFoundException } from "./exceptions/plugin-not-found-exception" ;
8
7
import type { Config , ScreensConfig } from "tailwindcss/types/config" ;
9
8
import { getTailwindTheme } from "./theme" ;
10
9
import { CalculateHexFromString } from "./utils/calculate-hex-from-string" ;
@@ -98,7 +97,6 @@ export const parse = (input: string, config?: Config): AST | Error => {
98
97
const availablePlugins = functionalPlugins . get ( root ) as FunctionalPlugin [ ]
99
98
let modifier : string | null = null
100
99
let [ valueWithoutModifier , modifierSegment = null ] = segment ( value || "" , '/' )
101
-
102
100
if ( modifierSegment && isColor ( valueWithoutModifier , theme ) ) {
103
101
modifier = buildModifier ( modifierSegment , theme . opacity )
104
102
}
@@ -110,6 +108,13 @@ export const parse = (input: string, config?: Config): AST | Error => {
110
108
111
109
if ( unitType === "color" ) {
112
110
const color = CalculateHexFromString ( arbitraryValue )
111
+ if ( ! color ) {
112
+ return {
113
+ root : base ,
114
+ kind : "error" ,
115
+ message : "Color is not correct" ,
116
+ }
117
+ }
113
118
valueWithoutModifier = findTailwindColorFromHex ( color . hex , theme [ associatedPluginByType ?. scaleKey || "colors" ] ) || color . hex
114
119
}
115
120
@@ -135,10 +140,15 @@ export const parse = (input: string, config?: Config): AST | Error => {
135
140
if ( ! value ) {
136
141
value = 'DEFAULT'
137
142
}
143
+
138
144
//check value against each scale of available plugins
139
- let matchedPlugin = availablePlugins . find ( ( { scaleKey} ) => value . split ( '-' ) [ 0 ] in theme [ scaleKey ] )
145
+ let matchedPlugin = availablePlugins . find ( ( { scaleKey} ) => value . split ( '-' ) [ 0 ] in theme [ scaleKey ] || valueWithoutModifier in theme [ scaleKey ] )
140
146
if ( ! matchedPlugin ) {
141
- throw new PluginNotFoundException ( base )
147
+ return {
148
+ root : base ,
149
+ kind : "error" ,
150
+ message : `found "${ availablePlugins . map ( x => x . ns ) . join ( ', ' ) } " plugins but unable to determine which one is matched to given value "${ value } ".` ,
151
+ }
142
152
}
143
153
144
154
const val = getValue ( matchedPlugin . type === "color" ? valueWithoutModifier : value , matchedPlugin , theme [ matchedPlugin . scaleKey ] )
0 commit comments