1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
"use strict";
|
6 |
|
|
|
7 |
|
|
var SourceNode = require("source-map").SourceNode;
|
8 |
|
|
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
9 |
|
|
var SourceListMap = require("source-list-map").SourceListMap;
|
10 |
|
|
var Source = require("./Source");
|
11 |
|
|
|
12 |
|
|
class LineToLineMappedSource extends Source {
|
13 |
|
|
constructor(value, name, originalSource) {
|
14 |
|
|
super();
|
15 |
|
|
this._value = value;
|
16 |
|
|
this._name = name;
|
17 |
|
|
this._originalSource = originalSource;
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
source() {
|
21 |
|
|
return this._value;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
node(options) {
|
25 |
|
|
var value = this._value;
|
26 |
|
|
var name = this._name;
|
27 |
|
|
var lines = value.split("\n");
|
28 |
|
|
var node = new SourceNode(null, null, null,
|
29 |
|
|
lines.map(function(line, idx) {
|
30 |
|
|
return new SourceNode(idx + 1, 0, name, (line + (idx != lines.length - 1 ? "\n" : "")));
|
31 |
|
|
})
|
32 |
|
|
);
|
33 |
|
|
node.setSourceContent(name, this._originalSource);
|
34 |
|
|
return node;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
listMap(options) {
|
38 |
|
|
return new SourceListMap(this._value, this._name, this._originalSource)
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
updateHash(hash) {
|
42 |
|
|
hash.update(this._value);
|
43 |
|
|
hash.update(this._originalSource);
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
require("./SourceAndMapMixin")(LineToLineMappedSource.prototype);
|
48 |
|
|
|
49 |
|
|
module.exports = LineToLineMappedSource;
|