Skip to content

Commit

Permalink
commentRegExp faster and matches more
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Sep 4, 2016
1 parent e97fe4d commit 4c84ff2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions require.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^\.\//,
Expand All @@ -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 || '';
}

Expand Down
23 changes: 21 additions & 2 deletions tests/remoteUrls/jqwrap.js
Original file line number Diff line number Diff line change
@@ -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
};
});
3 changes: 3 additions & 0 deletions tests/remoteUrls/remoteUrls-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
]
);
Expand Down
3 changes: 3 additions & 0 deletions tests/remoteUrls/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define({
name: 'util'
});
3 changes: 3 additions & 0 deletions tests/remoteUrls/util2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define({
name: 'util2'
});

0 comments on commit 4c84ff2

Please sign in to comment.