Skip to content

Commit aea747a

Browse files
GeorgySergadevversion
authored andcommitted
fix(compiler): preserve attributes attached to :host selector (#57796)
keep attributes used to scope :host selectors PR Close #57796
1 parent 11692c8 commit aea747a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/compiler/src/shadow_css.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ export class ShadowCss {
804804
cssPrefixWithPseudoSelectorFunctionMatch;
805805
const hasOuterHostNoCombinator = mainSelector.includes(_polyfillHostNoCombinator);
806806
const scopedMainSelector = mainSelector.replace(
807-
_polyfillHostNoCombinatorReGlobal,
807+
_polyfillExactHostNoCombinatorReGlobal,
808808
`[${hostSelector}]`,
809809
);
810810

@@ -982,6 +982,7 @@ const _polyfillHostNoCombinator = _polyfillHost + '-no-combinator';
982982
const _polyfillHostNoCombinatorWithinPseudoFunction = new RegExp(
983983
`:.*(.*${_polyfillHostNoCombinator}.*)`,
984984
);
985+
const _polyfillExactHostNoCombinatorReGlobal = /-shadowcsshost-no-combinator/g;
985986
const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s]*)/;
986987
const _polyfillHostNoCombinatorReGlobal = new RegExp(_polyfillHostNoCombinatorRe, 'g');
987988
const _shadowDOMSelectorsRe = [

packages/compiler/test/shadow_css/shadow_css_spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ describe('ShadowCss', () => {
6767
expect(shim('one[attr] {}', 'contenta')).toEqualCss('one[attr][contenta] {}');
6868
expect(shim('[is="one"] {}', 'contenta')).toEqualCss('[is="one"][contenta] {}');
6969
expect(shim('[attr] {}', 'contenta')).toEqualCss('[attr][contenta] {}');
70+
});
71+
72+
it('should transform :host with attributes and pseudo selectors', () => {
7073
expect(shim(':host [attr] {}', 'contenta', 'hosta')).toEqualCss('[hosta] [attr][contenta] {}');
74+
expect(shim(':host(create-first-project) {}', 'contenta', 'hosta')).toEqualCss(
75+
'create-first-project[hosta] {}',
76+
);
77+
expect(shim(':host[attr] {}', 'contenta', 'hosta')).toEqualCss('[attr][hosta] {}');
78+
expect(shim(':host[attr]:where(:not(.cm-button)) {}', 'contenta', 'hosta')).toEqualCss(
79+
'[hosta][attr]:where(:not(.cm-button)) {}',
80+
);
7181
});
7282

7383
it('should handle escaped sequences in selectors', () => {

0 commit comments

Comments
 (0)