Skip to content

Commit 4169bb1

Browse files
committed
Simplify implementation, remove unnecessary new features
1 parent fc1d4c4 commit 4169bb1

File tree

7 files changed

+29
-312
lines changed

7 files changed

+29
-312
lines changed

__tests__/tailwindAtRule.test.js

Lines changed: 0 additions & 226 deletions
This file was deleted.

src/lib/purgeUnusedStyles.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ function removeTailwindComments(css) {
1111
case 'tailwind start base':
1212
case 'tailwind start components':
1313
case 'tailwind start utilities':
14-
case 'tailwind start screens':
1514
case 'tailwind end base':
1615
case 'tailwind end components':
1716
case 'tailwind end utilities':
18-
case 'tailwind end screens':
1917
comment.remove()
2018
break
2119
default:

src/lib/substituteResponsiveAtRules.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ export default function(config) {
1010
theme: { screens },
1111
separator,
1212
} = config
13-
const responsiveRules = {
14-
components: postcss.root(),
15-
utilities: postcss.root(),
16-
}
13+
const responsiveRules = postcss.root()
1714
const finalRules = []
1815

1916
css.walkAtRules('responsive', atRule => {
20-
const bucket = atRule.params === 'components' ? 'components' : 'utilities'
2117
const nodes = atRule.nodes
22-
responsiveRules[bucket].append(...cloneNodes(nodes))
18+
responsiveRules.append(...cloneNodes(nodes))
2319
atRule.before(nodes)
2420
atRule.remove()
2521
})
@@ -30,10 +26,8 @@ export default function(config) {
3026
params: buildMediaQuery(screens[screen]),
3127
})
3228

33-
mediaQuery.append(postcss.comment({ text: 'tailwind start components' }))
34-
3529
mediaQuery.append(
36-
_.tap(responsiveRules.components.clone(), clonedRoot => {
30+
_.tap(responsiveRules.clone(), clonedRoot => {
3731
clonedRoot.walkRules(rule => {
3832
rule.selectors = _.map(rule.selectors, selector =>
3933
buildSelectorVariant(selector, screen, separator, message => {
@@ -44,24 +38,6 @@ export default function(config) {
4438
})
4539
)
4640

47-
mediaQuery.append(postcss.comment({ text: 'tailwind end components' }))
48-
49-
mediaQuery.append(postcss.comment({ text: 'tailwind start utilities' }))
50-
51-
mediaQuery.append(
52-
_.tap(responsiveRules.utilities.clone(), clonedRoot => {
53-
clonedRoot.walkRules(rule => {
54-
rule.selectors = _.map(rule.selectors, selector =>
55-
buildSelectorVariant(selector, screen, separator, message => {
56-
throw rule.error(message)
57-
})
58-
)
59-
})
60-
})
61-
)
62-
63-
mediaQuery.append(postcss.comment({ text: 'tailwind end utilities' }))
64-
6541
finalRules.push(mediaQuery)
6642
})
6743

src/lib/substituteTailwindAtRules.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,58 +49,24 @@ export default function(
4949

5050
let includesScreensExplicitly = false
5151

52-
function hasChildren(atRule) {
53-
return atRule.nodes !== undefined && atRule.nodes.length > 0
54-
}
55-
56-
function extractChildren(atRule, bucket) {
57-
if (hasChildren(atRule)) {
58-
atRule.walkAtRules('variants', variantsAtRule => {
59-
const params = postcss.list.comma(variantsAtRule.params)
60-
if (params.includes('responsive')) {
61-
variantsAtRule.params = params.filter(p => p !== 'responsive').join(', ')
62-
variantsAtRule.before(
63-
postcss.atRule({ name: 'responsive', nodes: [variantsAtRule.clone()] })
64-
)
65-
variantsAtRule.remove()
66-
}
67-
})
68-
69-
atRule.walkAtRules('responsive', responsiveAtRule => {
70-
responsiveAtRule.params = bucket
71-
})
72-
73-
atRule.before(atRule.nodes)
74-
}
75-
}
76-
7752
css.walkAtRules('tailwind', atRule => {
7853
if (atRule.params === 'preflight') {
7954
// prettier-ignore
8055
throw atRule.error("`@tailwind preflight` is not a valid at-rule in Tailwind v1.0, use `@tailwind base` instead.", { word: 'preflight' })
8156
}
8257

8358
if (atRule.params === 'base') {
84-
atRule.before(postcss.comment({ text: 'tailwind start base' }))
8559
atRule.before(updateSource(pluginBase, atRule.source))
86-
extractChildren(atRule, 'base')
87-
atRule.before(postcss.comment({ text: 'tailwind end base' }))
8860
atRule.remove()
8961
}
9062

9163
if (atRule.params === 'components') {
92-
atRule.before(postcss.comment({ text: 'tailwind start components' }))
9364
atRule.before(updateSource(pluginComponents, atRule.source))
94-
extractChildren(atRule, 'components')
95-
atRule.before(postcss.comment({ text: 'tailwind end components' }))
9665
atRule.remove()
9766
}
9867

9968
if (atRule.params === 'utilities') {
100-
atRule.before(postcss.comment({ text: 'tailwind start utilities' }))
10169
atRule.before(updateSource(pluginUtilities, atRule.source))
102-
extractChildren(atRule, 'utilities')
103-
atRule.before(postcss.comment({ text: 'tailwind end utilities' }))
10470
atRule.remove()
10571
}
10672
})

src/processTailwindFeatures.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export default function(getConfig) {
2424
substituteResponsiveAtRules(config),
2525
substituteScreenAtRules(config),
2626
substituteClassApplyAtRules(config, processedPlugins.utilities),
27+
function(css) {
28+
css.walkAtRules('bucket', atRule => {
29+
const bucket = atRule.params
30+
atRule.before(postcss.comment({ text: `tailwind start ${bucket}` }))
31+
atRule.before(atRule.nodes)
32+
atRule.before(postcss.comment({ text: `tailwind end ${bucket}` }))
33+
atRule.remove()
34+
})
35+
},
2736
purgeUnusedStyles(config),
2837
]).process(css, { from: _.get(css, 'source.input.file') })
2938
}

0 commit comments

Comments
 (0)