Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added PrefixSource

  • Loading branch information...
commit 0037f89607ff3a5b195867e300549c5fc6899aef 1 parent 453969a
@sokra sokra authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 lib/PrefixSource.js
View
37 lib/PrefixSource.js
@@ -0,0 +1,37 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+var SourceMapNodeSource = require("./SourceMapNodeSource");
+var SourceNode = require("source-map").SourceNode;
+
+function PrefixSource(prefix, source) {
+ var node = source.node();
+ node = new SourceNode(null, null, null, [
+ prefix,
+ this._cloneAndReplace(node, /\n/g, "\n" + prefix)
+ ]);
+ SourceMapNodeSource.call(this, node);
+}
+module.exports = PrefixSource;
+
+PrefixSource.prototype = Object.create(SourceMapNodeSource.prototype);
+PrefixSource.prototype._cloneAndReplace = function cloneAndReplace(node, regExp, replacement) {
+ if(typeof node === "string") {
+ return node.replace(regExp, replacement);
+ } else {
+ var newNode = new SourceNode(
+ node.line,
+ node.column,
+ node.source,
+ node.children.map(function(node) {
+ return cloneAndReplace(node, regExp, replacement);
+ }),
+ node.name
+ );
+ node.walkSourceContents(function(file, content) {
+ newNode.setSourceContent(file, content);
+ });
+ return newNode;
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.