Skip to content

Commit eb4f1ff

Browse files
authored
Merge pull request requirejs#1582 from requirejs/comment-regexp
Update commentRegExp for better sugared CommonJS syntax dependency parsing
2 parents 393986a + 4c84ff2 commit eb4f1ff

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

require.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var requirejs, require, define;
1212
var req, s, head, baseElement, dataMain, src,
1313
interactiveScript, currentlyAddingScript, mainScript, subPath,
1414
version = '2.2.0',
15-
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
15+
commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/mg,
1616
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
1717
jsSuffixRegExp = /\.js$/,
1818
currDirRegExp = /^\.\//,
@@ -36,7 +36,7 @@ var requirejs, require, define;
3636
useInteractive = false;
3737

3838
//Could match something like ')//comment', do not lose the prefix to comment.
39-
function commentReplace(match, multi, multiText, singlePrefix) {
39+
function commentReplace(match, singlePrefix) {
4040
return singlePrefix || '';
4141
}
4242

tests/remoteUrls/jqwrap.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
define(function (require) {
2-
//Tests detecting a full URL dependency inside simplified wrapper.
2+
//Test a full URL dependency inside simplified wrapper.
33
require('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');
44

5+
//Test protocol relative URL.
6+
require('//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js');
7+
8+
var s = '<img src="//www.example.com/loading.gif"/>'; var util = require('util');
9+
10+
var t = '<img src=//www.example.com/loading.gif/>'; var util2 = require('util2');
11+
12+
//Make sure that this does not match, a string with no semicolon
13+
//after it, but with a line break before a commented out require.
14+
var something = 'something'
15+
//require('bad');
16+
17+
//--------
18+
//This will match if this comment removed to here: var something = 'something'// require('bad');
19+
//--------
20+
521
function noop() {};
622

723
return {
8-
isFunction: jQuery.isFunction(noop)
24+
isFunction: jQuery.isFunction(noop),
25+
swfobject: swfobject,
26+
util: util,
27+
util2: util2
928
};
1029
});

tests/remoteUrls/remoteUrls-tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ require({
88
[
99
function remoteUrls(t){
1010
t.is(true, jqwrap.isFunction);
11+
t.is(true, !!jqwrap.swfobject);
12+
t.is('util', jqwrap.util.name);
13+
t.is('util2', jqwrap.util2.name);
1114
}
1215
]
1316
);

tests/remoteUrls/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'util'
3+
});

tests/remoteUrls/util2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'util2'
3+
});

0 commit comments

Comments
 (0)