How to use the scope-analyzer.getBinding 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
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 / split-require / plugin.js View on Github external
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
function getDependencies (moduleWrapper) {
  var deps = {}
  if (moduleWrapper.params.length < 3) return deps

  var req = scan.getBinding(moduleWrapper.params[2])
  req.getReferences().forEach(function (ref) {
    if (ref.parent.type === 'CallExpression' && ref.parent.callee === ref && ref.parent.arguments[0].type === 'Literal') {
      deps[ref.parent.arguments[0].value] = ref.parent.arguments[0].value
    }
  })

  return deps
}
github goto-bus-stop / browser-pack-flat / index.js View on Github external
function renameImport (row, node, name) {
  if (node.parent.type === 'VariableDeclarator' && node.parent.id.type === 'Identifier') {
    var binding = scan.getBinding(node.parent.id)
    if (binding) {
      renameBinding(binding, name)
      removeVariableDeclarator(row, node.parent)
      return
    }
  }
  node.edit.update(name)
}

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