Skip to content

Instantly share code, notes, and snippets.

@thecodedrift
Last active December 26, 2015 09:09
Show Gist options
  • Select an option

  • Save thecodedrift/7126947 to your computer and use it in GitHub Desktop.

Select an option

Save thecodedrift/7126947 to your computer and use it in GitHub Desktop.
diff --git a/src/requirecontext.js b/src/requirecontext.js
index 14accf0..5e8e301 100644
--- a/src/requirecontext.js
+++ b/src/requirecontext.js
@@ -293,12 +293,16 @@ var RequireContext = Fiber.extend(function () {
}
}
if (typeof factory === 'function') {
- factory.apply(module, resolved);
+ result = factory.apply(module, resolved);
+ if (result) {
+ module.exports = result;
+ }
}
else if (typeof factory === 'object') {
module.exports = factory;
}
module.amd = true;
+ module.exec = true;
});
},
@@ -488,6 +492,7 @@ RequireContext.createInlineDefine = function(module, require) {
module.exports = factory;
}
module.amd = true;
+ module.exec = true;
};
define.amd = {};
return define;
diff --git a/src/treerunner.js b/src/treerunner.js
index 14fa3f3..0dda8a7 100644
--- a/src/treerunner.js
+++ b/src/treerunner.js
@@ -216,8 +216,16 @@ var TreeRunner = Fiber.extend(function () {
var node = new TreeNode();
node.data.originalId = requires[i];
root.addChild(node);
- var runner = new TreeRunner(node);
- childRunner(runner);
+
+ if (Executor.getModule(requires[i]) && Executor.getModule(requires[i]).exec) {
+ // we have it
+ childDone();
+ }
+ else {
+ // go get it
+ var runner = new TreeRunner(node);
+ childRunner(runner);
+ }
}
}
});
diff --git a/tests/integration/all.html b/tests/integration/all.html
index 4217c2b..10f2708 100644
--- a/tests/integration/all.html
+++ b/tests/integration/all.html
@@ -40,7 +40,8 @@ governing permissions and limitations under the License.
'./tests/_generic.html?test=plugins',
'./tests/_generic.html?test=relative_196',
'./tests/_generic.html?test=relative_199',
- './tests/_generic.html?test=anon_define_240'
+ './tests/_generic.html?test=anon_define_240',
+ './tests/_generic.html?test=inline_define'
]);
</script>
</body>
diff --git a/tests/integration/tests/inline_define.js b/tests/integration/tests/inline_define.js
new file mode 100644
index 0000000..eed786e
--- /dev/null
+++ b/tests/integration/tests/inline_define.js
@@ -0,0 +1,12 @@
+// verify inline define functionality
+asyncTest("Modules can be defined inline using AMD syntax - AMD", 1, function() {
+ define('one', [], function() {
+ return {
+ two: 2
+ };
+ });
+ require(['one'], function(one) {
+ equal(one.two, 2, 'able to retrieve the value from an inline-defined AMD module');
+ start();
+ });
+});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment