MCPcopy Create free account
hub / github.com/angular/angular / shimCssText

Method shimCssText

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

Source from the content-addressed store, hash-verified

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