Skip to content
Open
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
4 changes: 3 additions & 1 deletion packages/compiler/src/shadow_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export class ShadowCss {
if (rule.selector[0] !== '@') {
if (rule.isBlock) {
const selectorParts = selector.split(_selectorSplitRe);
const containsDeep = selectorParts.some((part) => _shadowDeepSelectors.test(part));
const containsDeep = selectorParts.some((part) => _shadowDeepSelectorRe.test(part));

selector = this._scopeSelector({
selector,
Expand Down Expand Up @@ -1013,6 +1013,8 @@ const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s,]*)/;
// Support for `>>>`, `deep`, `::ng-deep` is then also deprecated and will be removed in the future.
// see https://github.com/angular/angular/pull/17677
const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)|(?:::ng-deep)/g;
// Non-global copy for `.test()`, which would otherwise carry `lastIndex` over to the next rule.
const _shadowDeepSelectorRe = new RegExp(_shadowDeepSelectors.source);

// Splits the selector into independent parts by `,` (comma) unless comma is within parenthesis,
// for example `:is(.one, two)`. Negative lookup after comma allows not splitting inside nested
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler/test/shadow_css/nesting_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,11 @@ describe('ShadowCss nesting', () => {
'.foo[contenta] .bar { .baz { color: red; } }',
);
});

it('should not let a previous ::ng-deep rule affect the next one', () => {
// An empty rule body leaves nothing to reset the global regex's `lastIndex`.
expect(
shim('.foo ::ng-deep .bar {}\n::ng-deep .baz { .qux { color: red; } }', 'contenta'),
).toEqualCss('.foo[contenta] .bar {} .baz { .qux { color: red; } }');
});
});
Loading