Skip to content

Commit

Permalink
Merge pull request #156 from leigeber/master
Browse files Browse the repository at this point in the history
Resolve multiple sourcemap concatenation
  • Loading branch information
shama committed Apr 20, 2016
2 parents a1dd214 + e5f6546 commit e8577c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions tasks/lib/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ exports.init = function(grunt) {
// Add the lines of a given file to the sourcemap. If in the file, store a
// prior sourcemap and return src with sourceMappingURL removed.
SourceMapConcatHelper.prototype.addlines = function(src, filename) {
var sourceMapRegEx = /\n\/[*/][@#]\s+sourceMappingURL=((?:(?!\s+\*\/).)*).*/;
var relativeFilename = path.relative(path.dirname(this.dest), filename);
// sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library
relativeFilename = relativeFilename.replace(/\\/g, '/');
if (
/\/\/[@#]\s+sourceMappingURL=(.+)/.test(src) ||
/\/\*#\s+sourceMappingURL=(\S+)\s+\*\//.test(src)
) {
if (sourceMapRegEx.test(src)) {
var sourceMapFile = RegExp.$1;
var sourceMapPath;

Expand All @@ -154,7 +152,7 @@ exports.init = function(grunt) {
sourceContent = new Buffer(RegExp.$2, 'base64').toString();
} else {
// If sourceMapPath is relative, expand relative to the file
// refering to it.
// referring to it.
sourceMapPath = path.resolve(path.dirname(filename), sourceMapFile);
sourceContent = grunt.file.read(sourceMapPath);
}
Expand Down Expand Up @@ -197,7 +195,7 @@ exports.init = function(grunt) {
}
}
// Remove the old sourceMappingURL.
src = src.replace(/[@#]\s+sourceMappingURL=[^\s]+/, '');
src = src.replace(sourceMapRegEx, '');
} else {
// Otherwise perform a rudimentary tokenization of the source.
this._forEachTokenPosition(src, relativeFilename, this.addMapping);
Expand Down
2 changes: 1 addition & 1 deletion test/expected/sourcemap3_embed.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit e8577c5

@hsingh23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this fixes my problem

Please sign in to comment.