Skip to content

Commit 1e09bdc

Browse files
mattrbeckAndrewKushnir
authored andcommitted
fix(compiler): support commas in :host() argument
This change adds support for commas in :host() arguments (e.g. `:host(:not(.foo, .bar))` as well as in nested parens when the argument is applied without parens (e.g. `:host:not(:has(.foo, .bar))`). Previously these selectors would receive an extra `[nghost]` attr, e.g. `[nghost]:not(.foo, [nghost].bar)`. I didn't file a bug for this one, but it's also blocking on an internal LSC. Like the other CSS changes, I'll run a TGP to confirm this isn't breaking. (cherry picked from commit 680c3c7)
1 parent 143883a commit 1e09bdc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/compiler/src/shadow_css.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,13 @@ export class ShadowCss {
511511
return cssText.replace(_cssColonHostRe, (_, hostSelectors: string, otherSelectors: string) => {
512512
if (hostSelectors) {
513513
const convertedSelectors: string[] = [];
514-
const hostSelectorArray = hostSelectors.split(',').map((p) => p.trim());
515-
for (const hostSelector of hostSelectorArray) {
516-
if (!hostSelector) break;
514+
for (const hostSelector of this._splitOnTopLevelCommas(hostSelectors)) {
515+
const trimmedHostSelector = hostSelector.trim();
516+
if (!trimmedHostSelector) break;
517517
const convertedSelector =
518-
_polyfillHostNoCombinator + hostSelector.replace(_polyfillHost, '') + otherSelectors;
518+
_polyfillHostNoCombinator +
519+
trimmedHostSelector.replace(_polyfillHost, '') +
520+
otherSelectors;
519521
convertedSelectors.push(convertedSelector);
520522
}
521523
return convertedSelectors.join(',');

packages/compiler/test/shadow_css/host_and_host_context_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ describe('ShadowCss, :host and :host-context', () => {
101101
expect(shim(':host:not(.foo, .bar) {}', 'contenta', 'a-host')).toEqualCss(
102102
'[a-host]:not(.foo, .bar) {}',
103103
);
104+
expect(shim(':host:not(:has(p, a)) {}', 'contenta', 'a-host')).toEqualCss(
105+
'[a-host]:not(:has(p, a)) {}',
106+
);
107+
expect(shim(':host(:not(.foo, .bar)) {}', 'contenta', 'a-host')).toEqualCss(
108+
'[a-host]:not(.foo, .bar) {}',
109+
);
104110
});
105111

106112
// see b/63672152

0 commit comments

Comments
 (0)