1 |
|
2 |
|
3 |
|
4 |
|
5 | var base64VLQ = require("./base64-vlq");
|
6 | var getNumberOfLines = require("./helpers").getNumberOfLines;
|
7 |
|
8 | function SourceNode(generatedCode, source, originalSource, startingLine) {
|
9 | this.generatedCode = generatedCode;
|
10 | this.originalSource = originalSource;
|
11 | this.source = source;
|
12 | this.startingLine = startingLine || 1;
|
13 | }
|
14 | module.exports = SourceNode;
|
15 |
|
16 | SourceNode.prototype.clone = function() {
|
17 | return new SourceNode(this.generatedCode, this.source, this.originalSource, this.startingLine);
|
18 | }
|
19 |
|
20 | var LINE_MAPPING = "AACA;";
|
21 | var LAST_LINE_MAPPING = "AACA";
|
22 |
|
23 | SourceNode.prototype.getGeneratedCode = function() {
|
24 | return this.generatedCode;
|
25 | };
|
26 |
|
27 | SourceNode.prototype.getMappings = function(mappingsContext) {
|
28 | var lines = getNumberOfLines(this.generatedCode);
|
29 | var sourceIdx = mappingsContext.ensureSource(this.source, this.originalSource);
|
30 | var mappings = "A";
|
31 | mappings += base64VLQ.encode(sourceIdx - mappingsContext.currentSource);
|
32 | mappings += base64VLQ.encode(this.startingLine - mappingsContext.currentOriginalLine);
|
33 | mappings += "A";
|
34 | if(lines !== 0)
|
35 | mappings += ";"
|
36 | mappingsContext.currentSource = sourceIdx;
|
37 | mappingsContext.currentOriginalLine = (lines || 1) + this.startingLine - 1;
|
38 | mappings += Array(lines).join(LINE_MAPPING);
|
39 | if(lines !== 0 && this.generatedCode[this.generatedCode.length - 1] !== "\n") {
|
40 | mappings += LAST_LINE_MAPPING;
|
41 | mappingsContext.currentOriginalLine++;
|
42 | }
|
43 | return mappings;
|
44 | };
|
45 |
|
46 | SourceNode.prototype.mapGeneratedCode = function(fn) {
|
47 | this.generatedCode = fn(this.generatedCode);
|
48 | };
|