MCPcopy
hub / github.com/benjamn/recast / join

Method join

lib/lines.ts:619–693  ·  view source on GitHub ↗
(elements: (string | Lines)[])

Source from the content-addressed store, hash-verified

617 }
618
619 join(elements: (string | Lines)[]) {
620 const separator = this;
621 const infos: any[] = [];
622 const mappings: any[] = [];
623 let prevInfo: any;
624
625 function appendLines(linesOrNull: Lines | null) {
626 if (linesOrNull === null) {
627 return;
628 }
629
630 if (prevInfo) {
631 const info = linesOrNull.infos[0];
632 const indent = new Array(info.indent + 1).join(" ");
633 const prevLine = infos.length;
634 const prevColumn =
635 Math.max(prevInfo.indent, 0) +
636 prevInfo.sliceEnd -
637 prevInfo.sliceStart;
638
639 prevInfo.line =
640 prevInfo.line.slice(0, prevInfo.sliceEnd) +
641 indent +
642 info.line.slice(info.sliceStart, info.sliceEnd);
643
644 // If any part of a line is indentation-locked, the whole line
645 // will be indentation-locked.
646 prevInfo.locked = prevInfo.locked || info.locked;
647
648 prevInfo.sliceEnd = prevInfo.line.length;
649
650 if (linesOrNull.mappings.length > 0) {
651 linesOrNull.mappings.forEach(function (mapping: any) {
652 mappings.push(mapping.add(prevLine, prevColumn));
653 });
654 }
655 } else if (linesOrNull.mappings.length > 0) {
656 mappings.push.apply(mappings, linesOrNull.mappings);
657 }
658
659 linesOrNull.infos.forEach(function (info: any, i: any) {
660 if (!prevInfo || i > 0) {
661 prevInfo = { ...info };
662 infos.push(prevInfo);
663 }
664 });
665 }
666
667 function appendWithSeparator(linesOrNull: Lines | null, i: number) {
668 if (i > 0) appendLines(separator);
669 appendLines(linesOrNull);
670 }
671
672 elements
673 .map(function (elem: any) {
674 const lines = fromString(elem);
675 if (lines.isEmpty()) return null;
676 return lines;

Callers 15

printLeadingCommentFunction · 0.80
printTrailingCommentFunction · 0.80
genericPrintNoParensFunction · 0.80
printStatementSequenceFunction · 0.80
printArgumentsListFunction · 0.80
printFunctionParamsFunction · 0.80
printExportDeclarationFunction · 0.80
bootstrapSliceMethod · 0.80
sliceStringMethod · 0.80
appendLinesMethod · 0.80
concatMethod · 0.80

Calls 3

isEmptyMethod · 0.95
fromStringFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected