Skip to content

Commit 58722d5

Browse files
committed
use known tree to handle @apply when required @tailwind at rules exists
Otherwise we will generate the lookup tree.
1 parent 142b4a0 commit 58722d5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

__tests__/applyAtRule.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,16 @@ test('you can apply utility classes that do not actually exist as long as they w
337337
})
338338
})
339339

340-
test('the shadow lookup is only used if no @tailwind rules were in the source tree', () => {
340+
test('shadow lookup will be constructed when we have missing @tailwind atrules', () => {
341341
const input = `
342342
@tailwind base;
343343
.foo { @apply mt-4; }
344344
`
345345

346346
expect.assertions(1)
347347

348-
return run(input).catch((e) => {
349-
expect(e).toMatchObject({ name: 'CssSyntaxError' })
348+
return run(input).then((result) => {
349+
expect(result.css).toContain(`.foo { margin-top: 1rem;\n}`)
350350
})
351351
})
352352

src/lib/substituteClassApplyAtRules.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,15 @@ export default function substituteClassApplyAtRules(config, getProcessedPlugins,
310310
}
311311

312312
// Tree already contains @tailwind rules, don't prepend default Tailwind tree
313-
if (hasAtRule(css, 'tailwind')) {
313+
let requiredTailwindAtRules = ['utilities']
314+
if (
315+
hasAtRule(css, 'tailwind', (node) => {
316+
let idx = requiredTailwindAtRules.indexOf(node.params)
317+
if (idx !== -1) requiredTailwindAtRules.splice(idx, 1)
318+
if (requiredTailwindAtRules.length <= 0) return true
319+
return false
320+
})
321+
) {
314322
return processApplyAtRules(css, postcss.root(), config)
315323
}
316324

0 commit comments

Comments
 (0)