Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)) {
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)
it('assumes only .js as valid by default', function () {
const testContext = utils.testContext({})
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.jsx', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.css', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.invalid.extension', testContext)).to.equal(false)
})
it('assumes only .js as valid by default', function () {
const testContext = utils.testContext({})
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.jsx', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.css', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.invalid.extension', testContext)).to.equal(false)
})
it('assumes only .js as valid by default', function () {
const testContext = utils.testContext({})
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.jsx', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.css', testContext)).to.equal(false)
expect(hasValidExtension('../files/foo.invalid.extension', testContext)).to.equal(false)
})
it('can be configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.foo', '.bar' ] })
expect(hasValidExtension('../files/foo.foo', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.bar', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(false)
})
})
it('can be configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.foo', '.bar' ] })
expect(hasValidExtension('../files/foo.foo', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.bar', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(false)
})
})
it('can be configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.foo', '.bar' ] })
expect(hasValidExtension('../files/foo.foo', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.bar', testContext)).to.equal(true)
expect(hasValidExtension('../files/foo.js', testContext)).to.equal(false)
})
})