Fix bug where an '=' or ',' character right before the require statement breaks loading of module #88

Merged
merged 1 commit into from Mar 8, 2012
View
2 src/inject.coffee
@@ -818,7 +818,7 @@ extractRequires = (file) ->
# collect runtime requirements
reqs = []
file = file.replace(commentRegex, "")
- reqs.push(match[0]) while (match = requireRegex.exec(file))
+ reqs.push(match[0].match(/require.*/)[0]) while (match = requireRegex.exec(file))
@Jakobo
Jakobo Feb 27, 2012

This seems a bit over-greedy. If this works, we should also move the regex up to the top of the file so people can find all the regexes easily for maintenance.

if reqs?.length > 0
try
eval(reqs.join(";"))
View
4 tests/modules-1.0/includes/bugs/bug_require.js
@@ -0,0 +1,4 @@
+var b=require('bug_require_a');
@Jakobo
Jakobo Feb 27, 2012

Thank you for writing a test! I've ran locally and verified that w/o the fix things do indeed break.

+
+exports.foo = "bar";
+ok(true, "bug require loaded");
View
3 tests/modules-1.0/includes/bugs/bug_require_a.js
@@ -0,0 +1,3 @@
+exports.foo = "bar";
+ok(true, "require statement with no space before require should have run");
+start();
View
6 tests/modules-1.0/modules-1.0.js
@@ -62,4 +62,10 @@ asyncTest("#59 require() statements in commented lines should be ignored", 1, fu
asyncTest("#65 circular dependencies should be resolved", 4, function() {
require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/bugs");
require.run("bug_65");
+});
+
+// requiring a module that has commented lines- those lines should not run
+asyncTest("require() statements with no space before them should still run", 2, function() {
+ require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/bugs");
+ require.run("bug_require");
});