How to use the scope-analyzer.crawl function in scope-analyzer

To help you get started, we’ve selected a few scope-analyzer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github goto-bus-stop / split-require / plugin.js View on Github external
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)
      }
github goto-bus-stop / webpack-unpack / index.js View on Github external
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)

scope-analyzer

simple scope analysis for javascript ASTs

Apache-2.0
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis