Skip to content

Commit 49ac1b6

Browse files
author
Cem Yılmaz
committed
white or black detection fixed on parsing and removed exceptions
1 parent 34b5be4 commit 49ac1b6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/parse.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {type FunctionalPlugin, functionalPlugins, namedPlugins, type Variant} fr
44
import {parseVariant} from "./parse-variant";
55
import {inferDataType} from "./utils/infer-data-type";
66
import {getValue, type Value} from "./utils/value";
7-
import {PluginNotFoundException} from "./exceptions/plugin-not-found-exception";
87
import type {Config, ScreensConfig} from "tailwindcss/types/config";
98
import {getTailwindTheme} from "./theme";
109
import {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

Comments
 (0)