build/toposort.js
function visit( node, predecessors ) {
                //check if a node is dependent of itself
                if( predecessors.length !== 0 && predecessors.indexOf( node ) !== -1 ) {
                    throw new Error( "Cyclic dependency found. " + node + " is dependent of itself.\nDependency chain: "
                                     + predecessors.join( " -> " ) + " => " + node );
                }

                var index = nodes.indexOf( node );

                //if the node still exists, traverse its dependencies
                if( index !== -1 ) {
                    var copy = false;

                    //mark the node as false to exclude it from future iterations
                    nodes[index] = false;

                    //loop through all edges and follow dependencies of the current node
                    for( var _iterator4 = _this.edges, _isArray4 = Array.isArray( _iterator4 ), _i4 = 0, _iterator4 = _isArray4 ?
                                                                                                                      _iterator4 :
                                                                                                                      _iterator4[Symbol.iterator](); ; ) {
                        var _ref4;

                        if( _isArray4 ) {
                            if( _i4 >= _iterator4.length ) {
                                break;
                            }
                            _ref4 = _iterator4[_i4++];
                        } else {
                            _i4 = _iterator4.next();
                            if( _i4.done ) {
                                break;
                            }
                            _ref4 = _i4.value;
                        }

                        var edge = _ref4;

                        if( edge[0] === node ) {
                            //lazily create a copy of predecessors with the current node concatenated onto it
                            copy = copy || predecessors.concat( [node] );

                            //recurse to node dependencies
                            visit( edge[1], copy );
                        }
                    }

                    //add the node to the next place in the sorted array
                    sorted[--place] = node;
                }
            }
function visit( node, predecessors ) {
                //check if a node is dependent of itself
                if( predecessors.length !== 0 && predecessors.indexOf( node ) !== -1 ) {
                    throw new Error( "Cyclic dependency found. " + node + " is dependent of itself.\nDependency chain: "
                                     + predecessors.join( " -> " ) + " => " + node );
                }

                var index = nodes.indexOf( node );

                //if the node still exists, traverse its dependencies
                if( index !== -1 ) {
                    var copy = false;

                    //mark the node as false to exclude it from future iterations
                    nodes[index] = false;

                    //loop through all edges and follow dependencies of the current node
                    for( var _iterator4 = _this.edges, _isArray4 = Array.isArray( _iterator4 ), _i4 = 0, _iterator4 = _isArray4 ?
                                                                                                                      _iterator4 :
                                                                                                                      _iterator4[Symbol.iterator](); ; ) {
                        var _ref4;

                        if( _isArray4 ) {
                            if( _i4 >= _iterator4.length ) {
                                break;
                            }
                            _ref4 = _iterator4[_i4++];
                        } else {
                            _i4 = _iterator4.next();
                            if( _i4.done ) {
                                break;
                            }
                            _ref4 = _i4.value;
                        }

                        var edge = _ref4;

                        if( edge[0] === node ) {
                            //lazily create a copy of predecessors with the current node concatenated onto it
                            copy = copy || predecessors.concat( [node] );

                            //recurse to node dependencies
                            visit( edge[1], copy );
                        }
                    }

                    //add the node to the next place in the sorted array
                    sorted[--place] = node;
                }
            }
function visit ( node , predecessors ) { //check if a node is dependent of itself if ( predecessors . length !== 0 && predecessors . indexOf ( node ) !== - 1 ) { throw new Error ( "Cyclic dependency found. " + node + " is dependent of itself.\nDependency chain: " + predecessors . join ( " -> " ) + " => " + node ) ; } var index = nodes . indexOf ( node ) ; //if the node still exists, traverse its dependencies if ( index !== - 1 ) { var copy = false ; //mark the node as false to exclude it from future iterations nodes [ index ] = false ; //loop through all edges and follow dependencies of the current node for ( var _iterator4 = _this . edges , _isArray4 = Array . isArray ( _iterator4 ) , _i4 = 0 , _iterator4 = _isArray4 ? _iterator4 : _iterator4 [ Symbol . iterator ] ( ) ; ; ) { var _ref4 ; if ( _isArray4 ) { if ( _i4 >= _iterator4 . length ) { break ; } _ref4 = _iterator4 [ _i4 ++ ] ; } else { _i4 = _iterator4 . next ( ) ; if ( _i4 . done ) { break ; } _ref4 = _i4 . value ; } var edge = _ref4 ; if ( edge [ 0 ] === node ) { //lazily create a copy of predecessors with the current node concatenated onto it copy = copy || predecessors . concat ( [ node ] ) ; //recurse to node dependencies visit ( edge [ 1 ] , copy ) ; } } //add the node to the next place in the sorted array sorted [ -- place ] = node ; } }
define a visitor function that recursively traverses dependencies.
define a visitor function that recursively traverses dependencies .