Skip to content

Commit 80ee4f7

Browse files
committed
fix: classes are not reduced when prefix is used
1 parent 3dfdaff commit 80ee4f7

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/TailwindConverter.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ export class TailwindConverter {
140140
});
141141

142142
if (tailwindClasses.length) {
143-
return this.makeTailwindNode(
144-
rule,
145-
reduceTailwindClasses(tailwindClasses)
146-
);
143+
tailwindClasses = reduceTailwindClasses(tailwindClasses);
144+
145+
if (this.config.tailwindConfig.prefix) {
146+
tailwindClasses = tailwindClasses.map(className =>
147+
className[0] === '[' // is "arbitrary property" class
148+
? className
149+
: `${this.config.tailwindConfig.prefix}${className}`
150+
);
151+
}
152+
153+
return this.makeTailwindNode(rule, tailwindClasses);
147154
}
148155

149156
return null;
@@ -162,11 +169,7 @@ export class TailwindConverter {
162169
];
163170
}
164171

165-
return this.config.tailwindConfig.prefix
166-
? classes.map(
167-
className => `${this.config.tailwindConfig.prefix}${className}`
168-
)
169-
: classes;
172+
return classes;
170173
}
171174

172175
protected makeTailwindNode(

test/TailwindConverter.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const complexCSS: string = fs
1111

1212
const simpleCSS = `
1313
.foo {
14-
text-align: center;
14+
padding-top: 12px;
15+
padding-bottom: 12px;
1516
font-size: 12px;
1617
animation-delay: 200ms;
1718
@@ -71,8 +72,8 @@ describe('TailwindConverter', () => {
7172
{
7273
rule: expect.objectContaining({ selector: '.foo' }),
7374
tailwindClasses: [
74-
'text-center',
7575
'text-xs',
76+
'py-3',
7677
'hover:blur-sm',
7778
'hover:brightness-50',
7879
'hover:sepia',
@@ -106,8 +107,8 @@ describe('TailwindConverter', () => {
106107
{
107108
rule: expect.objectContaining({ selector: '.foo' }),
108109
tailwindClasses: [
109-
'tw-text-center',
110110
'tw-text-xs',
111+
'tw-py-3',
111112
'hover_tw-blur-sm',
112113
'hover_tw-brightness-50',
113114
'hover_tw-sepia',
@@ -133,9 +134,9 @@ describe('TailwindConverter', () => {
133134
{
134135
rule: expect.objectContaining({ selector: '.foo' }),
135136
tailwindClasses: [
136-
'text-center',
137137
'text-xs',
138138
'[animation-delay:200ms]',
139+
'py-3',
139140
'hover:blur-sm',
140141
'hover:brightness-50',
141142
'hover:sepia',

test/__snapshots__/TailwindConverter.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`TailwindConverter should consider \`prefix\`, \`separator\` and \`corePlugins\` configurations 1`] = `
44
".foo {
5-
@apply tw-text-center tw-text-xs hover_tw-blur-sm hover_tw-brightness-50 hover_tw-sepia hover_tw-contrast-100 hover_tw-hue-rotate-30 hover_tw-invert-0 hover_tw-opacity-5 hover_tw-saturate-150 hover_tw-text-base;
5+
@apply tw-text-xs tw-py-3 hover_tw-blur-sm hover_tw-brightness-50 hover_tw-sepia hover_tw-contrast-100 hover_tw-hue-rotate-30 hover_tw-invert-0 hover_tw-opacity-5 hover_tw-saturate-150 hover_tw-text-base;
66
animation-delay: 200ms;
77
}
88
.foo:hover {
@@ -154,7 +154,7 @@ exports[`TailwindConverter should convert the css part string 1`] = `
154154

155155
exports[`TailwindConverter should convert the simple CSS 1`] = `
156156
".foo {
157-
@apply text-center text-xs hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:text-base md:font-semibold;
157+
@apply text-xs py-3 hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:text-base md:font-semibold;
158158
animation-delay: 200ms;
159159
}
160160
.foo:hover {
@@ -166,7 +166,7 @@ exports[`TailwindConverter should convert the simple CSS 1`] = `
166166

167167
exports[`TailwindConverter should convert unconvertible declarations if \`arbitraryPropertiesIsEnabled\` config is enabled 1`] = `
168168
".foo {
169-
@apply text-center text-xs [animation-delay:200ms] hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)] hover:text-base md:font-semibold;
169+
@apply text-xs [animation-delay:200ms] py-3 hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)] hover:text-base md:font-semibold;
170170
}
171171
"
172172
`;

0 commit comments

Comments
 (0)