Previously files were serialized with an extra newline seperator that was not removed when parsing. This caused the parsed file to start with an extra newline that invalidated its source-map. Also, the splitting was producing an empty entry at the start of the extracted golden files which is now ignored. PR Close #39939
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
/**
 | 
						|
 * @license
 | 
						|
 * Copyright Google LLC All Rights Reserved.
 | 
						|
 *
 | 
						|
 * Use of this source code is governed by an MIT-style license that can be
 | 
						|
 * found in the LICENSE file at https://angular.io/license
 | 
						|
 */
 | 
						|
 | 
						|
const headerStart =
 | 
						|
    '/****************************************************************************************************\n' +
 | 
						|
    ' * PARTIAL FILE: ';
 | 
						|
 | 
						|
const headerEnd =
 | 
						|
    '\n ****************************************************************************************************/\n';
 | 
						|
 | 
						|
/**
 | 
						|
 * Render the partially compiled files into a single golden partial output string.
 | 
						|
 *
 | 
						|
 * @param files The partially compiled files to be rendered.
 | 
						|
 */
 | 
						|
export function renderGoldenPartial(files: PartiallyCompiledFile[]): string {
 | 
						|
  return files.map(file => `${headerStart + file.path + headerEnd}${file.content}`).join('\n');
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Parse the `partialContent` into a set of partially compiled files.
 | 
						|
 *
 | 
						|
 * The `partialContent` is a single string that can contains multiple files.
 | 
						|
 * Each file is delimited by a header comment that also contains its original path.
 | 
						|
 *
 | 
						|
 * @param partialContent The partial content to parse.
 | 
						|
 */
 | 
						|
export function parseGoldenPartial(partialContent: string): PartiallyCompiledFile[] {
 | 
						|
  const files: PartiallyCompiledFile[] = [];
 | 
						|
  const partials = partialContent.split(headerStart);
 | 
						|
  for (const partial of partials) {
 | 
						|
    const [path, content] = partial.split(headerEnd);
 | 
						|
    if (path) {
 | 
						|
      files.push({path, content});
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return files;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Represents the path and contents of a partially compiled file.
 | 
						|
 */
 | 
						|
export interface PartiallyCompiledFile {
 | 
						|
  path: string;
 | 
						|
  content: string;
 | 
						|
}
 |