in src/React.Core/Babel.cs [99:146]
public virtual JavaScriptWithSourceMap TransformFileWithSourceMap(
string filename,
bool forceGenerateSourceMap = false
)
{
var cacheKey = string.Format(JSX_CACHE_KEY, filename);
// 1. Check in-memory cache. We need to invalidate any in-memory cache if there's no
// source map cached and forceGenerateSourceMap is true.
var cached = _cache.Get<JavaScriptWithSourceMap>(cacheKey);
var cacheIsValid = cached != null && (!forceGenerateSourceMap || cached.SourceMap != null);
if (cacheIsValid)
{
return cached;
}
// 2. Check on-disk cache
var contents = _fileSystem.ReadAsString(filename);
var hash = _fileCacheHash.CalculateHash(contents);
var output = LoadFromFileCache(filename, hash, forceGenerateSourceMap);
if (output == null)
{
// 3. Not cached, perform the transformation
try
{
output = TransformWithHeader(filename, contents, hash);
}
catch (BabelException ex)
{
// Add the filename to the error message
throw new BabelException(string.Format(
"In file \"{0}\": {1}",
filename,
ex.Message
), ex);
}
}
// Cache the result from above (either disk cache or live transformation) to memory
var fullPath = _fileSystem.MapPath(filename);
_cache.Set(
cacheKey,
output,
slidingExpiration: TimeSpan.FromMinutes(30),
cacheDependencyFiles: new[] { fullPath }
);
return output;
}