Skip to content

Commit 487b703

Browse files
committed
Fix #13274: Wrap sourceMap directive in multiline comments. Close gh-1143.
(cherry picked from commit ac93559)
1 parent fb0f295 commit 487b703

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Gruntfile.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ module.exports = function( grunt ) {
409409
nonascii = false;
410410

411411
distpaths.forEach(function( filename ) {
412-
var i, c,
412+
var i, c, map,
413413
text = fs.readFileSync( filename, "utf8" );
414414

415415
// Ensure files use only \n for line endings, not \r\n
@@ -438,7 +438,18 @@ module.exports = function( grunt ) {
438438
text = text.replace( /"dist\//g, "\"" );
439439
fs.writeFileSync( filename, text, "utf-8" );
440440
} else if ( /\.min\.js$/.test( filename ) ) {
441-
text = text.replace( /sourceMappingURL=dist\//, "sourceMappingURL=" );
441+
// Wrap sourceMap directive in multiline comments (#13274)
442+
text = text.replace( /\n?(\/\/@\s*sourceMappingURL=)(.*)/,
443+
function( _, directive, path ) {
444+
map = "\n" + directive + path.replace( /^dist\//, "" );
445+
return "";
446+
});
447+
if ( map ) {
448+
text = text.replace( /(^\/\*[\w\W]*?)\s*\*\/|$/,
449+
function( _, comment ) {
450+
return ( comment || "\n/*" ) + map + "\n*/";
451+
});
452+
}
442453
fs.writeFileSync( filename, text, "utf-8" );
443454
}
444455

test/data/core/cc_on.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5+
<script>
6+
var cc_on = false,
7+
errors = [];
8+
/*@cc_on
9+
cc_on = true;
10+
@*/
11+
window.onerror = function( errorMessage, filePath, lineNumber ) {
12+
errors.push( errorMessage );
13+
};
14+
</script>
15+
<script src="../../../dist/jquery.min.js"></script>
16+
</head>
17+
<body>
18+
<script>
19+
window.parent.iframeCallback( cc_on, errors, jQuery );
20+
</script>
21+
</body>
22+
</html>

test/unit/core.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ test("Basic requirements", function() {
1717
ok( $, "$" );
1818
});
1919

20+
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
21+
expect( 3 );
22+
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
23+
deepEqual( errors, [], "No errors" );
24+
ok( $(), "jQuery executes" );
25+
});
26+
2027
test("jQuery()", function() {
2128

2229
var elem, i,

0 commit comments

Comments
 (0)