c3-linearization
Advanced tools
Comparing version 0.2.0 to 0.2.1
15
index.js
@@ -43,3 +43,3 @@ "use strict"; | ||
function _linearize(graph, head, results, options) { | ||
function _linearize(graph, head, results, visiting, options) { | ||
if (results.hasOwnProperty(head)) { | ||
@@ -49,2 +49,7 @@ return results[head]; | ||
if (visiting.has(head)) { | ||
throw new Error('circular dependency found'); | ||
} | ||
visiting.add(head); | ||
const parents = graph[head]; | ||
@@ -58,3 +63,3 @@ | ||
let sequences = parents.map(x => _linearize(graph, x, results, options)); | ||
let sequences = parents.map(x => _linearize(graph, x, results, visiting, options)); | ||
@@ -67,2 +72,5 @@ if (options.python === true) { | ||
results[head] = res; | ||
visiting.delete(head); | ||
return res; | ||
@@ -75,6 +83,7 @@ } | ||
const results = {}; | ||
const visiting = new Set(); | ||
const heads = Object.keys(graph); | ||
for (let head of heads) { | ||
_linearize(graph, head, results, options); | ||
_linearize(graph, head, results, visiting, options); | ||
} | ||
@@ -81,0 +90,0 @@ |
{ | ||
"name": "c3-linearization", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A package that implements the C3 linearization algorithm", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -52,2 +52,9 @@ const assert = require('assert'); | ||
it('reports circular dependencies correctly', function () { | ||
assert.throws( | ||
function() { linearize({ a: ['b'], b: ['c'], c: ['b'] }) }, | ||
'circular dependency found' | ||
) | ||
}) | ||
}) |
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
6669
115