Skip to content

Commit 4c25a42

Browse files
committed
fix(compiler): remove deprecated shadow CSS encapsulation polyfills
Completely remove support for `polyfill-next-selector`, `polyfill-unscoped-rule`, and `polyfill-rule` from `shadow_css.ts`, along with their associated methods and regular expressions. Also delete `polyfills_spec.ts` entirely. (cherry picked from commit 23f0898)
1 parent 8a1533c commit 4c25a42

2 files changed

Lines changed: 0 additions & 135 deletions

File tree

packages/compiler/src/shadow_css.ts

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,12 @@ export class ShadowCss {
192192
return COMMENT_PLACEHOLDER;
193193
});
194194

195-
cssText = this._insertDirectives(cssText);
196195
const scopedCssText = this._scopeCssText(cssText, selector, hostSelector);
197196
// Add back comments at the original position.
198197
let commentIdx = 0;
199198
return scopedCssText.replace(_commentWithHashPlaceHolderRe, () => comments[commentIdx++]);
200199
}
201200

202-
private _insertDirectives(cssText: string): string {
203-
cssText = this._insertPolyfillDirectivesInCssText(cssText);
204-
return this._insertPolyfillRulesInCssText(cssText);
205-
}
206-
207201
/**
208202
* Process styles to add scope to keyframes.
209203
*
@@ -410,48 +404,6 @@ export class ShadowCss {
410404
return {...rule, content};
411405
}
412406

413-
/*
414-
* Process styles to convert native ShadowDOM rules that will trip
415-
* up the css parser; we rely on decorating the stylesheet with inert rules.
416-
*
417-
* For example, we convert this rule:
418-
*
419-
* polyfill-next-selector { content: ':host menu-item'; }
420-
* ::content menu-item {
421-
*
422-
* to this:
423-
*
424-
* scopeName menu-item {
425-
*
426-
**/
427-
private _insertPolyfillDirectivesInCssText(cssText: string): string {
428-
return cssText.replace(_cssContentNextSelectorRe, function (...m: string[]) {
429-
return m[2] + '{';
430-
});
431-
}
432-
433-
/*
434-
* Process styles to add rules which will only apply under the polyfill
435-
*
436-
* For example, we convert this rule:
437-
*
438-
* polyfill-rule {
439-
* content: ':host menu-item';
440-
* ...
441-
* }
442-
*
443-
* to this:
444-
*
445-
* scopeName menu-item {...}
446-
*
447-
**/
448-
private _insertPolyfillRulesInCssText(cssText: string): string {
449-
return cssText.replace(_cssContentRuleRe, (...m: string[]) => {
450-
const rule = m[0].replace(m[1], '').replace(m[2], '');
451-
return m[4] + rule;
452-
});
453-
}
454-
455407
/* Ensure styles are scoped. Pseudo-scoping takes a rule like:
456408
*
457409
* .foo {... }
@@ -461,7 +413,6 @@ export class ShadowCss {
461413
* scopeName .foo { ... }
462414
*/
463415
private _scopeCssText(cssText: string, scopeSelector: string, hostSelector: string): string {
464-
const unscopedRules = this._extractUnscopedRulesFromCssText(cssText);
465416
// replace :host and :host-context with -shadowcsshost and -shadowcsshostcontext respectively
466417
cssText = this._insertPolyfillHostInCssText(cssText);
467418
cssText = this._convertColonHost(cssText);
@@ -471,36 +422,9 @@ export class ShadowCss {
471422
cssText = this._scopeKeyframesRelatedCss(cssText, scopeSelector);
472423
cssText = this._scopeSelectors(cssText, scopeSelector, hostSelector);
473424
}
474-
cssText = cssText + '\n' + unscopedRules;
475425
return cssText.trim();
476426
}
477427

478-
/*
479-
* Process styles to add rules which will only apply under the polyfill
480-
* and do not process via CSSOM. (CSSOM is destructive to rules on rare
481-
* occasions, e.g. -webkit-calc on Safari.)
482-
* For example, we convert this rule:
483-
*
484-
* @polyfill-unscoped-rule {
485-
* content: 'menu-item';
486-
* ... }
487-
*
488-
* to this:
489-
*
490-
* menu-item {...}
491-
*
492-
**/
493-
private _extractUnscopedRulesFromCssText(cssText: string): string {
494-
let r = '';
495-
let m: RegExpExecArray | null;
496-
_cssContentUnscopedRuleRe.lastIndex = 0;
497-
while ((m = _cssContentUnscopedRuleRe.exec(cssText)) !== null) {
498-
const rule = m[0].replace(m[2], '').replace(m[1], m[4]);
499-
r += rule + '\n\n';
500-
}
501-
return r;
502-
}
503-
504428
/*
505429
* convert a rule like :host(.foo) > .bar { }
506430
*
@@ -1062,11 +986,6 @@ class SafeSelector {
1062986

1063987
const _cssScopedPseudoFunctionPrefix = '(:(where|is)\\()?';
1064988
const _cssPrefixWithPseudoSelectorFunction = /:(where|is)\(/gi;
1065-
const _cssContentNextSelectorRe =
1066-
/polyfill-next-selector[^}]*content:[\s]*?(['"])(.*?)\1[;\s]*}([^{]*?){/gim;
1067-
const _cssContentRuleRe = /(polyfill-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
1068-
const _cssContentUnscopedRuleRe =
1069-
/(polyfill-unscoped-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
1070989
const _polyfillHost = '-shadowcsshost';
1071990
// note: :host-context pre-processed to -shadowcsshostcontext.
1072991
const _polyfillHostContext = '-shadowcsscontext';

packages/compiler/test/shadow_css/polyfills_spec.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)