[Pkg-javascript-commits] [node-deps-sort] 28/79: dedupe/dedupeIndex

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:41:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-deps-sort.

commit 38aabf7d72334b3c99bf62730f10fea7a6510e98
Author: James Halliday <mail at substack.net>
Date:   Mon Jul 21 07:15:46 2014 -0700

    dedupe/dedupeIndex
---
 index.js             | 15 ++++++---------
 test/dedupe.js       |  4 ++--
 test/dedupe_index.js |  6 +++---
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/index.js b/index.js
index e9b520c..6889ec4 100644
--- a/index.js
+++ b/index.js
@@ -25,21 +25,15 @@ function sorter (rows, tr, opts) {
         }, {});
     }
     
-    var dedupeIndex = 0, hashes = {}, hmap = {};
+    var hashes = {};
     if (opts.dedupe) {
         rows.forEach(function (row, ix) {
             var h = shasum(row.source);
-            if (hashes[h] === true) {
-                hashes[h] = ++ dedupeIndex;
-                rows[hmap[h]].dedupe = hashes[h];
-                row.dedupe = hashes[h];
-            }
-            else if (hashes[h]) {
+            if (hashes[h]) {
                 row.dedupe = hashes[h];
             }
             else {
-                hashes[h] = true;
-                hmap[h] = ix;
+                hashes[h] = row.id;
             }
         });
     }
@@ -65,6 +59,9 @@ function sorter (rows, tr, opts) {
             Object.keys(row.deps).forEach(function (key) {
                 row.indexDeps[key] = index[row.deps[key]];
             });
+            if (row.dedupe) {
+                row.dedupeIndex = index[row.dedupe];
+            }
             tr.push(row);
         });
     }
diff --git a/test/dedupe.js b/test/dedupe.js
index 7d68906..f9933bd 100644
--- a/test/dedupe.js
+++ b/test/dedupe.js
@@ -9,8 +9,8 @@ test('dedupe', function (t) {
     function write (row, enc, next) { rows.push(row); next() }
     function end () {
         t.deepEqual(rows, [
-            { id: '/bar.js', deps: {}, source: 'TWO', dedupe: 1 },
-            { id: '/foo.js', deps: {}, source: 'TWO', dedupe: 1 },
+            { id: '/bar.js', deps: {}, source: 'TWO' },
+            { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js' },
             { id: '/main.js', deps: {
                 './foo': '/foo.js',
                 './bar': '/bar.js'
diff --git a/test/dedupe_index.js b/test/dedupe_index.js
index 5efe31d..fb6348a 100644
--- a/test/dedupe_index.js
+++ b/test/dedupe_index.js
@@ -13,7 +13,6 @@ test('dedupe index', function (t) {
                 id: '/bar.js',
                 deps: {},
                 source: 'TWO',
-                dedupe: 1,
                 index: 1,
                 indexDeps: {}
             },
@@ -21,9 +20,10 @@ test('dedupe index', function (t) {
                 id: '/foo.js',
                 deps: {},
                 source: 'TWO',
-                dedupe: 1,
+                dedupe: '/bar.js',
                 index: 2,
-                indexDeps: {}
+                indexDeps: {},
+                dedupeIndex: 1
             },
             {
                 id: '/main.js',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-deps-sort.git



More information about the Pkg-javascript-commits mailing list