From e37fff744dae73ebdba710e113cf6902d154e93e Mon Sep 17 00:00:00 2001 From: jrburke Date: Wed, 27 Jun 2012 16:49:02 -0700 Subject: [PATCH] Fixes #344, do not find obj.require calls for runtime dependency scanning --- require.js | 2 +- tests/all.js | 1 + tests/cjsSpace/c.js | 9 +++++++++ tests/cjsSpace/cjsDotRequire-tests.js | 18 ++++++++++++++++++ tests/cjsSpace/cjsDotRequire.html | 16 ++++++++++++++++ updatesubs.sh | 2 +- 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/cjsSpace/c.js create mode 100644 tests/cjsSpace/cjsDotRequire-tests.js create mode 100644 tests/cjsSpace/cjsDotRequire.html diff --git a/require.js b/require.js index 214e1340a..8c29bc503 100644 --- a/require.js +++ b/require.js @@ -12,7 +12,7 @@ var requirejs, require, define; var version = '2.0.2+', commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, - cjsRequireRegExp = /require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, + cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, jsSuffixRegExp = /\.js$/, currDirRegExp = /^\.\//, ostring = Object.prototype.toString, diff --git a/tests/all.js b/tests/all.js index 40da2f500..d5c0ffa93 100644 --- a/tests/all.js +++ b/tests/all.js @@ -18,6 +18,7 @@ doh.registerUrl("dataMainBaseUrl", "../dataMain/baseUrl/dataMainBaseUrl.html"); if (hasToString) { doh.registerUrl("anonSimple", "../anon/anonSimple.html"); doh.registerUrl("cjsSpace", "../cjsSpace/cjsSpace.html"); + doh.registerUrl("cjsDotRequire", "../cjsSpace/cjsDotRequire.html"); doh.registerUrl("packages", "../packages/packages.html"); } diff --git a/tests/cjsSpace/c.js b/tests/cjsSpace/c.js new file mode 100644 index 000000000..150dc0f5f --- /dev/null +++ b/tests/cjsSpace/c.js @@ -0,0 +1,9 @@ +define(function (require) { + if (typeof obj !== 'undefined') { + obj.require('bad'); + } + return { + name: 'c' + }; +}); + diff --git a/tests/cjsSpace/cjsDotRequire-tests.js b/tests/cjsSpace/cjsDotRequire-tests.js new file mode 100644 index 000000000..332e0324e --- /dev/null +++ b/tests/cjsSpace/cjsDotRequire-tests.js @@ -0,0 +1,18 @@ +require({ + baseUrl: './' + }, + ['a', 'c'], + function(a, c) { + doh.register( + 'cjsDotRequire', + [ + function cjsDotRequire(t){ + t.is('a', a.name); + t.is('b', a.b.name); + t.is('c', c.name); + } + ] + ); + doh.run(); + } +); diff --git a/tests/cjsSpace/cjsDotRequire.html b/tests/cjsSpace/cjsDotRequire.html new file mode 100644 index 000000000..50d91ec1b --- /dev/null +++ b/tests/cjsSpace/cjsDotRequire.html @@ -0,0 +1,16 @@ + + + + require.js: Skipping false obj.require('') Test + + + + + + +

require.js: Skipping false obj.require('') Test

+

Test for Issue 344. + Make sure modules that have obj.require() calls do not get found as dependencies.

+

Check console for messages

+ + diff --git a/updatesubs.sh b/updatesubs.sh index 46596a8dd..c29258698 100755 --- a/updatesubs.sh +++ b/updatesubs.sh @@ -23,7 +23,7 @@ echo "Updating the cajon project" cp require.js ../cajon/tools/require.js cp ../r.js/r.js ../cajon/tools/r.js cd ../cajon/tools -./build.sh +./build-cajon.sh cd ../../requirejs # The require-cs project