How to use the scope-analyzer.nearestScope 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 / browser-pack-flat / index.js View on Github external
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,

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