diff --git a/packages/compiler/src/shadow_css.ts b/packages/compiler/src/shadow_css.ts index cadfaf55e85..93c174b5e6b 100644 --- a/packages/compiler/src/shadow_css.ts +++ b/packages/compiler/src/shadow_css.ts @@ -186,7 +186,7 @@ export class ShadowCss { // Replace non hash comments with empty lines. // This is done so that we do not leak any sensitive data in comments. const newLinesMatches = m.match(_newLinesRe); - comments.push((newLinesMatches?.join('') ?? '') + '\n'); + comments.push(newLinesMatches?.join('') ?? ''); } return COMMENT_PLACEHOLDER; diff --git a/packages/compiler/test/shadow_css/shadow_css_spec.ts b/packages/compiler/test/shadow_css/shadow_css_spec.ts index 89b1a74efda..d9c2893c3bb 100644 --- a/packages/compiler/test/shadow_css/shadow_css_spec.ts +++ b/packages/compiler/test/shadow_css/shadow_css_spec.ts @@ -368,17 +368,17 @@ describe('ShadowCss', () => { describe('comments', () => { // Comments should be kept in the same position as otherwise inline sourcemaps break due to // shift in lines. - it('should replace multiline comments with newline', () => { - expect(shim('/* b {c} */ b {c}', 'contenta')).toBe('\n b[contenta] {c}'); + it('should remove inline comments without adding extra lines', () => { + expect(shim('/* b {c} */ b {c}', 'contenta')).toBe(' b[contenta] {c}'); }); - it('should replace multiline comments with newline in the original position', () => { - expect(shim('/* b {c}\n */ b {c}', 'contenta')).toBe('\n\n b[contenta] {c}'); + it('should preserve internal newlines from multiline comments', () => { + expect(shim('/* b {c}\n */ b {c}', 'contenta')).toBe('\n b[contenta] {c}'); }); - it('should replace comments with newline in the original position', () => { + it('should remove multiple inline comments without adding extra lines', () => { expect(shim('/* b {c} */ b {c} /* a {c} */ a {c}', 'contenta')).toBe( - '\n b[contenta] {c} \n a[contenta] {c}', + ' b[contenta] {c} a[contenta] {c}', ); }); @@ -392,9 +392,7 @@ describe('ShadowCss', () => { }); it('should handle adjacent comments', () => { - expect(shim('/* comment 1 */ /* comment 2 */ b {c}', 'contenta')).toBe( - '\n \n b[contenta] {c}', - ); + expect(shim('/* comment 1 */ /* comment 2 */ b {c}', 'contenta')).toBe(' b[contenta] {c}'); }); }); });