How to use the scope-analyzer.createScope 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
})[0]
    row.source = dedup.source
  }

  var requireCalls = []
  var orderOfExecution = new Map()

  var ast
  // hack to keep track of `module`/`exports` references correctly.
  // in node.js they're defined by a function wrapper, so their scope is
  // one level higher-ish than the module scope. this emulates that.
  var globalScope = {
    type: 'BrowserPackFlatWrapper',
    parent: null
  }
  scan.createScope(globalScope, ['require', 'module', 'exports'])

  var source = row.source

  // Determine if a require() call may not be evaluated according to its linear source position
  // This happens primarily if the call is inside a function, or inside a conditional branch
  function isOrderUnpredictable (node) {
    while ((node = node.parent)) {
      // Special-case for IIFE, behaviour is the same as evaluating inline
      if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
        // (() => {})()
        if (node.parent && node.parent.type === 'CallExpression' && node.parent.callee === node) {
          continue
        }
        // (function(){}).call(null)
        // this form is added by browserify to inject globals
        if (node.parent && node.parent.type === 'MemberExpression' &&

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