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 SourceMapGenerator = require("source-map").SourceMapGenerator;
|
10 |
|
|
var SourceListMap = require("source-list-map").SourceListMap;
|
11 |
|
|
var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
|
12 |
|
|
var Source = require("./Source");
|
13 |
|
|
var applySourceMap = require("./applySourceMap");
|
14 |
|
|
|
15 |
|
|
class SourceMapSource extends Source {
|
16 |
|
|
constructor(value, name, sourceMap, originalSource, innerSourceMap, removeOriginalSource) {
|
17 |
|
|
super();
|
18 |
|
|
this._value = value;
|
19 |
|
|
this._name = name;
|
20 |
|
|
this._sourceMap = sourceMap;
|
21 |
|
|
this._originalSource = originalSource;
|
22 |
|
|
this._innerSourceMap = innerSourceMap;
|
23 |
|
|
this._removeOriginalSource = removeOriginalSource;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
source() {
|
27 |
|
|
return this._value;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
node(options) {
|
31 |
|
|
var sourceMap = this._sourceMap;
|
32 |
|
|
var node = SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
|
33 |
|
|
node.setSourceContent(this._name, this._originalSource);
|
34 |
|
|
var innerSourceMap = this._innerSourceMap;
|
35 |
|
|
if(innerSourceMap) {
|
36 |
|
|
node = applySourceMap(node, new SourceMapConsumer(innerSourceMap), this._name, this._removeOriginalSource);
|
37 |
|
|
}
|
38 |
|
|
return node;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
listMap(options) {
|
42 |
|
|
options = options || {};
|
43 |
|
|
if(options.module === false)
|
44 |
|
|
return new SourceListMap(this._value, this._name, this._value);
|
45 |
|
|
return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
updateHash(hash) {
|
49 |
|
|
hash.update(this._value);
|
50 |
|
|
if(this._originalSource)
|
51 |
|
|
hash.update(this._originalSource);
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
require("./SourceAndMapMixin")(SourceMapSource.prototype);
|
56 |
|
|
|
57 |
|
|
module.exports = SourceMapSource;
|