Skip to content

Commit 417dea2

Browse files
committed
fix(compiler): simplify handling of colon host with a selector list
Update `_convertColonHost` to extract and use only the first argument from a `:host(...)` selector list, ignoring subsequent arguments instead of splitting and duplicating the selector list. Also remove the obsolete test cases from `host_and_host_context_spec.ts`.
1 parent 7623580 commit 417dea2

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

packages/compiler/src/shadow_css.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,17 @@ export class ShadowCss {
511511
private _convertColonHost(cssText: string): string {
512512
return cssText.replace(_cssColonHostRe, (_, hostSelectors: string, otherSelectors: string) => {
513513
if (hostSelectors) {
514-
const convertedSelectors: string[] = [];
515-
for (const hostSelector of this._splitOnTopLevelCommas(hostSelectors, true)) {
516-
const trimmedHostSelector = hostSelector.trim();
517-
if (!trimmedHostSelector) break;
518-
const convertedSelector =
514+
const hostSelector = this._splitOnTopLevelCommas(hostSelectors, true).next().value;
515+
const trimmedHostSelector = hostSelector ? hostSelector.trim() : '';
516+
if (trimmedHostSelector) {
517+
return (
519518
_polyfillHostNoCombinator +
520519
trimmedHostSelector.replace(_polyfillHost, '') +
521-
otherSelectors;
522-
convertedSelectors.push(convertedSelector);
520+
otherSelectors
521+
);
523522
}
524-
return convertedSelectors.join(',');
525-
} else {
526-
return _polyfillHostNoCombinator + otherSelectors;
527523
}
524+
return _polyfillHostNoCombinator + otherSelectors;
528525
});
529526
}
530527

packages/compiler/test/shadow_css/host_and_host_context_spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,10 @@ describe('ShadowCss, :host and :host-context', () => {
4141
expect(shim(':host.pr\\fc fung {}', 'contenta', 'a-host')).toEqual('.pr\\fc fung[a-host] {}');
4242
});
4343

44-
it('should handle multiple tag selectors', () => {
45-
expect(shim(':host(ul,li) {}', 'contenta', 'a-host')).toEqualCss('ul[a-host], li[a-host] {}');
46-
expect(shim(':host(ul,li) > .z {}', 'contenta', 'a-host')).toEqualCss(
47-
'ul[a-host] > .z[contenta], li[a-host] > .z[contenta] {}',
48-
);
49-
});
50-
5144
it('should handle compound class selectors', () => {
5245
expect(shim(':host(.a.b) {}', 'contenta', 'a-host')).toEqualCss('.a.b[a-host] {}');
5346
});
5447

55-
it('should handle multiple class selectors', () => {
56-
expect(shim(':host(.x,.y) {}', 'contenta', 'a-host')).toEqualCss('.x[a-host], .y[a-host] {}');
57-
expect(shim(':host(.x,.y) > .z {}', 'contenta', 'a-host')).toEqualCss(
58-
'.x[a-host] > .z[contenta], .y[a-host] > .z[contenta] {}',
59-
);
60-
});
61-
62-
it('should handle multiple attribute selectors', () => {
63-
expect(shim(':host([a="b"],[c=d]) {}', 'contenta', 'a-host')).toEqualCss(
64-
'[a="b"][a-host], [c=d][a-host] {}',
65-
);
66-
});
67-
6848
it('should handle pseudo selectors', () => {
6949
expect(shim(':host(:before) {}', 'contenta', 'a-host')).toEqualCss('[a-host]:before {}');
7050
expect(shim(':host:before {}', 'contenta', 'a-host')).toEqualCss('[a-host]:before {}');

0 commit comments

Comments
 (0)