MCPcopy Create free account
hub / github.com/dashnowords/imfe / generateCodeFrame

Function generateCodeFrame

chapter17/vue.js:11593–11628  ·  view source on GitHub ↗
(
    source,
    start,
    end
  )

Source from the content-addressed store, hash-verified

11591 var range = 2;
11592
11593 function generateCodeFrame (
11594 source,
11595 start,
11596 end
11597 ) {
11598 if ( start === void 0 ) start = 0;
11599 if ( end === void 0 ) end = source.length;
11600
11601 var lines = source.split(/\r?\n/);
11602 var count = 0;
11603 var res = [];
11604 for (var i = 0; i < lines.length; i++) {
11605 count += lines[i].length + 1;
11606 if (count >= start) {
11607 for (var j = i - range; j <= i + range || end > count; j++) {
11608 if (j < 0 || j >= lines.length) { continue }
11609 res.push(("" + (j + 1) + (repeat$1(" ", 3 - String(j + 1).length)) + "| " + (lines[j])));
11610 var lineLength = lines[j].length;
11611 if (j === i) {
11612 // push underline
11613 var pad = start - (count - lineLength) + 1;
11614 var length = end > count ? lineLength - pad : end - start;
11615 res.push(" | " + repeat$1(" ", pad) + repeat$1("^", length));
11616 } else if (j > i) {
11617 if (end > count) {
11618 var length$1 = Math.min(end - count, lineLength);
11619 res.push(" | " + repeat$1("^", length$1));
11620 }
11621 count += lineLength + 1;
11622 }
11623 }
11624 break
11625 }
11626 }
11627 return res.join('\n')
11628 }
11629
11630 function repeat$1 (str, n) {
11631 var result = '';

Callers 1

Calls 1

repeat$1Function · 0.85

Tested by

no test coverage detected