Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
harvest: function harvest (dir) {
const file1 = path.join(__dirname, '../fixture/', dir, '/input.js')
const file2 = path.join(__dirname, '../fixture/', dir, '/harvest.json')
const input = fs.readFileSync(file1, 'utf8')
const expected = JSON.parse(fs.readFileSync(file2, 'utf8'))
const ast = AbstractSyntaxTree.parse(input, { sourceType: 'module' })
const analyzer = new Analyzer(ast)
const harvester = new Importer(ast, { analyzer })
const result = harvester.harvest()
const isValid = JSON.stringify(expected) === JSON.stringify(result)
if (!isValid) {
console.log('-- EXPECTED --')
console.log(JSON.stringify(expected, null, 2))
console.log('-- RESULT --')
console.log(JSON.stringify(result, null, 2))
}
return isValid
}
}
static parse (source, options) {
options.next = true
return AbstractSyntaxTree.parse(source, options)
}