commonjs-walker
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,3 +5,11 @@ 'use strict'; | ||
// Scenario: | ||
// One day, `to` depends on `from`, | ||
// So we suppose that there is a trace goes back the dependency chain | ||
// from `from` up to `to`: | ||
// ``` | ||
// | ||
// ``` | ||
// @param {Object} from The from node, the spring generations | ||
@@ -13,3 +21,3 @@ // @param {Object} to The node to be tested, the ancestors | ||
circular.trace = function (from, to) { | ||
var trace = [from]; | ||
var trace = [to]; | ||
@@ -25,3 +33,3 @@ if (from === to) { | ||
circular.lookBack = function (from, to, trace) { | ||
trace.push(to); | ||
trace.push(from); | ||
@@ -34,3 +42,3 @@ if (from === to) { | ||
// if meets the end, just pop. | ||
if (!to.dependents || to.dependents.length === 0) { | ||
if (!from.dependencies || from.dependencies.length === 0) { | ||
trace.pop(); | ||
@@ -40,4 +48,4 @@ return null; | ||
var found = to.dependents.some(function (new_to) { | ||
return circular.lookBack(from, new_to, trace); | ||
var found = from.dependencies.some(function (new_from) { | ||
return circular.lookBack(new_from, to, trace); | ||
}); | ||
@@ -44,0 +52,0 @@ |
{ | ||
"name": "commonjs-walker", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Analyzer and tree walker for commonjs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -46,6 +46,6 @@ 'use strict'; | ||
name: 'b', | ||
dependents: [ | ||
dependencies: [ | ||
{ | ||
name: 'c', | ||
dependents: [ | ||
dependencies: [ | ||
{ | ||
@@ -65,3 +65,3 @@ name: 'd' | ||
var result = circular.trace(a, b).map(function (item) { | ||
var result = circular.trace(b, a).map(function (item) { | ||
return item.name; | ||
@@ -68,0 +68,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19316
524