fix(compiler): preserve attributes attached to :host selector (#57796)

keep attributes used to scope :host selectors

PR Close #57796
This commit is contained in:
Georgy Serga 2024-09-23 17:55:48 +00:00 committed by Paul Gschwendtner
parent 11692c8dab
commit aea747ab3b
2 changed files with 12 additions and 1 deletions

View file

@ -804,7 +804,7 @@ export class ShadowCss {
cssPrefixWithPseudoSelectorFunctionMatch;
const hasOuterHostNoCombinator = mainSelector.includes(_polyfillHostNoCombinator);
const scopedMainSelector = mainSelector.replace(
_polyfillHostNoCombinatorReGlobal,
_polyfillExactHostNoCombinatorReGlobal,
`[${hostSelector}]`,
);
@ -982,6 +982,7 @@ const _polyfillHostNoCombinator = _polyfillHost + '-no-combinator';
const _polyfillHostNoCombinatorWithinPseudoFunction = new RegExp(
`:.*(.*${_polyfillHostNoCombinator}.*)`,
);
const _polyfillExactHostNoCombinatorReGlobal = /-shadowcsshost-no-combinator/g;
const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s]*)/;
const _polyfillHostNoCombinatorReGlobal = new RegExp(_polyfillHostNoCombinatorRe, 'g');
const _shadowDOMSelectorsRe = [

View file

@ -67,7 +67,17 @@ describe('ShadowCss', () => {
expect(shim('one[attr] {}', 'contenta')).toEqualCss('one[attr][contenta] {}');
expect(shim('[is="one"] {}', 'contenta')).toEqualCss('[is="one"][contenta] {}');
expect(shim('[attr] {}', 'contenta')).toEqualCss('[attr][contenta] {}');
});
it('should transform :host with attributes and pseudo selectors', () => {
expect(shim(':host [attr] {}', 'contenta', 'hosta')).toEqualCss('[hosta] [attr][contenta] {}');
expect(shim(':host(create-first-project) {}', 'contenta', 'hosta')).toEqualCss(
'create-first-project[hosta] {}',
);
expect(shim(':host[attr] {}', 'contenta', 'hosta')).toEqualCss('[attr][hosta] {}');
expect(shim(':host[attr]:where(:not(.cm-button)) {}', 'contenta', 'hosta')).toEqualCss(
'[hosta][attr]:where(:not(.cm-button)) {}',
);
});
it('should handle escaped sequences in selectors', () => {