Permalink
Browse files

fix(bundler): fix compatibility with source-map >= v0.6

Upgrade embedded concat-with-source-maps to latest version.

Close #870
  • Loading branch information...
huochunpeng committed May 18, 2018
1 parent 00ed997 commit 681a77d9f83303d4717c97575c91db0c8e1bc82a
Showing with 28 additions and 19 deletions.
  1. +28 −19 lib/build/concat-with-sourcemaps/index.js
@@ -13,9 +13,9 @@ function Concat(generateSourceMap, fileName, separator) {
this.contentParts = [];
if (separator === undefined) {
this.separator = new Buffer(0);
this.separator = bufferFrom('');
} else {
this.separator = new Buffer(separator);
this.separator = bufferFrom(separator);
}
if (this.sourceMapping) {
@@ -37,18 +37,17 @@ Concat.prototype.add = function(filePath, content, sourceMap) {
filePath = filePath && unixStylePath(filePath);
if (!Buffer.isBuffer(content)) {
content = new Buffer(content);
content = bufferFrom(content);
}
if (this.contentParts.length !== 0) {
this.contentParts.push(this.separator);
}
this.contentParts.push(content);
var contentString = content.toString();
var lines = contentString.split('\n').length;
if (sourceMap && this.sourceMapping) {
if (this.sourceMapping) {
var contentString = content.toString();
var lines = contentString.split('\n').length;
if (Object.prototype.toString.call(sourceMap) === '[object String]')
sourceMap = JSON.parse(sourceMap);
@@ -63,11 +62,11 @@ Concat.prototype.add = function(filePath, content, sourceMap) {
line: _this.lineOffset + mapping.generatedLine,
column: (mapping.generatedLine === 1 ? _this.columnOffset : 0) + mapping.generatedColumn
},
original: {
original: mapping.originalLine == null ? null : {
line: mapping.originalLine,
column: mapping.originalColumn
},
source: mapping.source,
source: mapping.originalLine != null ? mapping.source : null,
name: mapping.name
});
}
@@ -98,16 +97,13 @@ Concat.prototype.add = function(filePath, content, sourceMap) {
this._sourceMap.setSourceContent(filePath, sourceMap.sourcesContent[0]);
}
}
if (lines > 1)
this.columnOffset = 0;
if (this.separatorLineOffset === 0)
this.columnOffset += contentString.length - Math.max(0, contentString.lastIndexOf('\n')+1);
this.columnOffset += this.separatorColumnOffset;
this.lineOffset += lines - 1 + this.separatorLineOffset;
}
if (lines > 1)
this.columnOffset = 0;
if (this.separatorLineOffset === 0)
this.columnOffset += contentString.length - Math.max(0, contentString.lastIndexOf('\n')+1);
this.columnOffset += this.separatorColumnOffset;
this.lineOffset += lines - 1 + this.separatorLineOffset;
};
Object.defineProperty(Concat.prototype, 'content', {
@@ -122,4 +118,17 @@ Object.defineProperty(Concat.prototype, 'sourceMap', {
}
});
module.exports = Concat;
function bufferFrom(content) {
try {
return Buffer.from(content);
} catch(e) {
if (Object.prototype.toString.call(content) !== '[object String]') {
throw new TypeError("separator must be a string");
}
return new Buffer(content);
}
}
Concat.bufferFrom = bufferFrom;
Concat.default = Concat;
module.exports = Concat;

0 comments on commit 681a77d

Please sign in to comment.