Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ExportMap.for = function (context) {
const { path } = context
const cacheKey = hashObject(context).digest('hex')
let exportMap = exportCache.get(cacheKey)
// return cached ignore
if (exportMap === null) return null
const stats = fs.statSync(path)
if (exportMap != null) {
// date equality check
if (exportMap.mtime - stats.mtime === 0) {
return exportMap
}
// future: check content equality?
}
// check valid extensions first
if (!hasValidExtension(path, context)) {
exports.parse = function parse(content, options) {
options = Object.assign({}, options, parserOptions)
if (!options.filePath) {
throw new Error('no file path provided!')
}
const keyHash = crypto.createHash('sha256')
keyHash.update(content)
hashObject(options, keyHash)
const key = keyHash.digest('hex')
let ast = cache.get(key)
if (ast != null) return ast
const realParser = moduleRequire(options.parser)
ast = realParser.parse(content, options)
cache.set(key, ast)
return ast
}