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
This commit is contained in:
Zhicheng Wang 2017-04-18 22:11:33 +08:00 committed by Miško Hevery
parent c7c5214029
commit 5f681f9745
2 changed files with 12 additions and 7 deletions

View File

@ -146,10 +146,12 @@ export class ShadowCss {
* - hostSelector is the attribute added to the host itself.
*/
shimCssText(cssText: string, selector: string, hostSelector: string = ''): string {
const sourceMappingUrl: string = extractSourceMappingUrl(cssText);
const commentsWithHash = extractCommentsWithHash(cssText);
cssText = stripComments(cssText);
cssText = this._insertDirectives(cssText);
return this._scopeCssText(cssText, selector, hostSelector) + sourceMappingUrl;
const scopedCssText = this._scopeCssText(cssText, selector, hostSelector);
return [scopedCssText, ...commentsWithHash].join('\n');
}
private _insertDirectives(cssText: string): string {
@ -544,12 +546,10 @@ function stripComments(input: string): string {
return input.replace(_commentRe, '');
}
// all comments except inline source mapping
const _sourceMappingUrlRe = /\/\*\s*#\s*sourceMappingURL=[\s\S]+?\*\//;
const _commentWithHashRe = /\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g;
function extractSourceMappingUrl(input: string): string {
const matcher = input.match(_sourceMappingUrlRe);
return matcher ? matcher[0] : '';
function extractCommentsWithHash(input: string): string[] {
return input.match(_commentWithHashRe) || [];
}
const _ruleRe = /(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g;

View File

@ -300,6 +300,11 @@ import {normalizeCSS} from '@angular/platform-browser/testing/src/browser_util';
expect(s('b {c}/* #sourceMappingURL=data:x */', 'contenta'))
.toEqual('b[contenta] {c}/* #sourceMappingURL=data:x */');
});
it('should keep sourceURL comments', () => {
expect(s('/*# sourceMappingURL=data:x */b {c}/*# sourceURL=xxx */', 'contenta'))
.toEqual('b[contenta] {c}/*# sourceMappingURL=data:x *//*# sourceURL=xxx */');
});
});
describe('processRules', () => {