You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

668 lines
25 KiB

5 years ago
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __importDefault = (this && this.__importDefault) || function (mod) {
  14. return (mod && mod.__esModule) ? mod : { "default": mod };
  15. };
  16. Object.defineProperty(exports, "__esModule", { value: true });
  17. var assert_1 = __importDefault(require("assert"));
  18. var source_map_1 = __importDefault(require("source-map"));
  19. var options_1 = require("./options");
  20. var util_1 = require("./util");
  21. var mapping_1 = __importDefault(require("./mapping"));
  22. var Lines = /** @class */ (function () {
  23. function Lines(infos, sourceFileName) {
  24. if (sourceFileName === void 0) { sourceFileName = null; }
  25. this.infos = infos;
  26. this.mappings = [];
  27. this.cachedSourceMap = null;
  28. this.cachedTabWidth = void 0;
  29. assert_1.default.ok(infos.length > 0);
  30. this.length = infos.length;
  31. this.name = sourceFileName || null;
  32. if (this.name) {
  33. this.mappings.push(new mapping_1.default(this, {
  34. start: this.firstPos(),
  35. end: this.lastPos(),
  36. }));
  37. }
  38. }
  39. Lines.prototype.toString = function (options) {
  40. return this.sliceString(this.firstPos(), this.lastPos(), options);
  41. };
  42. Lines.prototype.getSourceMap = function (sourceMapName, sourceRoot) {
  43. if (!sourceMapName) {
  44. // Although we could make up a name or generate an anonymous
  45. // source map, instead we assume that any consumer who does not
  46. // provide a name does not actually want a source map.
  47. return null;
  48. }
  49. var targetLines = this;
  50. function updateJSON(json) {
  51. json = json || {};
  52. json.file = sourceMapName;
  53. if (sourceRoot) {
  54. json.sourceRoot = sourceRoot;
  55. }
  56. return json;
  57. }
  58. if (targetLines.cachedSourceMap) {
  59. // Since Lines objects are immutable, we can reuse any source map
  60. // that was previously generated. Nevertheless, we return a new
  61. // JSON object here to protect the cached source map from outside
  62. // modification.
  63. return updateJSON(targetLines.cachedSourceMap.toJSON());
  64. }
  65. var smg = new source_map_1.default.SourceMapGenerator(updateJSON());
  66. var sourcesToContents = {};
  67. targetLines.mappings.forEach(function (mapping) {
  68. var sourceCursor = mapping.sourceLines.skipSpaces(mapping.sourceLoc.start) || mapping.sourceLines.lastPos();
  69. var targetCursor = targetLines.skipSpaces(mapping.targetLoc.start) || targetLines.lastPos();
  70. while (util_1.comparePos(sourceCursor, mapping.sourceLoc.end) < 0 &&
  71. util_1.comparePos(targetCursor, mapping.targetLoc.end) < 0) {
  72. var sourceChar = mapping.sourceLines.charAt(sourceCursor);
  73. var targetChar = targetLines.charAt(targetCursor);
  74. assert_1.default.strictEqual(sourceChar, targetChar);
  75. var sourceName = mapping.sourceLines.name;
  76. // Add mappings one character at a time for maximum resolution.
  77. smg.addMapping({
  78. source: sourceName,
  79. original: { line: sourceCursor.line,
  80. column: sourceCursor.column },
  81. generated: { line: targetCursor.line,
  82. column: targetCursor.column }
  83. });
  84. if (!hasOwn.call(sourcesToContents, sourceName)) {
  85. var sourceContent = mapping.sourceLines.toString();
  86. smg.setSourceContent(sourceName, sourceContent);
  87. sourcesToContents[sourceName] = sourceContent;
  88. }
  89. targetLines.nextPos(targetCursor, true);
  90. mapping.sourceLines.nextPos(sourceCursor, true);
  91. }
  92. });
  93. targetLines.cachedSourceMap = smg;
  94. return smg.toJSON();
  95. };
  96. Lines.prototype.bootstrapCharAt = function (pos) {
  97. assert_1.default.strictEqual(typeof pos, "object");
  98. assert_1.default.strictEqual(typeof pos.line, "number");
  99. assert_1.default.strictEqual(typeof pos.column, "number");
  100. var line = pos.line, column = pos.column, strings = this.toString().split(lineTerminatorSeqExp), string = strings[line - 1];
  101. if (typeof string === "undefined")
  102. return "";
  103. if (column === string.length &&
  104. line < strings.length)
  105. return "\n";
  106. if (column >= string.length)
  107. return "";
  108. return string.charAt(column);
  109. };
  110. Lines.prototype.charAt = function (pos) {
  111. assert_1.default.strictEqual(typeof pos, "object");
  112. assert_1.default.strictEqual(typeof pos.line, "number");
  113. assert_1.default.strictEqual(typeof pos.column, "number");
  114. var line = pos.line, column = pos.column, secret = this, infos = secret.infos, info = infos[line - 1], c = column;
  115. if (typeof info === "undefined" || c < 0)
  116. return "";
  117. var indent = this.getIndentAt(line);
  118. if (c < indent)
  119. return " ";
  120. c += info.sliceStart - indent;
  121. if (c === info.sliceEnd &&
  122. line < this.length)
  123. return "\n";
  124. if (c >= info.sliceEnd)
  125. return "";
  126. return info.line.charAt(c);
  127. };
  128. Lines.prototype.stripMargin = function (width, skipFirstLine) {
  129. if (width === 0)
  130. return this;
  131. assert_1.default.ok(width > 0, "negative margin: " + width);
  132. if (skipFirstLine && this.length === 1)
  133. return this;
  134. var lines = new Lines(this.infos.map(function (info, i) {
  135. if (info.line && (i > 0 || !skipFirstLine)) {
  136. info = __assign({}, info, { indent: Math.max(0, info.indent - width) });
  137. }
  138. return info;
  139. }));
  140. if (this.mappings.length > 0) {
  141. var newMappings = lines.mappings;
  142. assert_1.default.strictEqual(newMappings.length, 0);
  143. this.mappings.forEach(function (mapping) {
  144. newMappings.push(mapping.indent(width, skipFirstLine, true));
  145. });
  146. }
  147. return lines;
  148. };
  149. Lines.prototype.indent = function (by) {
  150. if (by === 0) {
  151. return this;
  152. }
  153. var lines = new Lines(this.infos.map(function (info) {
  154. if (info.line && !info.locked) {
  155. info = __assign({}, info, { indent: info.indent + by });
  156. }
  157. return info;
  158. }));
  159. if (this.mappings.length > 0) {
  160. var newMappings = lines.mappings;
  161. assert_1.default.strictEqual(newMappings.length, 0);
  162. this.mappings.forEach(function (mapping) {
  163. newMappings.push(mapping.indent(by));
  164. });
  165. }
  166. return lines;
  167. };
  168. Lines.prototype.indentTail = function (by) {
  169. if (by === 0) {
  170. return this;
  171. }
  172. if (this.length < 2) {
  173. return this;
  174. }
  175. var lines = new Lines(this.infos.map(function (info, i) {
  176. if (i > 0 && info.line && !info.locked) {
  177. info = __assign({}, info, { indent: info.indent + by });
  178. }
  179. return info;
  180. }));
  181. if (this.mappings.length > 0) {
  182. var newMappings = lines.mappings;
  183. assert_1.default.strictEqual(newMappings.length, 0);
  184. this.mappings.forEach(function (mapping) {
  185. newMappings.push(mapping.indent(by, true));
  186. });
  187. }
  188. return lines;
  189. };
  190. Lines.prototype.lockIndentTail = function () {
  191. if (this.length < 2) {
  192. return this;
  193. }
  194. return new Lines(this.infos.map(function (info, i) {
  195. return __assign({}, info, { locked: i > 0 });
  196. }));
  197. };
  198. Lines.prototype.getIndentAt = function (line) {
  199. assert_1.default.ok(line >= 1, "no line " + line + " (line numbers start from 1)");
  200. return Math.max(this.infos[line - 1].indent, 0);
  201. };
  202. Lines.prototype.guessTabWidth = function () {
  203. if (typeof this.cachedTabWidth === "number") {
  204. return this.cachedTabWidth;
  205. }
  206. var counts = []; // Sparse array.
  207. var lastIndent = 0;
  208. for (var line = 1, last = this.length; line <= last; ++line) {
  209. var info = this.infos[line - 1];
  210. var sliced = info.line.slice(info.sliceStart, info.sliceEnd);
  211. // Whitespace-only lines don't tell us much about the likely tab
  212. // width of this code.
  213. if (isOnlyWhitespace(sliced)) {
  214. continue;
  215. }
  216. var diff = Math.abs(info.indent - lastIndent);
  217. counts[diff] = ~~counts[diff] + 1;
  218. lastIndent = info.indent;
  219. }
  220. var maxCount = -1;
  221. var result = 2;
  222. for (var tabWidth = 1; tabWidth < counts.length; tabWidth += 1) {
  223. if (hasOwn.call(counts, tabWidth) &&
  224. counts[tabWidth] > maxCount) {
  225. maxCount = counts[tabWidth];
  226. result = tabWidth;
  227. }
  228. }
  229. return this.cachedTabWidth = result;
  230. };
  231. // Determine if the list of lines has a first line that starts with a //
  232. // or /* comment. If this is the case, the code may need to be wrapped in
  233. // parens to avoid ASI issues.
  234. Lines.prototype.startsWithComment = function () {
  235. if (this.infos.length === 0) {
  236. return false;
  237. }
  238. var firstLineInfo = this.infos[0], sliceStart = firstLineInfo.sliceStart, sliceEnd = firstLineInfo.sliceEnd, firstLine = firstLineInfo.line.slice(sliceStart, sliceEnd).trim();
  239. return firstLine.length === 0 ||
  240. firstLine.slice(0, 2) === "//" ||
  241. firstLine.slice(0, 2) === "/*";
  242. };
  243. Lines.prototype.isOnlyWhitespace = function () {
  244. return isOnlyWhitespace(this.toString());
  245. };
  246. Lines.prototype.isPrecededOnlyByWhitespace = function (pos) {
  247. var info = this.infos[pos.line - 1];
  248. var indent = Math.max(info.indent, 0);
  249. var diff = pos.column - indent;
  250. if (diff <= 0) {
  251. // If pos.column does not exceed the indentation amount, then
  252. // there must be only whitespace before it.
  253. return true;
  254. }
  255. var start = info.sliceStart;
  256. var end = Math.min(start + diff, info.sliceEnd);
  257. var prefix = info.line.slice(start, end);
  258. return isOnlyWhitespace(prefix);
  259. };
  260. Lines.prototype.getLineLength = function (line) {
  261. var info = this.infos[line - 1];
  262. return this.getIndentAt(line) + info.sliceEnd - info.sliceStart;
  263. };
  264. Lines.prototype.nextPos = function (pos, skipSpaces) {
  265. if (skipSpaces === void 0) { skipSpaces = false; }
  266. var l = Math.max(pos.line, 0), c = Math.max(pos.column, 0);
  267. if (c < this.getLineLength(l)) {
  268. pos.column += 1;
  269. return skipSpaces
  270. ? !!this.skipSpaces(pos, false, true)
  271. : true;
  272. }
  273. if (l < this.length) {
  274. pos.line += 1;
  275. pos.column = 0;
  276. return skipSpaces
  277. ? !!this.skipSpaces(pos, false, true)
  278. : true;
  279. }
  280. return false;
  281. };
  282. Lines.prototype.prevPos = function (pos, skipSpaces) {
  283. if (skipSpaces === void 0) { skipSpaces = false; }
  284. var l = pos.line, c = pos.column;
  285. if (c < 1) {
  286. l -= 1;
  287. if (l < 1)
  288. return false;
  289. c = this.getLineLength(l);
  290. }
  291. else {
  292. c = Math.min(c - 1, this.getLineLength(l));
  293. }
  294. pos.line = l;
  295. pos.column = c;
  296. return skipSpaces
  297. ? !!this.skipSpaces(pos, true, true)
  298. : true;
  299. };
  300. Lines.prototype.firstPos = function () {
  301. // Trivial, but provided for completeness.
  302. return { line: 1, column: 0 };
  303. };
  304. Lines.prototype.lastPos = function () {
  305. return {
  306. line: this.length,
  307. column: this.getLineLength(this.length)
  308. };
  309. };
  310. Lines.prototype.skipSpaces = function (pos, backward, modifyInPlace) {
  311. if (backward === void 0) { backward = false; }
  312. if (modifyInPlace === void 0) { modifyInPlace = false; }
  313. if (pos) {
  314. pos = modifyInPlace ? pos : {
  315. line: pos.line,
  316. column: pos.column
  317. };
  318. }
  319. else if (backward) {
  320. pos = this.lastPos();
  321. }
  322. else {
  323. pos = this.firstPos();
  324. }
  325. if (backward) {
  326. while (this.prevPos(pos)) {
  327. if (!isOnlyWhitespace(this.charAt(pos)) &&
  328. this.nextPos(pos)) {
  329. return pos;
  330. }
  331. }
  332. return null;
  333. }
  334. else {
  335. while (isOnlyWhitespace(this.charAt(pos))) {
  336. if (!this.nextPos(pos)) {
  337. return null;
  338. }
  339. }
  340. return pos;
  341. }
  342. };
  343. Lines.prototype.trimLeft = function () {
  344. var pos = this.skipSpaces(this.firstPos(), false, true);
  345. return pos ? this.slice(pos) : emptyLines;
  346. };
  347. Lines.prototype.trimRight = function () {
  348. var pos = this.skipSpaces(this.lastPos(), true, true);
  349. return pos ? this.slice(this.firstPos(), pos) : emptyLines;
  350. };
  351. Lines.prototype.trim = function () {
  352. var start = this.skipSpaces(this.firstPos(), false, true);
  353. if (start === null) {
  354. return emptyLines;
  355. }
  356. var end = this.skipSpaces(this.lastPos(), true, true);
  357. if (end === null) {
  358. return emptyLines;
  359. }
  360. return this.slice(start, end);
  361. };
  362. Lines.prototype.eachPos = function (callback, startPos, skipSpaces) {
  363. if (startPos === void 0) { startPos = this.firstPos(); }
  364. if (skipSpaces === void 0) { skipSpaces = false; }
  365. var pos = this.firstPos();
  366. if (startPos) {
  367. pos.line = startPos.line,
  368. pos.column = startPos.column;
  369. }
  370. if (skipSpaces && !this.skipSpaces(pos, false, true)) {
  371. return; // Encountered nothing but spaces.
  372. }
  373. do
  374. callback.call(this, pos);
  375. while (this.nextPos(pos, skipSpaces));
  376. };
  377. Lines.prototype.bootstrapSlice = function (start, end) {
  378. var strings = this.toString().split(lineTerminatorSeqExp).slice(start.line - 1, end.line);
  379. if (strings.length > 0) {
  380. strings.push(strings.pop().slice(0, end.column));
  381. strings[0] = strings[0].slice(start.column);
  382. }
  383. return fromString(strings.join("\n"));
  384. };
  385. Lines.prototype.slice = function (start, end) {
  386. if (!end) {
  387. if (!start) {
  388. // The client seems to want a copy of this Lines object, but
  389. // Lines objects are immutable, so it's perfectly adequate to
  390. // return the same object.
  391. return this;
  392. }
  393. // Slice to the end if no end position was provided.
  394. end = this.lastPos();
  395. }
  396. if (!start) {
  397. throw new Error("cannot slice with end but not start");
  398. }
  399. var sliced = this.infos.slice(start.line - 1, end.line);
  400. if (start.line === end.line) {
  401. sliced[0] = sliceInfo(sliced[0], start.column, end.column);
  402. }
  403. else {
  404. assert_1.default.ok(start.line < end.line);
  405. sliced[0] = sliceInfo(sliced[0], start.column);
  406. sliced.push(sliceInfo(sliced.pop(), 0, end.column));
  407. }
  408. var lines = new Lines(sliced);
  409. if (this.mappings.length > 0) {
  410. var newMappings = lines.mappings;
  411. assert_1.default.strictEqual(newMappings.length, 0);
  412. this.mappings.forEach(function (mapping) {
  413. var sliced = mapping.slice(this, start, end);
  414. if (sliced) {
  415. newMappings.push(sliced);
  416. }
  417. }, this);
  418. }
  419. return lines;
  420. };
  421. Lines.prototype.bootstrapSliceString = function (start, end, options) {
  422. return this.slice(start, end).toString(options);
  423. };
  424. Lines.prototype.sliceString = function (start, end, options) {
  425. if (start === void 0) { start = this.firstPos(); }
  426. if (end === void 0) { end = this.lastPos(); }
  427. options = options_1.normalize(options);
  428. var parts = [];
  429. var _a = options.tabWidth, tabWidth = _a === void 0 ? 2 : _a;
  430. for (var line = start.line; line <= end.line; ++line) {
  431. var info = this.infos[line - 1];
  432. if (line === start.line) {
  433. if (line === end.line) {
  434. info = sliceInfo(info, start.column, end.column);
  435. }
  436. else {
  437. info = sliceInfo(info, start.column);
  438. }
  439. }
  440. else if (line === end.line) {
  441. info = sliceInfo(info, 0, end.column);
  442. }
  443. var indent = Math.max(info.indent, 0);
  444. var before = info.line.slice(0, info.sliceStart);
  445. if (options.reuseWhitespace &&
  446. isOnlyWhitespace(before) &&
  447. countSpaces(before, options.tabWidth) === indent) {
  448. // Reuse original spaces if the indentation is correct.
  449. parts.push(info.line.slice(0, info.sliceEnd));
  450. continue;
  451. }
  452. var tabs = 0;
  453. var spaces = indent;
  454. if (options.useTabs) {
  455. tabs = Math.floor(indent / tabWidth);
  456. spaces -= tabs * tabWidth;
  457. }
  458. var result = "";
  459. if (tabs > 0) {
  460. result += new Array(tabs + 1).join("\t");
  461. }
  462. if (spaces > 0) {
  463. result += new Array(spaces + 1).join(" ");
  464. }
  465. result += info.line.slice(info.sliceStart, info.sliceEnd);
  466. parts.push(result);
  467. }
  468. return parts.join(options.lineTerminator);
  469. };
  470. Lines.prototype.isEmpty = function () {
  471. return this.length < 2 && this.getLineLength(1) < 1;
  472. };
  473. Lines.prototype.join = function (elements) {
  474. var separator = this;
  475. var infos = [];
  476. var mappings = [];
  477. var prevInfo;
  478. function appendLines(linesOrNull) {
  479. if (linesOrNull === null) {
  480. return;
  481. }
  482. if (prevInfo) {
  483. var info = linesOrNull.infos[0];
  484. var indent = new Array(info.indent + 1).join(" ");
  485. var prevLine = infos.length;
  486. var prevColumn = Math.max(prevInfo.indent, 0) +
  487. prevInfo.sliceEnd - prevInfo.sliceStart;
  488. prevInfo.line = prevInfo.line.slice(0, prevInfo.sliceEnd) + indent + info.line.slice(info.sliceStart, info.sliceEnd);
  489. // If any part of a line is indentation-locked, the whole line
  490. // will be indentation-locked.
  491. prevInfo.locked = prevInfo.locked || info.locked;
  492. prevInfo.sliceEnd = prevInfo.line.length;
  493. if (linesOrNull.mappings.length > 0) {
  494. linesOrNull.mappings.forEach(function (mapping) {
  495. mappings.push(mapping.add(prevLine, prevColumn));
  496. });
  497. }
  498. }
  499. else if (linesOrNull.mappings.length > 0) {
  500. mappings.push.apply(mappings, linesOrNull.mappings);
  501. }
  502. linesOrNull.infos.forEach(function (info, i) {
  503. if (!prevInfo || i > 0) {
  504. prevInfo = __assign({}, info);
  505. infos.push(prevInfo);
  506. }
  507. });
  508. }
  509. function appendWithSeparator(linesOrNull, i) {
  510. if (i > 0)
  511. appendLines(separator);
  512. appendLines(linesOrNull);
  513. }
  514. elements.map(function (elem) {
  515. var lines = fromString(elem);
  516. if (lines.isEmpty())
  517. return null;
  518. return lines;
  519. }).forEach(function (linesOrNull, i) {
  520. if (separator.isEmpty()) {
  521. appendLines(linesOrNull);
  522. }
  523. else {
  524. appendWithSeparator(linesOrNull, i);
  525. }
  526. });
  527. if (infos.length < 1)
  528. return emptyLines;
  529. var lines = new Lines(infos);
  530. lines.mappings = mappings;
  531. return lines;
  532. };
  533. Lines.prototype.concat = function () {
  534. var args = [];
  535. for (var _i = 0; _i < arguments.length; _i++) {
  536. args[_i] = arguments[_i];
  537. }
  538. var list = [this];
  539. list.push.apply(list, args);
  540. assert_1.default.strictEqual(list.length, args.length + 1);
  541. return emptyLines.join(list);
  542. };
  543. return Lines;
  544. }());
  545. exports.Lines = Lines;
  546. var fromStringCache = {};
  547. var hasOwn = fromStringCache.hasOwnProperty;
  548. var maxCacheKeyLen = 10;
  549. function countSpaces(spaces, tabWidth) {
  550. var count = 0;
  551. var len = spaces.length;
  552. for (var i = 0; i < len; ++i) {
  553. switch (spaces.charCodeAt(i)) {
  554. case 9: // '\t'
  555. assert_1.default.strictEqual(typeof tabWidth, "number");
  556. assert_1.default.ok(tabWidth > 0);
  557. var next = Math.ceil(count / tabWidth) * tabWidth;
  558. if (next === count) {
  559. count += tabWidth;
  560. }
  561. else {
  562. count = next;
  563. }
  564. break;
  565. case 11: // '\v'
  566. case 12: // '\f'
  567. case 13: // '\r'
  568. case 0xfeff: // zero-width non-breaking space
  569. // These characters contribute nothing to indentation.
  570. break;
  571. case 32: // ' '
  572. default: // Treat all other whitespace like ' '.
  573. count += 1;
  574. break;
  575. }
  576. }
  577. return count;
  578. }
  579. exports.countSpaces = countSpaces;
  580. var leadingSpaceExp = /^\s*/;
  581. // As specified here: http://www.ecma-international.org/ecma-262/6.0/#sec-line-terminators
  582. var lineTerminatorSeqExp = /\u000D\u000A|\u000D(?!\u000A)|\u000A|\u2028|\u2029/;
  583. /**
  584. * @param {Object} options - Options object that configures printing.
  585. */
  586. function fromString(string, options) {
  587. if (string instanceof Lines)
  588. return string;
  589. string += "";
  590. var tabWidth = options && options.tabWidth;
  591. var tabless = string.indexOf("\t") < 0;
  592. var cacheable = !options && tabless && (string.length <= maxCacheKeyLen);
  593. assert_1.default.ok(tabWidth || tabless, "No tab width specified but encountered tabs in string\n" + string);
  594. if (cacheable && hasOwn.call(fromStringCache, string))
  595. return fromStringCache[string];
  596. var lines = new Lines(string.split(lineTerminatorSeqExp).map(function (line) {
  597. // TODO: handle null exec result
  598. var spaces = leadingSpaceExp.exec(line)[0];
  599. return {
  600. line: line,
  601. indent: countSpaces(spaces, tabWidth),
  602. // Boolean indicating whether this line can be reindented.
  603. locked: false,
  604. sliceStart: spaces.length,
  605. sliceEnd: line.length
  606. };
  607. }), options_1.normalize(options).sourceFileName);
  608. if (cacheable)
  609. fromStringCache[string] = lines;
  610. return lines;
  611. }
  612. exports.fromString = fromString;
  613. function isOnlyWhitespace(string) {
  614. return !/\S/.test(string);
  615. }
  616. function sliceInfo(info, startCol, endCol) {
  617. var sliceStart = info.sliceStart;
  618. var sliceEnd = info.sliceEnd;
  619. var indent = Math.max(info.indent, 0);
  620. var lineLength = indent + sliceEnd - sliceStart;
  621. if (typeof endCol === "undefined") {
  622. endCol = lineLength;
  623. }
  624. startCol = Math.max(startCol, 0);
  625. endCol = Math.min(endCol, lineLength);
  626. endCol = Math.max(endCol, startCol);
  627. if (endCol < indent) {
  628. indent = endCol;
  629. sliceEnd = sliceStart;
  630. }
  631. else {
  632. sliceEnd -= lineLength - endCol;
  633. }
  634. lineLength = endCol;
  635. lineLength -= startCol;
  636. if (startCol < indent) {
  637. indent -= startCol;
  638. }
  639. else {
  640. startCol -= indent;
  641. indent = 0;
  642. sliceStart += startCol;
  643. }
  644. assert_1.default.ok(indent >= 0);
  645. assert_1.default.ok(sliceStart <= sliceEnd);
  646. assert_1.default.strictEqual(lineLength, indent + sliceEnd - sliceStart);
  647. if (info.indent === indent &&
  648. info.sliceStart === sliceStart &&
  649. info.sliceEnd === sliceEnd) {
  650. return info;
  651. }
  652. return {
  653. line: info.line,
  654. indent: indent,
  655. // A destructive slice always unlocks indentation.
  656. locked: false,
  657. sliceStart: sliceStart,
  658. sliceEnd: sliceEnd
  659. };
  660. }
  661. function concat(elements) {
  662. return emptyLines.join(elements);
  663. }
  664. exports.concat = concat;
  665. ;
  666. // The emptyLines object needs to be created all the way down here so that
  667. // Lines.prototype will be fully populated.
  668. var emptyLines = fromString("");