demo/typescript.js
function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
            if (filesByName.contains(fileName)) {
                // We've already looked for this file, use cached result
                return getSourceFileFromCache(fileName, /*useAbsolutePath*/ false);
            }
            var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
            if (filesByName.contains(normalizedAbsolutePath)) {
                var file_1 = getSourceFileFromCache(normalizedAbsolutePath, /*useAbsolutePath*/ true);
                // we don't have resolution for this relative file name but the match was found by absolute file name
                // store resolution for relative name as well
                filesByName.set(fileName, file_1);
                return file_1;
            }
            // We haven't looked for this file, do so now and cache result
            var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) {
                if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
                    fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
                }
                else {
                    fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
                }
            });
            filesByName.set(fileName, file);
            if (file) {
                skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
                // Set the source file for normalized absolute path
                filesByName.set(normalizedAbsolutePath, file);
                var basePath = ts.getDirectoryPath(fileName);
                if (!options.noResolve) {
                    processReferencedFiles(file, basePath);
                }
                // always process imported modules to record module name resolutions
                processImportedModules(file, basePath);
                if (isDefaultLib) {
                    file.isDefaultLib = true;
                    files.unshift(file);
                }
                else {
                    files.push(file);
                }
            }
            return file;
            function getSourceFileFromCache(fileName, useAbsolutePath) {
                var file = filesByName.get(fileName);
                if (file && host.useCaseSensitiveFileNames()) {
                    var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
                    if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) {
                        if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
                            fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
                        }
                        else {
                            fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
                        }
                    }
                }
                return file;
            }
        }
function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
            if (filesByName.contains(fileName)) {
                // We've already looked for this file, use cached result
                return getSourceFileFromCache(fileName, /*useAbsolutePath*/ false);
            }
            var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
            if (filesByName.contains(normalizedAbsolutePath)) {
                var file_1 = getSourceFileFromCache(normalizedAbsolutePath, /*useAbsolutePath*/ true);
                // we don't have resolution for this relative file name but the match was found by absolute file name
                // store resolution for relative name as well
                filesByName.set(fileName, file_1);
                return file_1;
            }
            // We haven't looked for this file, do so now and cache result
            var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) {
                if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
                    fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
                }
                else {
                    fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
                }
            });
            filesByName.set(fileName, file);
            if (file) {
                skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
                // Set the source file for normalized absolute path
                filesByName.set(normalizedAbsolutePath, file);
                var basePath = ts.getDirectoryPath(fileName);
                if (!options.noResolve) {
                    processReferencedFiles(file, basePath);
                }
                // always process imported modules to record module name resolutions
                processImportedModules(file, basePath);
                if (isDefaultLib) {
                    file.isDefaultLib = true;
                    files.unshift(file);
                }
                else {
                    files.push(file);
                }
            }
            return file;
            function getSourceFileFromCache(fileName, useAbsolutePath) {
                var file = filesByName.get(fileName);
                if (file && host.useCaseSensitiveFileNames()) {
                    var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
                    if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) {
                        if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
                            fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
                        }
                        else {
                            fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
                        }
                    }
                }
                return file;
            }
        }
Get source file from normalized fileName