fileoverview import * as tsickle from 'tsickle' ; /**
 * Recursively walk the import graph provided by tsickle, populating entries
 * in the result map such that if foo imports bar, foo will appear before bar
 * in the map.
 */ function topologicalSort ( result , current , modulesManifest , visiting ) { const referencedModules = modulesManifest . getReferencedModules ( current ) ; if ( ! referencedModules ) return ; for ( const referencedModule of referencedModules ) { const referencedFileName = modulesManifest . getFileNameFromModule ( referencedModule ) ; if ( ! referencedFileName ) continue ; if ( ! result [ referencedFileName ] ) { if ( visiting [ referencedFileName ] ) { const path = [ current , ... Object . keys ( visiting ) ] . join ( ' ->\n' ) ; throw new Error ( `\n\nCyclical dependency between files:\n${ path }\n` ) ; } visiting [ referencedFileName ] = true ; topologicalSort ( result , referencedFileName , modulesManifest , visiting ) ; delete visiting [ referencedFileName ] ; } } result [ current ] = true ; } /**
 * Create the contents of the .es5.MF file which propagates partial ordering of
 * the import graph to later actions.
 * Each line in the resulting text corresponds with a workspace-relative file
 * path, and the lines are ordered to match the expected load order in a
 * browser.
 */ export function constructManifest ( modulesManifest , host ) { const result = { } ; for ( const file of modulesManifest . fileNames ) { topologicalSort ( result , file , modulesManifest , { } ) ; } return Object . keys ( result ) . map ( fn => host . relativeOutputPath ( fn ) ) . join ( '\n' ) + '\n' ; }