-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
187 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var combineSourceMap = require("combine-source-map"); | ||
var convertSourceMap = require("convert-source-map"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var SourceMap = (function () { | ||
function SourceMap(config) { | ||
this.config = config; | ||
this.line = 0; | ||
} | ||
SourceMap.prototype.initialize = function (bundle) { | ||
this.combiner = combineSourceMap.create(); | ||
this.line = this.getNumberOfNewlines(bundle); | ||
}; | ||
SourceMap.prototype.createInlineSourceMap = function (queued) { | ||
var inlined = queued.emitOutput.outputText; | ||
if (queued.emitOutput.sourceMapText) { | ||
var map = convertSourceMap | ||
.fromJSON(queued.emitOutput.sourceMapText) | ||
.addProperty("sourcesContent", [queued.emitOutput.sourceFile.text]); | ||
inlined = combineSourceMap.removeComments(queued.emitOutput.outputText) + map.toComment(); | ||
// used by Karma to log errors with original source code line numbers | ||
queued.file.sourceMap = map.toObject(); | ||
} | ||
return inlined; | ||
}; | ||
SourceMap.prototype.addFile = function (bundleItem) { | ||
if (this.config.bundlerOptions.sourceMap) { | ||
this.loadFileFromComment(bundleItem); | ||
var sourceFile = path.relative(this.config.karma.basePath, bundleItem.filename); | ||
this.combiner.addFile({ sourceFile: path.join("/base", sourceFile), source: bundleItem.source }, { line: this.line }); | ||
} | ||
bundleItem.source = combineSourceMap.removeComments(bundleItem.source); | ||
}; | ||
SourceMap.prototype.offsetLineNumber = function (wrappedSource) { | ||
if (this.config.bundlerOptions.sourceMap) { | ||
this.line += this.getNumberOfNewlines(wrappedSource); | ||
} | ||
}; | ||
SourceMap.prototype.getComment = function () { | ||
return this.config.bundlerOptions.sourceMap ? this.combiner.comment() : ""; | ||
}; | ||
SourceMap.prototype.loadFileFromComment = function (bundleItem) { | ||
var commentMatch = convertSourceMap.mapFileCommentRegex.exec(bundleItem.source); | ||
if (commentMatch && !commentMatch[1].startsWith("data:")) { | ||
var dirname_1 = path.dirname(bundleItem.filename); | ||
var mapFilename = path.join(dirname_1, commentMatch[1]); | ||
var mapJson = fs.readFileSync(mapFilename, "utf-8"); | ||
var map = convertSourceMap.fromJSON(mapJson); | ||
if (!map.getProperty("sourcesContent")) { | ||
var sourcesContent_1 = []; | ||
map.getProperty("sources").forEach(function (source) { | ||
var sourceFilename = path.join(dirname_1, source); | ||
var sourceContent = fs.readFileSync(sourceFilename, "utf-8"); | ||
sourcesContent_1.push(sourceContent); | ||
}); | ||
map.addProperty("sourcesContent", sourcesContent_1); | ||
} | ||
bundleItem.source = combineSourceMap.removeComments(bundleItem.source) + map.toComment(); | ||
} | ||
}; | ||
SourceMap.prototype.getNumberOfNewlines = function (source) { | ||
var newlines = source.match(/\n/g); | ||
return newlines ? newlines.length : 0; | ||
}; | ||
return SourceMap; | ||
}()); | ||
exports.SourceMap = SourceMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.