Skip to content

Commit de6c644

Browse files
asnowwolfmhevery
authored andcommitted
fix(compiler): Don't strip /*# sourceURL ... */ (#16088)
Currently, `shimCssText` only keep `/*# sourceMappingUrl ... */` comments and strip `/*# sourceURL ... */` comments. So, Chrome can't find the source maps for component style(that's created in new `style` tags) PR Close #16088
1 parent 5423882 commit de6c644

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/compiler/src/shadow_css.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ export class ShadowCss {
146146
* - hostSelector is the attribute added to the host itself.
147147
*/
148148
shimCssText(cssText: string, selector: string, hostSelector: string = ''): string {
149-
const sourceMappingUrl: string = extractSourceMappingUrl(cssText);
149+
const commentsWithHash = extractCommentsWithHash(cssText);
150150
cssText = stripComments(cssText);
151151
cssText = this._insertDirectives(cssText);
152-
return this._scopeCssText(cssText, selector, hostSelector) + sourceMappingUrl;
152+
153+
const scopedCssText = this._scopeCssText(cssText, selector, hostSelector);
154+
return [scopedCssText, ...commentsWithHash].join('\n');
153155
}
154156

155157
private _insertDirectives(cssText: string): string {
@@ -544,12 +546,10 @@ function stripComments(input: string): string {
544546
return input.replace(_commentRe, '');
545547
}
546548

547-
// all comments except inline source mapping
548-
const _sourceMappingUrlRe = /\/\*\s*#\s*sourceMappingURL=[\s\S]+?\*\//;
549+
const _commentWithHashRe = /\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g;
549550

550-
function extractSourceMappingUrl(input: string): string {
551-
const matcher = input.match(_sourceMappingUrlRe);
552-
return matcher ? matcher[0] : '';
551+
function extractCommentsWithHash(input: string): string[] {
552+
return input.match(_commentWithHashRe) || [];
553553
}
554554

555555
const _ruleRe = /(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g;

packages/compiler/test/shadow_css_spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ import {normalizeCSS} from '@angular/platform-browser/testing/src/browser_util';
300300
expect(s('b {c}/* #sourceMappingURL=data:x */', 'contenta'))
301301
.toEqual('b[contenta] {c}/* #sourceMappingURL=data:x */');
302302
});
303+
304+
it('should keep sourceURL comments', () => {
305+
expect(s('/*# sourceMappingURL=data:x */b {c}/*# sourceURL=xxx */', 'contenta'))
306+
.toEqual('b[contenta] {c}/*# sourceMappingURL=data:x *//*# sourceURL=xxx */');
307+
});
303308
});
304309

305310
describe('processRules', () => {

0 commit comments

Comments
 (0)