protected virtual JavaScriptWithSourceMap LoadFromFileCache()

in src/React.Core/Babel.cs [158:207]


		protected virtual JavaScriptWithSourceMap LoadFromFileCache(string filename, string hash, bool forceGenerateSourceMap)
		{
			var cacheFilename = GetOutputPath(filename);
			if (!_fileSystem.FileExists(cacheFilename))
			{
				// Cache file doesn't exist on disk
				return null;
			}
			var cacheContents = _fileSystem.ReadAsString(cacheFilename);
			if (!_fileCacheHash.ValidateHash(cacheContents, hash))
			{
				// Hash of the cache is invalid (file changed since the time the cache was written).
				return null;
			}
				
			// Cache is valid :D
			// See if we have a source map cached alongside the file
			SourceMap sourceMap = null;
			var sourceMapFilename = GetSourceMapOutputPath(filename);
			if (_fileSystem.FileExists(sourceMapFilename))
			{
				try
				{
					var sourceMapString = _fileSystem.ReadAsString(sourceMapFilename);
					if (!string.IsNullOrEmpty(sourceMapString))
					{
						sourceMap = SourceMap.FromJson(sourceMapString);
					}
				}
				catch (Exception e)
				{
					// Just ignore it
					Trace.WriteLine("Error reading source map file: " + e.Message);
				}
			}
			
			// If forceGenerateSourceMap is true, we need to explicitly ignore this cached version
			// if there's no source map
			if (forceGenerateSourceMap && sourceMap == null)
			{
				return null;
			}

			return new JavaScriptWithSourceMap
			{
				Code = cacheContents,
				SourceMap = sourceMap,
				Hash = hash,
			};
		}