Skip to content

Commit

Permalink
distinguish between pseudo selectors with and without children
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jun 22, 2024
1 parent 9169091 commit a5ee8fb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
70 changes: 38 additions & 32 deletions packages/cli/src/plugins/resource/plugin-standard-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function bundleCss(body, url, compilation) {

walk(ast, {
enter: function (node, item) { // eslint-disable-line complexity
const { type, name, value } = node;
const { type, name, value, children } = node;

if ((type === 'String' || type === 'Url') && this.atrulePrelude && this.atrule.name === 'import') {
const { value } = node;
Expand Down Expand Up @@ -83,23 +83,26 @@ function bundleCss(body, url, compilation) {
} else if (type === 'PseudoClassSelector') {
optimizedCss += `:${name}`;

switch (name) {
if (children) {
switch (name) {

case 'dir':
case 'is':
case 'has':
case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-of-type':
case 'nth-last-of-type':
case 'where':
optimizedCss += '(';
break;
default:
break;
case 'dir':
case 'host':
case 'is':
case 'has':
case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-of-type':
case 'nth-last-of-type':
case 'where':
optimizedCss += '(';
break;
default:
break;

}
}
} else if (type === 'PseudoElementSelector') {
optimizedCss += `::${name}`;
Expand Down Expand Up @@ -208,23 +211,26 @@ function bundleCss(body, url, compilation) {
optimizedCss += ')';
break;
case 'PseudoClassSelector':
switch (node.name) {

case 'dir':
case 'is':
case 'has':
case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-last-of-type':
case 'nth-of-type':
case 'where':
optimizedCss += ')';
break;
default:
break;
if (node.children) {
switch (node.name) {

case 'dir':
case 'host':
case 'is':
case 'has':
case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-last-of-type':
case 'nth-of-type':
case 'where':
optimizedCss += ')';
break;
default:
break;

}
}
break;
case 'PseudoElementSelector':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ h1{background-image:url('/foo/bar.baz')}

:dir(rtl){background-color:red}

:host(h1){color:red}

::slotted(.content){background-color:aqua}

h2 ::slotted(span){background:silver}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ h1 {
background-color: red;
}

:host(h1) {
color: red;
}

::slotted(.content) {
background-color: aqua;
}
Expand Down

0 comments on commit a5ee8fb

Please sign in to comment.