[Pkg-javascript-commits] [node-deps-sort] 27/79: indexed dedupe test

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 c50399c33518a2e65bd7afc7f8dbe2b64d4f8db0
Author: James Halliday <mail at substack.net>
Date:   Mon Jul 21 07:10:15 2014 -0700

    indexed dedupe test
---
 index.js             | 55 ++++++++++++++++++++++++++--------------------------
 test/dedupe_index.js | 26 ++++++++++++++++++++++---
 2 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/index.js b/index.js
index d0b1dae..e9b520c 100644
--- a/index.js
+++ b/index.js
@@ -4,14 +4,6 @@ var isarray = require('isarray');
 
 module.exports = function (opts) {
     if (!opts) opts = {};
-    var expose = opts.expose || {};
-    if (isarray(expose)) {
-        expose = expose.reduce(function (acc, key) {
-            acc[key] = true;
-            return acc;
-        }, {});
-    }
-    
     var rows = [];
     return through.obj(write, end);
     
@@ -25,6 +17,33 @@ module.exports = function (opts) {
 };
 
 function sorter (rows, tr, opts) {
+    var expose = opts.expose || {};
+    if (isarray(expose)) {
+        expose = expose.reduce(function (acc, key) {
+            acc[key] = true;
+            return acc;
+        }, {});
+    }
+    
+    var dedupeIndex = 0, hashes = {}, hmap = {};
+    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]) {
+                row.dedupe = hashes[h];
+            }
+            else {
+                hashes[h] = true;
+                hmap[h] = ix;
+            }
+        });
+    }
+    
     if (opts.index) {
         var index = {};
         var offset = 0;
@@ -50,25 +69,7 @@ function sorter (rows, tr, opts) {
         });
     }
     else {
-        var dedupeIndex = 0, hashes = {}, hmap = {};
-        rows.forEach(function (row, ix) {
-            if (opts.dedupe) {
-                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]) {
-                    row.dedupe = hashes[h];
-                }
-                else {
-                    hashes[h] = true;
-                    hmap[h] = ix;
-                }
-            }
-            tr.push(row);
-        });
+        rows.forEach(function (row) { tr.push(row) });
     }
     tr.push(null);
 };
diff --git a/test/dedupe_index.js b/test/dedupe_index.js
index cb40393..5efe31d 100644
--- a/test/dedupe_index.js
+++ b/test/dedupe_index.js
@@ -9,9 +9,29 @@ test('dedupe index', function (t) {
     function write (row, enc, next) { rows.push(row); next() }
     function end () {
         t.deepEqual(rows, [
-            { id: 1, deps: {}, source: 'TWO', dedupe: 1 },
-            { id: 2, deps: {}, source: 'TWO', dedupe: 1 },
-            { id: 3, deps: { './foo': 1, './bar': 2 }, source: 'ONE' }
+            {
+                id: '/bar.js',
+                deps: {},
+                source: 'TWO',
+                dedupe: 1,
+                index: 1,
+                indexDeps: {}
+            },
+            {
+                id: '/foo.js',
+                deps: {},
+                source: 'TWO',
+                dedupe: 1,
+                index: 2,
+                indexDeps: {}
+            },
+            {
+                id: '/main.js',
+                deps: { './foo': '/foo.js', './bar': '/bar.js' },
+                source: 'ONE',
+                index: 3,
+                indexDeps: { './foo': 2, './bar': 1 },
+            }
         ]);
     }
     s.pipe(through.obj(write, end));

-- 
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