@@ -4,7 +4,6 @@ import {type FunctionalPlugin, functionalPlugins, namedPlugins, type Variant} fr
44import { parseVariant } from "./parse-variant" ;
55import { inferDataType } from "./utils/infer-data-type" ;
66import { getValue , type Value } from "./utils/value" ;
7- import { PluginNotFoundException } from "./exceptions/plugin-not-found-exception" ;
87import type { Config , ScreensConfig } from "tailwindcss/types/config" ;
98import { getTailwindTheme } from "./theme" ;
109import { CalculateHexFromString } from "./utils/calculate-hex-from-string" ;
@@ -98,7 +97,6 @@ export const parse = (input: string, config?: Config): AST | Error => {
9897 const availablePlugins = functionalPlugins . get ( root ) as FunctionalPlugin [ ]
9998 let modifier : string | null = null
10099 let [ valueWithoutModifier , modifierSegment = null ] = segment ( value || "" , '/' )
101-
102100 if ( modifierSegment && isColor ( valueWithoutModifier , theme ) ) {
103101 modifier = buildModifier ( modifierSegment , theme . opacity )
104102 }
@@ -110,6 +108,13 @@ export const parse = (input: string, config?: Config): AST | Error => {
110108
111109 if ( unitType === "color" ) {
112110 const color = CalculateHexFromString ( arbitraryValue )
111+ if ( ! color ) {
112+ return {
113+ root : base ,
114+ kind : "error" ,
115+ message : "Color is not correct" ,
116+ }
117+ }
113118 valueWithoutModifier = findTailwindColorFromHex ( color . hex , theme [ associatedPluginByType ?. scaleKey || "colors" ] ) || color . hex
114119 }
115120
@@ -135,10 +140,15 @@ export const parse = (input: string, config?: Config): AST | Error => {
135140 if ( ! value ) {
136141 value = 'DEFAULT'
137142 }
143+
138144 //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 ] )
140146 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+ }
142152 }
143153
144154 const val = getValue ( matchedPlugin . type === "color" ? valueWithoutModifier : value , matchedPlugin , theme [ matchedPlugin . scaleKey ] )
0 commit comments