source: trip-planner-front/node_modules/source-list-map/lib/CodeNode.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7const getNumberOfLines = require("./helpers").getNumberOfLines;
8const getUnfinishedLine = require("./helpers").getUnfinishedLine;
9
10class CodeNode {
11 constructor(generatedCode) {
12 this.generatedCode = generatedCode;
13 }
14
15 clone() {
16 return new CodeNode(this.generatedCode);
17 }
18
19 getGeneratedCode() {
20 return this.generatedCode;
21 }
22
23 getMappings(mappingsContext) {
24 const lines = getNumberOfLines(this.generatedCode);
25 const mapping = Array(lines+1).join(";");
26 if(lines > 0) {
27 mappingsContext.unfinishedGeneratedLine = getUnfinishedLine(this.generatedCode);
28 if(mappingsContext.unfinishedGeneratedLine > 0) {
29 return mapping + "A";
30 } else {
31 return mapping;
32 }
33 } else {
34 const prevUnfinished = mappingsContext.unfinishedGeneratedLine;
35 mappingsContext.unfinishedGeneratedLine += getUnfinishedLine(this.generatedCode);
36 if(prevUnfinished === 0 && mappingsContext.unfinishedGeneratedLine > 0) {
37 return "A";
38 } else {
39 return "";
40 }
41 }
42 }
43
44 addGeneratedCode(generatedCode) {
45 this.generatedCode += generatedCode;
46 }
47
48 mapGeneratedCode(fn) {
49 const generatedCode = fn(this.generatedCode);
50 return new CodeNode(generatedCode);
51 }
52
53 getNormalizedNodes() {
54 return [this];
55 }
56
57 merge(otherNode) {
58 if(otherNode instanceof CodeNode) {
59 this.generatedCode += otherNode.generatedCode;
60 return this;
61 }
62 return false;
63 }
64}
65
66module.exports = CodeNode;
Note: See TracBrowser for help on using the repository browser.