index.js
function detectCycles (rows) {
  var cyclicalModules = new Set()
  var checked = new Set()
  rows.forEach(function (module) {
    var visited = []

    check(module)

    function check (row) {
      var i = visited.indexOf(row)
      if (i !== -1) {
        checked.add(row)
        for (; i < visited.length; i++) {
          cyclicalModules.add(visited[i])
        }
        return
      }
      if (checked.has(row)) return
      visited.push(row)
      Object.keys(row.deps).forEach(function (k) {
        var dep = row.deps[k]
        var other = rows.byId[dep]
        if (other) check(other, visited)
      })
      visited.pop()
    }
  })

  // mark cyclical dependencies
  for (var i = 0; i < rows.length; i++) {
    rows[i][kEvaluateOnDemand] = cyclicalModules.has(rows[i])
  }
  return cyclicalModules.size > 0
}
function detectCycles (rows) {
  var cyclicalModules = new Set()
  var checked = new Set()
  rows.forEach(function (module) {
    var visited = []

    check(module)

    function check (row) {
      var i = visited.indexOf(row)
      if (i !== -1) {
        checked.add(row)
        for (; i < visited.length; i++) {
          cyclicalModules.add(visited[i])
        }
        return
      }
      if (checked.has(row)) return
      visited.push(row)
      Object.keys(row.deps).forEach(function (k) {
        var dep = row.deps[k]
        var other = rows.byId[dep]
        if (other) check(other, visited)
      })
      visited.pop()
    }
  })

  // mark cyclical dependencies
  for (var i = 0; i < rows.length; i++) {
    rows[i][kEvaluateOnDemand] = cyclicalModules.has(rows[i])
  }
  return cyclicalModules.size > 0
}
function detectCycles ( rows ) { var cyclicalModules = new Set ( ) var checked = new Set ( ) rows . forEach ( function ( module ) { var visited = [ ] check ( module ) function check ( row ) { var i = visited . indexOf ( row ) if ( i !== - 1 ) { checked . add ( row ) for ( ; i < visited . length ; i ++ ) { cyclicalModules . add ( visited [ i ] ) } return } if ( checked . has ( row ) ) return visited . push ( row ) Object . keys ( row . deps ) . forEach ( function ( k ) { var dep = row . deps [ k ] var other = rows . byId [ dep ] if ( other ) check ( other , visited ) } ) visited . pop ( ) } } ) // mark cyclical dependencies for ( var i = 0 ; i < rows . length ; i ++ ) { rows [ i ] [ kEvaluateOnDemand ] = cyclicalModules . has ( rows [ i ] ) } return cyclicalModules . size > 0 }
Detect cyclical dependencies in the bundle. All modules in a dependency cycle
are moved to the top of the bundle and wrapped in functions so they're not
evaluated immediately. When other modules need a module that's in a dependency
cycle, instead of using the module's exportName, it'll call the `createModuleFactory` runtime
function, which will execute the requested module and return its exports.
Detect cyclical dependencies in the bundle . All modules in a dependency cycle are moved to the top of the bundle and wrapped in functions so they re not evaluated immediately . When other modules need a module that s in a dependency cycle instead of using the module s exportName it ll call the createModuleFactory runtime function which will execute the requested module and return its exports .