Browse Source

Merge pull request #15 from stasm/named-modules-require-other-files

Named modules should be able to require other files
James Burke 11 years ago
parent
commit
97b851a96e
3 changed files with 16 additions and 3 deletions
  1. 1 1
      amdefine.js
  2. 6 2
      tests/named/lib.js
  3. 9 0
      tests/named/other.js

+ 1 - 1
amdefine.js

@@ -152,7 +152,7 @@ function amdefine(module, require) {
                 uri: __filename,
                 exports: e
             };
-            r = makeRequire(undefined, e, m, id);
+            r = makeRequire(require, e, m, id);
         } else {
             //Only support one define call per file
             if (alreadyCalled) {

+ 6 - 2
tests/named/lib.js

@@ -2,12 +2,16 @@ if (typeof define !== 'function') { var define = require('../../amdefine')(modul
 
 define('sub/nested/d', function (require, exports, module) {
     var c = require('../c'),
-        e = require('./e');
+        e = require('./e'),
+        // if sub/nested/other is not defined, look for a file called
+        // other.js in the current directory
+        other = require('./other');
 
     return {
         name: 'd',
         e: e,
-        cName: c.name
+        cName: c.name,
+        otherName: other.name
     };
 });
 

+ 9 - 0
tests/named/other.js

@@ -0,0 +1,9 @@
+if (typeof define !== 'function') { var define = require('../../amdefine')(module) }
+
+define('other', function (require, exports, module) {
+    return {
+        name: 'other'
+    };
+});
+
+module.exports = define.require('other');