Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var requireList = scan.scope(globalScope).getReferences('require')
var moduleExportsList = scan.scope(globalScope).getReferences('module')
.map(function (node) { return node.parent })
.filter(isModuleExports)
var exportsList = scan.scope(globalScope).getReferences('exports')
var moduleList = scan.scope(globalScope).getReferences('module')
.filter(function (node) { return !isModuleExports(node.parent) })
// Detect simple exports that are just `module.exports = xyz`, we can compile them to a single
// variable assignment.
var isSimpleExport = false
if (moduleExportsList.length === 1 && exportsList.length === 0 && moduleList.length === 0) {
var node = moduleExportsList[0]
if (node.parent.type === 'AssignmentExpression' && node.parent.left === node &&
node.parent.parent.type === 'ExpressionStatement') {
isSimpleExport = scan.nearestScope(node.object, false) === ast
var name = getNodeName(node.parent.right)
if (name) {
moduleExportsName = toIdentifier('_$' + name + '_' + row.id)
}
}
}
row[kAst] = ast
row[kIsSimpleExport] = isSimpleExport
row[kExportsName] = moduleExportsName
row.hasExports = (moduleExportsList.length + exportsList.length) > 0
row[kRequireCalls] = requireCalls
row[kDependencyOrder] = orderOfExecution
row[kReferences] = {
require: requireList,