| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 552d2be commit 28f0693
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,15 +46,17 @@ function stat(filename) { | |||
| 46 | 46 | } | |
| 47 | 47 | stat.cache = null; | |
| 48 | 48 | ||
| 49 | + function updateChildren(parent, child, scan) { | ||
| 50 | + var children = parent && parent.children; | ||
| 51 | + if (children && !(scan && children.includes(child))) | ||
| 52 | + children.push(child); | ||
| 53 | + } | ||
| 49 | 54 | ||
| 50 | 55 | function Module(id, parent) { | |
| 51 | 56 | this.id = id; | |
| 52 | 57 | this.exports = {}; | |
| 53 | 58 | this.parent = parent; | |
| 54 | - if (parent && parent.children) { | ||
| 55 | - parent.children.push(this); | ||
| 56 | - } | ||
| 57 | - | ||
| 59 | + updateChildren(parent, this, false); | ||
| 58 | 60 | this.filename = null; | |
| 59 | 61 | this.loaded = false; | |
| 60 | 62 | this.children = []; | |
@@ -438,6 +440,7 @@ Module._load = function(request, parent, isMain) { | |||
| 438 | 440 | ||
| 439 | 441 | var cachedModule = Module._cache[filename]; | |
| 440 | 442 | if (cachedModule) { | |
| 443 | + updateChildren(parent, cachedModule, true); | ||
| 441 | 444 | return cachedModule.exports; | |
| 442 | 445 | } | |
| 443 | 446 | ||
@@ -446,6 +449,7 @@ Module._load = function(request, parent, isMain) { | |||
| 446 | 449 | return NativeModule.require(filename); | |
| 447 | 450 | } | |
| 448 | 451 | ||
| 452 | + // Don't call updateChildren(), Module constructor already does. | ||
| 449 | 453 | var module = new Module(filename, parent); | |
| 450 | 454 | ||
| 451 | 455 | if (isMain) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('sys'); // Builtin should not show up in module.children array. | ||
| 3 | + require('./b'); // This should. | ||
| 4 | + require('./b'); // This should not. | ||
| 5 | + module.exports = module.children.slice(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + module.exports = module.children.slice(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,13 @@ | |||
| 1 | + // Flags: --no-deprecation | ||
| 2 | + 'use strict'; | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const path = require('path'); | ||
| 6 | + | ||
| 7 | + const dir = path.join(common.fixturesDir, 'GH-7131'); | ||
| 8 | + const b = require(path.join(dir, 'b')); | ||
| 9 | + const a = require(path.join(dir, 'a')); | ||
| 10 | + | ||
| 11 | + assert.strictEqual(a.length, 1); | ||
| 12 | + assert.strictEqual(b.length, 0); | ||
| 13 | + assert.deepStrictEqual(a[0].exports, b); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -237,7 +237,10 @@ try { | |||
| 237 | 237 | // modules that we've required, and that all of them contain | |
| 238 | 238 | // the appropriate children, and so on. | |
| 239 | 239 | ||
| 240 | + const visited = new Set(); | ||
| 240 | 241 | const children = module.children.reduce(function red(set, child) { | |
| 242 | + if (visited.has(child)) return set; | ||
| 243 | + visited.add(child); | ||
| 241 | 244 | let id = path.relative(path.dirname(__dirname), child.id); | |
| 242 | 245 | id = id.replace(backslash, '/'); | |
| 243 | 246 | set[id] = child.children.reduce(red, {}); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments