import { SourceMap , MappedPosition , ISourcePathDetails } from './sourceMap' ; import { SourceMapFactory } from './sourceMapFactory' ; import { ISourceMapPathOverrides , IPathMapping } from '../debugAdapterInterfaces' ; export class SourceMaps { private _generatedPathToSourceMap = new Map < string , SourceMap > ( ) ; private _authoredPathToSourceMap = new Map < string , SourceMap > ( ) ; private _sourceMapFactory : SourceMapFactory ; public constructor ( pathMapping ? , sourceMapPathOverrides ? , enableSourceMapCaching ? ) { this . _sourceMapFactory = new SourceMapFactory ( pathMapping , sourceMapPathOverrides , enableSourceMapCaching ) ; } param pathToSource public getGeneratedPathFromAuthoredPath ( authoredPath ) { authoredPath = authoredPath . toLowerCase ( ) ; return this . _authoredPathToSourceMap . has ( authoredPath ) ? this . _authoredPathToSourceMap . get ( authoredPath ) . generatedPath ( ) : null ; } public mapToGenerated ( authoredPath , line , column ) { authoredPath = authoredPath . toLowerCase ( ) ; return this . _authoredPathToSourceMap . has ( authoredPath ) ? this . _authoredPathToSourceMap . get ( authoredPath ) . generatedPositionFor ( authoredPath , line , column ) : null ; } public mapToAuthored ( pathToGenerated , line , column ) { pathToGenerated = pathToGenerated . toLowerCase ( ) ; return this . _generatedPathToSourceMap . has ( pathToGenerated ) ? this . _generatedPathToSourceMap . get ( pathToGenerated ) . authoredPositionFor ( line , column ) : null ; } public allMappedSources ( pathToGenerated ) { pathToGenerated = pathToGenerated . toLowerCase ( ) ; return this . _generatedPathToSourceMap . has ( pathToGenerated ) ? this . _generatedPathToSourceMap . get ( pathToGenerated ) . authoredSources : null ; } public allSourcePathDetails ( pathToGenerated ) { pathToGenerated = pathToGenerated . toLowerCase ( ) ; return this . _generatedPathToSourceMap . has ( pathToGenerated ) ? this . _generatedPathToSourceMap . get ( pathToGenerated ) . allSourcePathDetails : null ; } public sourceContentFor ( authoredPath ) { authoredPath = authoredPath . toLowerCase ( ) ; return this . _authoredPathToSourceMap . has ( authoredPath ) ? this . _authoredPathToSourceMap . get ( authoredPath ) . sourceContentFor ( authoredPath ) : null ; } /**
     * Given a new path to a new script file, finds and loads the sourcemap for that file
     */ public async processNewSourceMap ( pathToGenerated , originalUrlToGenerated , sourceMapURL , isVSClient = false ) { const sourceMap = await this . _sourceMapFactory . getMapForGeneratedPath ( pathToGenerated , originalUrlToGenerated , sourceMapURL , isVSClient ) ; if ( sourceMap ) { this . _generatedPathToSourceMap . set ( pathToGenerated . toLowerCase ( ) , sourceMap ) ; sourceMap . authoredSources . forEach ( authoredSource => this . _authoredPathToSourceMap . set ( authoredSource . toLowerCase ( ) , sourceMap ) ) ; } } }