Skip to content

Commit e8577c5

Browse files
committed
Merge pull request #156 from leigeber/master
Resolve multiple sourcemap concatenation
2 parents a1dd214 + e5f6546 commit e8577c5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

tasks/lib/sourcemap.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,11 @@ exports.init = function(grunt) {
136136
// Add the lines of a given file to the sourcemap. If in the file, store a
137137
// prior sourcemap and return src with sourceMappingURL removed.
138138
SourceMapConcatHelper.prototype.addlines = function(src, filename) {
139+
var sourceMapRegEx = /\n\/[*/][@#]\s+sourceMappingURL=((?:(?!\s+\*\/).)*).*/;
139140
var relativeFilename = path.relative(path.dirname(this.dest), filename);
140141
// sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library
141142
relativeFilename = relativeFilename.replace(/\\/g, '/');
142-
if (
143-
/\/\/[@#]\s+sourceMappingURL=(.+)/.test(src) ||
144-
/\/\*#\s+sourceMappingURL=(\S+)\s+\*\//.test(src)
145-
) {
143+
if (sourceMapRegEx.test(src)) {
146144
var sourceMapFile = RegExp.$1;
147145
var sourceMapPath;
148146

@@ -154,7 +152,7 @@ exports.init = function(grunt) {
154152
sourceContent = new Buffer(RegExp.$2, 'base64').toString();
155153
} else {
156154
// If sourceMapPath is relative, expand relative to the file
157-
// refering to it.
155+
// referring to it.
158156
sourceMapPath = path.resolve(path.dirname(filename), sourceMapFile);
159157
sourceContent = grunt.file.read(sourceMapPath);
160158
}
@@ -197,7 +195,7 @@ exports.init = function(grunt) {
197195
}
198196
}
199197
// Remove the old sourceMappingURL.
200-
src = src.replace(/[@#]\s+sourceMappingURL=[^\s]+/, '');
198+
src = src.replace(sourceMapRegEx, '');
201199
} else {
202200
// Otherwise perform a rudimentary tokenization of the source.
203201
this._forEachTokenPosition(src, relativeFilename, this.addMapping);

test/expected/sourcemap3_embed.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)