Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix circular dependency issue

  • Loading branch information...
commit 6c6c646d5f06c9ac4c0873142ad83edd61ee65b2 1 parent 1bcdddd
@medikoo authored
View
6 lib/webmake.tpl
@@ -5,7 +5,7 @@
var getModule, getRequire, require;
getModule = (function (wrap) {
return function (scope, tree, path, fullpath) {
- var name, dir, exports = {}, module = { exports: exports }, fn, isDir;
+ var name, dir, exports, module, fn, isDir;
path = path.split(SEPARATOR);
name = path.pop();
if (!name) {
@@ -41,7 +41,9 @@
}
fn = scope[name];
if (!fn) throw new Error("Could not find module '" + fullpath + "'");
- scope[name] = wrap(module);
+ if (fn.hasOwnProperty('module')) return fn.module.exports;
+ exports = {};
+ fn.module = module = { exports: exports };
fn.call(exports, exports, module, getRequire(scope, tree));
return module.exports;
};
View
6 test/__playground/lib/circular-other-foo.js
@@ -0,0 +1,6 @@
+'use strict';
+
+var co = require('./circular-other');
+// co would be broken, but it must not be broken in program.js
+
+exports.dana = 'foo';
View
5 test/__playground/lib/circular-other.js
@@ -0,0 +1,5 @@
+'use strict';
+
+require('./circular-other-foo');
+
+module.exports = 'circTest';
View
2  test/__playground/lib/program.js
@@ -4,6 +4,8 @@ exports.x = require('./x');
exports.y = require('./y.js');
exports.indexed = require('./indexed');
exports.outer = require('../outer');
+require('./circular-other');
+exports.circularOther = require('./circular-other');
exports.outerSubIndex = require('../other/sub/')
exports.pathFile = require('./path');
exports.pathDir = require('./path/');
View
2  test/webmake.js
@@ -51,6 +51,8 @@ module.exports = {
"Require from package that doesn't have main module");
a(program.nodeshim, 'path for web');
+ a(program.circularOther, 'circTest', "Partially broken dependecy test");
+
options.output = output;
return t(input, options)(lock.call(readFile, output, 'utf8'))(
function (content) {
Please sign in to comment.
Something went wrong with that request. Please try again.