Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement/issue 1178 support all remaining standard pseudo-class and element selectors for CSS bundling #1239

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 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,16 +83,35 @@ function bundleCss(body, url, compilation) {
} else if (type === 'PseudoClassSelector') {
optimizedCss += `:${name}`;

if (children) {
switch (name) {

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}`;

switch (name) {

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 'highlight':
case 'part':
case 'slotted':
optimizedCss += '(';
break;
default:
Expand Down Expand Up @@ -192,16 +211,34 @@ function bundleCss(body, url, compilation) {
optimizedCss += ')';
break;
case 'PseudoClassSelector':
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':
switch (node.name) {

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 'highlight':
case 'part':
case 'slotted':
optimizedCss += ')';
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ h1:has(+h2){margin:0 0 0.25rem 0}
h1{background-image:url('/foo/bar.baz')}

.has-success{background-image:url('data:image/svg+xml;...')}

:where(html){--size-000:-.5rem}

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

:host(h1){color:red}

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

h2 ::slotted(span){background:silver}

tabbed-custom-element::part(tab){color:#0c0dcc;border-bottom:transparent solid 2px;}

::highlight(rainbow-color-1){color:#ad26ad;text-decoration:underline;}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ h1:has(+ h2) {
color: green;
}


.snippet {
margin: var(--size-4) 0;
padding: 0 var(--size-4);
Expand All @@ -142,6 +141,36 @@ h1 {
background-image: url('/foo/bar.baz');
}

.has-success{
.has-success {
background-image: url("data:image/svg+xml;...");
}

:where(html) {
--size-000: -.5rem;
}

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

:host(h1) {
color: red;
}

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

h2 ::slotted(span) {
background: silver;
}

tabbed-custom-element::part(tab) {
color: #0c0dcc;
border-bottom: transparent solid 2px;
}

::highlight(rainbow-color-1) {
color: #ad26ad;
text-decoration: underline;
}
Loading