Skip to content

Commit

Permalink
use known tree to handle @apply when required @tailwind at rules …
Browse files Browse the repository at this point in the history
…exists

Otherwise we will generate the lookup tree.
  • Loading branch information
RobinMalfait committed Dec 8, 2020
1 parent 142b4a0 commit 58722d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions __tests__/applyAtRule.test.js
Expand Up @@ -337,16 +337,16 @@ test('you can apply utility classes that do not actually exist as long as they w
})
})

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

expect.assertions(1)

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

Expand Down
10 changes: 9 additions & 1 deletion src/lib/substituteClassApplyAtRules.js
Expand Up @@ -310,7 +310,15 @@ export default function substituteClassApplyAtRules(config, getProcessedPlugins,
}

// Tree already contains @tailwind rules, don't prepend default Tailwind tree
if (hasAtRule(css, 'tailwind')) {
let requiredTailwindAtRules = ['utilities']
if (
hasAtRule(css, 'tailwind', (node) => {
let idx = requiredTailwindAtRules.indexOf(node.params)
if (idx !== -1) requiredTailwindAtRules.splice(idx, 1)
if (requiredTailwindAtRules.length <= 0) return true
return false
})
) {
return processApplyAtRules(css, postcss.root(), config)
}

Expand Down

0 comments on commit 58722d5

Please sign in to comment.