Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function detectSplitRequireCalls (ast, onreference, onrequire) {
scan.crawl(ast)
dash(ast, function (node) {
var binding
if (isRequire(node, 'split-require')) {
if (onrequire) onrequire(node)
if (node.parent.type === 'VariableDeclarator') {
// var sr = require('split-require')
binding = scan.getBinding(node.parent.id)
if (binding) binding.getReferences().slice(1).forEach(onreference)
} else if (node.parent.type === 'AssignmentExpression') {
// sr = require('split-require')
binding = scan.getBinding(node.parent.left)
if (binding) binding.getReferences().slice(1).forEach(onreference)
} else {
// require('split-require')(...args)
onreference(node)
}
if (!meta) meta = unpackJsonpPrelude(ast)
if (!meta) return
var entryId = meta.entryId
var factories = meta.factories
if (!factories.every(isFunctionOrEmpty)) {
return
}
var modules = []
for (var i = 0; i < factories.length; i++) {
var factory = factories[i]
if (factory.factory === null) continue
scan.crawl(factory.factory)
// If source is available, rewrite the require,exports,module var names in place
// Else, generate a string afterwards.
var range = getModuleRange(factory.factory.body)
var moduleSource = rewriteMagicIdentifiers(
factory.factory,
source ? source.slice(range.start, range.end) : null,
range.start
)
if (!moduleSource) {
moduleSource = astring.generate({
type: 'Program',
body: factory.factory.body.body
})
}
var deps = getDependencies(factory.factory)