sourcemap.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Generated by CoffeeScript 1.12.6
  2. (function() {
  3. var LineMap, SourceMap;
  4. LineMap = (function() {
  5. function LineMap(line1) {
  6. this.line = line1;
  7. this.columns = [];
  8. }
  9. LineMap.prototype.add = function(column, arg, options) {
  10. var sourceColumn, sourceLine;
  11. sourceLine = arg[0], sourceColumn = arg[1];
  12. if (options == null) {
  13. options = {};
  14. }
  15. if (this.columns[column] && options.noReplace) {
  16. return;
  17. }
  18. return this.columns[column] = {
  19. line: this.line,
  20. column: column,
  21. sourceLine: sourceLine,
  22. sourceColumn: sourceColumn
  23. };
  24. };
  25. LineMap.prototype.sourceLocation = function(column) {
  26. var mapping;
  27. while (!((mapping = this.columns[column]) || (column <= 0))) {
  28. column--;
  29. }
  30. return mapping && [mapping.sourceLine, mapping.sourceColumn];
  31. };
  32. return LineMap;
  33. })();
  34. SourceMap = (function() {
  35. var BASE64_CHARS, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK;
  36. function SourceMap() {
  37. this.lines = [];
  38. }
  39. SourceMap.prototype.add = function(sourceLocation, generatedLocation, options) {
  40. var base, column, line, lineMap;
  41. if (options == null) {
  42. options = {};
  43. }
  44. line = generatedLocation[0], column = generatedLocation[1];
  45. lineMap = ((base = this.lines)[line] || (base[line] = new LineMap(line)));
  46. return lineMap.add(column, sourceLocation, options);
  47. };
  48. SourceMap.prototype.sourceLocation = function(arg) {
  49. var column, line, lineMap;
  50. line = arg[0], column = arg[1];
  51. while (!((lineMap = this.lines[line]) || (line <= 0))) {
  52. line--;
  53. }
  54. return lineMap && lineMap.sourceLocation(column);
  55. };
  56. SourceMap.prototype.generate = function(options, code) {
  57. var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
  58. if (options == null) {
  59. options = {};
  60. }
  61. if (code == null) {
  62. code = null;
  63. }
  64. writingline = 0;
  65. lastColumn = 0;
  66. lastSourceLine = 0;
  67. lastSourceColumn = 0;
  68. needComma = false;
  69. buffer = "";
  70. ref = this.lines;
  71. for (lineNumber = i = 0, len = ref.length; i < len; lineNumber = ++i) {
  72. lineMap = ref[lineNumber];
  73. if (lineMap) {
  74. ref1 = lineMap.columns;
  75. for (j = 0, len1 = ref1.length; j < len1; j++) {
  76. mapping = ref1[j];
  77. if (!(mapping)) {
  78. continue;
  79. }
  80. while (writingline < mapping.line) {
  81. lastColumn = 0;
  82. needComma = false;
  83. buffer += ";";
  84. writingline++;
  85. }
  86. if (needComma) {
  87. buffer += ",";
  88. needComma = false;
  89. }
  90. buffer += this.encodeVlq(mapping.column - lastColumn);
  91. lastColumn = mapping.column;
  92. buffer += this.encodeVlq(0);
  93. buffer += this.encodeVlq(mapping.sourceLine - lastSourceLine);
  94. lastSourceLine = mapping.sourceLine;
  95. buffer += this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
  96. lastSourceColumn = mapping.sourceColumn;
  97. needComma = true;
  98. }
  99. }
  100. }
  101. v3 = {
  102. version: 3,
  103. file: options.generatedFile || '',
  104. sourceRoot: options.sourceRoot || '',
  105. sources: options.sourceFiles || [''],
  106. names: [],
  107. mappings: buffer
  108. };
  109. if (options.inlineMap) {
  110. v3.sourcesContent = [code];
  111. }
  112. return v3;
  113. };
  114. VLQ_SHIFT = 5;
  115. VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
  116. VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
  117. SourceMap.prototype.encodeVlq = function(value) {
  118. var answer, nextChunk, signBit, valueToEncode;
  119. answer = '';
  120. signBit = value < 0 ? 1 : 0;
  121. valueToEncode = (Math.abs(value) << 1) + signBit;
  122. while (valueToEncode || !answer) {
  123. nextChunk = valueToEncode & VLQ_VALUE_MASK;
  124. valueToEncode = valueToEncode >> VLQ_SHIFT;
  125. if (valueToEncode) {
  126. nextChunk |= VLQ_CONTINUATION_BIT;
  127. }
  128. answer += this.encodeBase64(nextChunk);
  129. }
  130. return answer;
  131. };
  132. BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  133. SourceMap.prototype.encodeBase64 = function(value) {
  134. return BASE64_CHARS[value] || (function() {
  135. throw new Error("Cannot Base64 encode value: " + value);
  136. })();
  137. };
  138. return SourceMap;
  139. })();
  140. module.exports = SourceMap;
  141. }).call(this);