Skip to content
Closed
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
13 changes: 7 additions & 6 deletions packages/compiler/src/shadow_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ export class ShadowCss {
},
);
})
.replace(_polyfillHostRe, replaceBy + ' ');
.replace(_polyfillHostRe, replaceBy);
}

return scopeSelector + ' ' + selector;
Expand All @@ -765,7 +765,7 @@ export class ShadowCss {
const isRe = /\[is=([^\]]*)\]/g;
scopeSelector = scopeSelector.replace(isRe, (_: string, ...parts: string[]) => parts[0]);

const attrName = '[' + scopeSelector + ']';
const attrName = `[${scopeSelector}]`;

const _scopeSelectorPart = (p: string) => {
let scopedP = p.trim();
Expand All @@ -776,7 +776,7 @@ export class ShadowCss {

if (p.includes(_polyfillHostNoCombinator)) {
scopedP = this._applySimpleSelectorScope(p, scopeSelector, hostSelector);
if (_polyfillHostNoCombinatorWithinPseudoFunction.test(p)) {
if (!p.match(_polyfillHostNoCombinatorOutsidePseudoFunction)) {
const [_, before, colon, after] = scopedP.match(/([^:]*)(:*)(.*)/)!;
scopedP = before + attrName + colon + after;
}
Expand Down Expand Up @@ -979,10 +979,11 @@ const _cssColonHostContextReGlobal = new RegExp(
);
const _cssColonHostContextRe = new RegExp(_polyfillHostContext + _parenSuffix, 'im');
const _polyfillHostNoCombinator = _polyfillHost + '-no-combinator';
const _polyfillHostNoCombinatorWithinPseudoFunction = new RegExp(
`:.*\\(.*${_polyfillHostNoCombinator}.*\\)`,
const _polyfillHostNoCombinatorOutsidePseudoFunction = new RegExp(
`${_polyfillHostNoCombinator}(?![^(]*\\))`,
'g',
);
const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s]*)/;
const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s,]*)/;
const _polyfillHostNoCombinatorReGlobal = new RegExp(_polyfillHostNoCombinatorRe, 'g');
const _shadowDOMSelectorsRe = [
/::shadow/g,
Expand Down
15 changes: 15 additions & 0 deletions packages/compiler/test/shadow_css/host_and_host_context_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ describe('ShadowCss, :host and :host-context', () => {
expect(shim(':host(:not(p)):before {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not(p):before {}',
);
expect(shim(':host:not(:host.foo) {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not([a-host].foo) {}',
);
expect(shim(':host:not(.foo:host) {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not(.foo[a-host]) {}',
);
expect(shim(':host:not(:host.foo, :host.bar) {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not([a-host].foo, .bar[a-host]) {}',
);
expect(shim(':host:not(:host.foo, .bar :host) {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not([a-host].foo, .bar [a-host]) {}',
);
expect(shim(':host:not(.foo, .bar) {}', 'contenta', 'a-host')).toEqualCss(
'[a-host]:not(.foo, .bar) {}',
);
});

// see b/63672152
Expand Down
18 changes: 18 additions & 0 deletions packages/compiler/test/shadow_css/shadow_css_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ describe('ShadowCss', () => {
expect(shim(':has(a) :has(b) {}', 'contenta', 'hosta')).toEqualCss(
'[contenta]:has(a) [contenta]:has(b) {}',
);
expect(shim(':has(a, b) {}', 'contenta', 'hosta')).toEqualCss('[contenta]:has(a, b) {}');
expect(shim(':has(a, b:where(.foo), :is(.bar)) {}', 'contenta', 'hosta')).toEqualCss(
'[contenta]:has(a, b:where(.foo), :is(.bar)) {}',
);
expect(
shim(':has(a, b:where(.foo), :is(.bar):first-child):first-letter {}', 'contenta', 'hosta'),
).toEqualCss('[contenta]:has(a, b:where(.foo), :is(.bar):first-child):first-letter {}');
expect(
shim(':where(a, b:where(.foo), :has(.bar):first-child) {}', 'contenta', 'hosta'),
).toEqualCss(
':where(a[contenta], b[contenta]:where(.foo), [contenta]:has(.bar):first-child) {}',
);
expect(shim(':has(.one :host, .two) {}', 'contenta', 'hosta')).toEqualCss(
'[contenta]:has(.one [hosta], .two) {}',
);
expect(shim(':has(.one, :host) {}', 'contenta', 'hosta')).toEqualCss(
'[contenta]:has(.one, [hosta]) {}',
);
});

it('should handle :host inclusions inside pseudo-selectors selectors', () => {
Expand Down