Permalink
Browse files

Fix #13274: Wrap sourceMap directive in multiline comments. Close gh-…

…1143.

(cherry picked from commit ac93559)
  • Loading branch information...
gibson042 committed Jan 23, 2013
1 parent fb0f295 commit 487b703521e63188102c73e8ce6ce203d28f260b
Showing with 42 additions and 2 deletions.
  1. +13 −2 Gruntfile.js
  2. +22 −0 test/data/core/cc_on.html
  3. +7 −0 test/unit/core.js
@@ -409,7 +409,7 @@ module.exports = function( grunt ) {
nonascii = false;
distpaths.forEach(function( filename ) {
var i, c,
var i, c, map,
text = fs.readFileSync( filename, "utf8" );
// Ensure files use only \n for line endings, not \r\n
@@ -438,7 +438,18 @@ module.exports = function( grunt ) {
text = text.replace( /"dist\//g, "\"" );
fs.writeFileSync( filename, text, "utf-8" );
} else if ( /\.min\.js$/.test( filename ) ) {
text = text.replace( /sourceMappingURL=dist\//, "sourceMappingURL=" );
// Wrap sourceMap directive in multiline comments (#13274)

This comment has been minimized.

@jdalton

jdalton Jan 25, 2013

Member

Should this be handled in Grunt? /cc @cowboy

This comment has been minimized.

@dmethvin

dmethvin Jan 25, 2013

Member

Uglify2 just got a --source-map-url option to fix the problem with the dist/ appearing in the url there, but it's only half fixed. I think the wrapping in a comment should be handled inside Uglify2 as well since it affects everyone and not just grunt or jQuery users. I opened ticket 108 there. When that gets fixed we'll need to remove our wrap lest we get double-wrapped.

This comment has been minimized.

@jdalton

jdalton Jan 25, 2013

Member

@dmethvin Ah, thanks for that!

This comment has been minimized.

@gibson042

gibson042 Jan 25, 2013

Member

Thanks @dmethvin. We should be safe from double wrapping, but will end up with an empty comment at the end of the file after we use a version of Uglify2 that fixes this (since I move the directive into our existing banner).

This comment has been minimized.

@cowboy

This comment has been minimized.

@gibson042

gibson042 Jan 25, 2013

Member

Actually, the more I think about this, the more I like the idea of managing the source map directive ourselves. Why have two comments in the minified source?

text = text.replace( /\n?(\/\/@\s*sourceMappingURL=)(.*)/,
function( _, directive, path ) {
map = "\n" + directive + path.replace( /^dist\//, "" );
return "";
});
if ( map ) {
text = text.replace( /(^\/\*[\w\W]*?)\s*\*\/|$/,
function( _, comment ) {
return ( comment || "\n/*" ) + map + "\n*/";
});
}
fs.writeFileSync( filename, text, "utf-8" );
}
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
var cc_on = false,
errors = [];
/*@cc_on
cc_on = true;
@*/
window.onerror = function( errorMessage, filePath, lineNumber ) {
errors.push( errorMessage );
};
</script>
<script src="../../../dist/jquery.min.js"></script>
</head>
<body>
<script>
window.parent.iframeCallback( cc_on, errors, jQuery );
</script>
</body>
</html>
@@ -17,6 +17,13 @@ test("Basic requirements", function() {
ok( $, "$" );
});
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
expect( 3 );
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
deepEqual( errors, [], "No errors" );
ok( $(), "jQuery executes" );
});
test("jQuery()", function() {
var elem, i,

0 comments on commit 487b703

Please sign in to comment.