Skip to content

Commit 106b904

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.
1 parent f9d0818 commit 106b904

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
@@ -512,11 +512,13 @@ export class ShadowCss {
512512
return cssText.replace(_cssColonHostRe, (_, hostSelectors: string, otherSelectors: string) => {
513513
if (hostSelectors) {
514514
const convertedSelectors: string[] = [];
515-
const hostSelectorArray = hostSelectors.split(',').map((p) => p.trim());
516-
for (const hostSelector of hostSelectorArray) {
517-
if (!hostSelector) break;
515+
for (const hostSelector of this._splitOnTopLevelCommas(hostSelectors)) {
516+
const trimmedHostSelector = hostSelector.trim();
517+
if (!trimmedHostSelector) break;
518518
const convertedSelector =
519-
_polyfillHostNoCombinator + hostSelector.replace(_polyfillHost, '') + otherSelectors;
519+
_polyfillHostNoCombinator +
520+
trimmedHostSelector.replace(_polyfillHost, '') +
521+
otherSelectors;
520522
convertedSelectors.push(convertedSelector);
521523
}
522524
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)