Skip to content

Commit ac443a4

Browse files
author
Cem Yılmaz
committed
fix something, broke something.
1 parent 63c4958 commit ac443a4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/parse.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {getTailwindTheme} from "./theme";
1010
import {CalculateHexFromString} from "./utils/calculate-hex-from-string";
1111
import {findTailwindColorFromHex} from "./utils/find-tailwind-color-from-hex";
1212
import {buildModifier} from "./utils/build-modifier";
13+
import {isColor} from "./utils/is-color";
1314

1415
export type State = {
1516
important: boolean
@@ -98,7 +99,7 @@ export const parse = (input: string, config?: Config): AST | Error => {
9899
let modifier: string | null = null
99100
let [valueWithoutModifier, modifierSegment = null] = segment(value || "", '/')
100101

101-
if (modifierSegment) {
102+
if (modifierSegment && isColor(valueWithoutModifier, theme)) {
102103
modifier = buildModifier(modifierSegment, theme.opacity)
103104
}
104105

@@ -140,10 +141,6 @@ export const parse = (input: string, config?: Config): AST | Error => {
140141
throw new PluginNotFoundException(base)
141142
}
142143

143-
if(matchedPlugin.type !== "color"){
144-
modifier = null
145-
}
146-
147144
const val = getValue(matchedPlugin.type === "color" ? valueWithoutModifier : value, matchedPlugin, theme[matchedPlugin.scaleKey])
148145

149146
return {

src/utils/is-color.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {CustomThemeConfig} from "tailwindcss/types/config"
22
import {segment} from "./segment";
3+
import get from "lodash/get";
34

45
const HASH = 0x23
56

@@ -207,7 +208,7 @@ export function isColor(value: string, theme?: CustomThemeConfig): boolean {
207208

208209
if (theme) {
209210
const [trueValue,] = segment(value, '/')
210-
isThemeColor = !!trueValue.split('-').reduce((acc, val) => acc[val], theme.colors as any);
211+
isThemeColor = !!get(theme.colors as any, trueValue.split('-').join('.'))
211212
}
212213

213214
return (

src/utils/value.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {DataType} from "./infer-data-type";
22
import type {FunctionalPlugin} from "../plugins";
33
import {UnmatchedValueException} from "../exceptions/unmatched-value-exception";
4+
import get from "lodash/get";
45

56
export type Value = {
67
kind: DataType,
@@ -11,7 +12,7 @@ export type Value = {
1112

1213
export const getValue = (value: string, plugin: FunctionalPlugin, scale: any): Value => {
1314
if (plugin.type === "color") {
14-
let matchedColor = value.split('-').reduce((acc, val) => acc[val], scale);
15+
let matchedColor = get(scale, value.split('-').join('.'))
1516
if (!matchedColor) {
1617
throw new UnmatchedValueException(plugin.ns, value)
1718
}

0 commit comments

Comments
 (0)