Skip to content

Commit 1e5742c

Browse files
committed
Fix wildcard duplication issue
This would be better as a symbol but the stringy-ness of class candidates is fairly well baked into assumptions across the codebase. new String + a well placed check seems to solve the problem
1 parent db475be commit 1e5742c

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/lib/expandTailwindAtRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default function expandTailwindAtRules(context) {
158158
// ---
159159

160160
// Find potential rules in changed files
161-
let candidates = new Set(['*'])
161+
let candidates = new Set([sharedState.NOT_ON_DEMAND])
162162
let seen = new Set()
163163

164164
env.DEBUG && console.time('Reading changed files')

src/lib/generateRules.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import isPlainObject from '../util/isPlainObject'
55
import prefixSelector from '../util/prefixSelector'
66
import { updateAllClasses } from '../util/pluginUtils'
77
import log from '../util/log'
8+
import * as sharedState from './sharedState'
89
import { formatVariantSelector, finalizeSelector } from '../util/formatVariantSelector'
910
import { asClass } from '../util/nameClass'
1011
import { normalize } from '../util/dataTypes'
@@ -382,6 +383,10 @@ function* resolveMatchedPlugins(classCandidate, context) {
382383
}
383384

384385
function splitWithSeparator(input, separator) {
386+
if (input === sharedState.NOT_ON_DEMAND) {
387+
return [sharedState.NOT_ON_DEMAND]
388+
}
389+
385390
return input.split(new RegExp(`\\${separator}(?![^[]*\\])`, 'g'))
386391
}
387392

src/lib/setupContextUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function withIdentifiers(styles) {
138138

139139
// If this isn't "on-demandable", assign it a universal candidate to always include it.
140140
if (containsNonOnDemandableSelectors) {
141-
candidates.unshift('*')
141+
candidates.unshift(sharedState.NOT_ON_DEMAND)
142142
}
143143

144144
// However, it could be that it also contains "on-demandable" candidates.
@@ -163,8 +163,8 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
163163
}
164164

165165
function prefixIdentifier(identifier, options) {
166-
if (identifier === '*') {
167-
return '*'
166+
if (identifier === sharedState.NOT_ON_DEMAND) {
167+
return sharedState.NOT_ON_DEMAND
168168
}
169169

170170
if (!options.respectPrefix) {

src/lib/sharedState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const env = {
55
export const contextMap = new Map()
66
export const configContextMap = new Map()
77
export const contextSourcesMap = new Map()
8+
export const NOT_ON_DEMAND = new String('*')
89

910
export function resolveDebug(debug) {
1011
if (debug === undefined) {

tests/basic-usage.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { html, run, css } from './util/run'
4+
import { html, run, css, defaults } from './util/run'
55

66
test('basic usage', () => {
77
let config = {
@@ -188,3 +188,25 @@ it('can scan extremely long classes without crashing', () => {
188188
expect(result.css).toMatchFormattedCss(css``)
189189
})
190190
})
191+
192+
it('variant star duplicate issue', () => {
193+
let config = {
194+
content: [{ raw: html`underline focus:*` }],
195+
corePlugins: { preflight: false },
196+
}
197+
198+
let input = css`
199+
@tailwind base;
200+
@tailwind components;
201+
@tailwind utilities;
202+
`
203+
204+
return run(input, config).then((result) => {
205+
expect(result.css).toMatchFormattedCss(css`
206+
${defaults}
207+
.underline {
208+
text-decoration-line: underline;
209+
}
210+
`)
211+
})
212+
})

0 commit comments

Comments
 (0)