MCPcopy
hub / github.com/angular/angular / shimCssText

Method shimCssText

packages/compiler/src/shadow_css.ts:175–199  ·  view source on GitHub ↗
(cssText: string, selector: string, hostSelector: string = '')

Source from the content-addressed store, hash-verified

173 * The hostSelector is the attribute added to the host itself.
174 */
175 shimCssText(cssText: string, selector: string, hostSelector: string = ''): string {
176 // **NOTE**: Do not strip comments as this will cause component sourcemaps to break
177 // due to shift in lines.
178
179 // Collect comments and replace them with a placeholder, this is done to avoid complicating
180 // the rule parsing RegExp and keep it safer.
181 const comments: string[] = [];
182 cssText = cssText.replace(_commentRe, (m) => {
183 if (m.match(_commentWithHashRe)) {
184 comments.push(m);
185 } else {
186 // Replace non hash comments with empty lines.
187 // This is done so that we do not leak any sensitive data in comments.
188 const newLinesMatches = m.match(_newLinesRe);
189 comments.push(newLinesMatches?.join('') ?? '');
190 }
191
192 return COMMENT_PLACEHOLDER;
193 });
194
195 const scopedCssText = this._scopeCssText(cssText, selector, hostSelector);
196 // Add back comments at the original position.
197 let commentIdx = 0;
198 return scopedCssText.replace(_commentWithHashPlaceHolderRe, () => comments[commentIdx++]);
199 }
200
201 /**
202 * Process styles to add scope to keyframes.

Callers 3

shimFunction · 0.95
encapsulateStyleFunction · 0.95
compileStylesFunction · 0.80

Calls 5

_scopeCssTextMethod · 0.95
joinMethod · 0.65
replaceMethod · 0.45
matchMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected