Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)) {
exportCache.set(cacheKey, null)
return null
}
// check for and cache ignore
if (isIgnored(path, context)) {
log('ignored path due to ignore settings:', path)
exportCache.set(cacheKey, null)
return null
}
const content = fs.readFileSync(path, { encoding: 'utf8' })
// check for and cache unambigious modules
if (!unambiguous.test(content)) {
log('ignored path due to unambiguous regex:', path)
exportCache.set(cacheKey, null)
return null
}
log('cache miss', cacheKey, 'for path', path)
exportMap = ExportMap.parse(path, content, context)
it('ignores paths with invalid extensions when configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.js', '.jsx', '.ts' ] })
expect(isIgnored('../files/foo.js', testContext)).to.equal(false)
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(false)
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(false)
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})
})
it('ignores paths with extensions other than .js', function () {
const testContext = utils.testContext({})
expect(isIgnored('../files/foo.js', testContext)).to.equal(false)
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(true)
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(true)
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})
it('ignores paths with extensions other than .js', function () {
const testContext = utils.testContext({})
expect(isIgnored('../files/foo.js', testContext)).to.equal(false)
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(true)
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(true)
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})
it('ignores paths with invalid extensions when configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.js', '.jsx', '.ts' ] })
expect(isIgnored('../files/foo.js', testContext)).to.equal(false)
expect(isIgnored('../files/bar.jsx', testContext)).to.equal(false)
expect(isIgnored('../files/typescript.ts', testContext)).to.equal(false)
expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})
})