File tree Expand file tree Collapse file tree 2 files changed +92
-2
lines changed Expand file tree Collapse file tree 2 files changed +92
-2
lines changed Original file line number Diff line number Diff line change @@ -59,11 +59,22 @@ function getClasses(selector) {
5959}
6060
6161function extractCandidates ( node ) {
62- let classes = node . type === 'rule' ? getClasses ( node . selector ) : [ ]
62+ let classes = [ ]
63+
64+ if ( node . type === 'rule' ) {
65+ for ( let selector of node . selectors ) {
66+ let classCandidates = getClasses ( selector )
67+ // At least one of the selectors contains non-"on-demandable" candidates.
68+ if ( classCandidates . length === 0 ) return [ ]
69+
70+ classes = [ ...classes , ...classCandidates ]
71+ }
72+ return classes
73+ }
6374
6475 if ( node . type === 'atrule' ) {
6576 node . walkRules ( ( rule ) => {
66- classes = [ ...classes , ...getClasses ( rule . selector ) ]
77+ classes = [ ...classes , ...rule . selectors . flatMap ( ( selector ) => getClasses ( selector ) ) ]
6778 } )
6879 }
6980
Original file line number Diff line number Diff line change 1+ import { run , html , css } from './util/run'
2+
3+ it ( 'should generate the partial selector, if only a partial is used (base layer)' , ( ) => {
4+ let config = {
5+ content : [ { raw : html `<div> </ div> ` } ] ,
6+ corePlugins : { preflight : false } ,
7+ }
8+
9+ let input = css `
10+ @tailwind base;
11+
12+ @layer base {
13+ : root {
14+ font-weight : bold;
15+ }
16+
17+ /* --- */
18+
19+ : root ,
20+ .a {
21+ color : black;
22+ }
23+ }
24+ `
25+
26+ return run ( input , config ) . then ( ( result ) => {
27+ return expect ( result . css ) . toMatchFormattedCss ( css `
28+ : root {
29+ font-weight : bold;
30+ }
31+
32+ /* --- */
33+
34+ : root ,
35+ .a {
36+ color : black;
37+ }
38+ ` )
39+ } )
40+ } )
41+
42+ it ( 'should generate the partial selector, if only a partial is used (utilities layer)' , ( ) => {
43+ let config = {
44+ content : [ { raw : html `<div class= "a" > </ div> ` } ] ,
45+ corePlugins : { preflight : false } ,
46+ }
47+
48+ let input = css `
49+ @tailwind utilities;
50+
51+ @layer utilities {
52+ : root {
53+ font-weight : bold;
54+ }
55+
56+ /* --- */
57+
58+ : root ,
59+ .a {
60+ color : black;
61+ }
62+ }
63+ `
64+
65+ return run ( input , config ) . then ( ( result ) => {
66+ return expect ( result . css ) . toMatchFormattedCss ( css `
67+ : root {
68+ font-weight : bold;
69+ }
70+
71+ /* --- */
72+
73+ : root ,
74+ .a {
75+ color : black;
76+ }
77+ ` )
78+ } )
79+ } )
You can’t perform that action at this time.
0 commit comments