Permalink
Browse files

commentRegExp faster and matches more

  • Loading branch information...
1 parent e97fe4d commit 4c84ff2875c76d8eb42bbbaa909e9fa4ebdd0ce1 @jrburke jrburke committed Sep 4, 2016
Showing with 32 additions and 4 deletions.
  1. +2 −2 require.js
  2. +21 −2 tests/remoteUrls/jqwrap.js
  3. +3 −0 tests/remoteUrls/remoteUrls-tests.js
  4. +3 −0 tests/remoteUrls/util.js
  5. +3 −0 tests/remoteUrls/util2.js
View
@@ -12,7 +12,7 @@ var requirejs, require, define;
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
version = '2.2.0',
- commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
+ commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
currDirRegExp = /^\.\//,
@@ -36,7 +36,7 @@ var requirejs, require, define;
useInteractive = false;
//Could match something like ')//comment', do not lose the prefix to comment.
- function commentReplace(match, multi, multiText, singlePrefix) {
+ function commentReplace(match, singlePrefix) {
return singlePrefix || '';
}
@@ -1,10 +1,29 @@
define(function (require) {
- //Tests detecting a full URL dependency inside simplified wrapper.
+ //Test a full URL dependency inside simplified wrapper.
require('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');
+ //Test protocol relative URL.
+ require('//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js');
+
+ var s = '<img src="//www.example.com/loading.gif"/>'; var util = require('util');
+
+ var t = '<img src=//www.example.com/loading.gif/>'; var util2 = require('util2');
+
+ //Make sure that this does not match, a string with no semicolon
+ //after it, but with a line break before a commented out require.
+ var something = 'something'
+//require('bad');
+
+ //--------
+ //This will match if this comment removed to here: var something = 'something'// require('bad');
+ //--------
+
function noop() {};
return {
- isFunction: jQuery.isFunction(noop)
+ isFunction: jQuery.isFunction(noop),
+ swfobject: swfobject,
+ util: util,
+ util2: util2
};
});
@@ -8,6 +8,9 @@ require({
[
function remoteUrls(t){
t.is(true, jqwrap.isFunction);
+ t.is(true, !!jqwrap.swfobject);
+ t.is('util', jqwrap.util.name);
+ t.is('util2', jqwrap.util2.name);
}
]
);
@@ -0,0 +1,3 @@
+define({
+ name: 'util'
+});
@@ -0,0 +1,3 @@
+define({
+ name: 'util2'
+});

0 comments on commit 4c84ff2

Please sign in to comment.