diff --git a/modules/@angular/compiler/src/shadow_css.ts b/modules/@angular/compiler/src/shadow_css.ts index 9527bacffb..b1052f3edd 100644 --- a/modules/@angular/compiler/src/shadow_css.ts +++ b/modules/@angular/compiler/src/shadow_css.ts @@ -149,9 +149,10 @@ 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); cssText = stripComments(cssText); cssText = this._insertDirectives(cssText); - return this._scopeCssText(cssText, selector, hostSelector); + return this._scopeCssText(cssText, selector, hostSelector) + sourceMappingUrl; } private _insertDirectives(cssText: string): string { @@ -454,12 +455,20 @@ var _polyfillHostRe = new RegExp(_polyfillHost, 'im'); var _colonHostRe = /:host/gim; var _colonHostContextRe = /:host-context/gim; -var _commentRe = /\/\*[\s\S]*?\*\//g; +var _commentRe = /\/\*\s*[\s\S]*?\*\//g; function stripComments(input:string):string { return StringWrapper.replaceAllMapped(input, _commentRe, (_: any /** TODO #9100 */) => ''); } +// all comments except inline source mapping ("/* #sourceMappingURL= ... */") +var _sourceMappingUrlRe = /[\s\S]*(\/\*\s*#\s*sourceMappingURL=[\s\S]+?\*\/)\s*$/; + +function extractSourceMappingUrl(input:string):string { + const matcher = input.match(_sourceMappingUrlRe); + return matcher ? matcher[1] : ''; +} + var _ruleRe = /(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g; var _curlyRe = /([{}])/g; const OPEN_CURLY = '{'; diff --git a/modules/@angular/compiler/test/shadow_css_spec.ts b/modules/@angular/compiler/test/shadow_css_spec.ts index a3a57e5ca4..2055c5346f 100644 --- a/modules/@angular/compiler/test/shadow_css_spec.ts +++ b/modules/@angular/compiler/test/shadow_css_spec.ts @@ -183,6 +183,13 @@ export function main() { it('should support multiline comments', () => { expect(s('/* \n */b {c}', 'a')).toEqual('b[a] {c}'); }); + + it('should keep sourceMappingURL comments', () => { + expect(s('b {c}/*# sourceMappingURL=data:x */', 'a')) + .toEqual('b[a] {c}/*# sourceMappingURL=data:x */'); + expect(s('b {c}/* #sourceMappingURL=data:x */', 'a')) + .toEqual('b[a] {c}/* #sourceMappingURL=data:x */'); + }); }); describe('processRules', () => {