MCPcopy Index your code
hub / github.com/glideapps/quicktype / serializeToStringArray

Function serializeToStringArray

src/Source.ts:197–261  ·  view source on GitHub ↗
(source: Source)

Source from the content-addressed store, hash-verified

195 }
196
197 function serializeToStringArray(source: Source): void {
198 switch (source.kind) {
199 case "text":
200 indentIfNeeded();
201 currentLine.push(source.text);
202 break;
203 case "newline":
204 finishLine();
205 indent += source.indentationChange;
206 indentNeeded = indent;
207 break;
208 case "sequence":
209 source.sequence.forEach((s: Source) => serializeToStringArray(s));
210 break;
211 case "table":
212 const t = source.table;
213 const widths = t
214 .map((l: List<Source>) => l.map((s: Source) => sourceLineLength(s, names)).toList())
215 .toList();
216 const numRows = t.size;
217 if (numRows === 0) break;
218 const numColumns = defined(t.map((l: List<Source>) => l.size).max());
219 if (numColumns === 0) break;
220 const columnWidths = defined(
221 Range(0, numColumns).map((i: number) => widths.map((l: List<number>) => l.get(i) || 0).max())
222 );
223 for (let y = 0; y < numRows; y++) {
224 indentIfNeeded();
225 const row = defined(t.get(y));
226 const rowWidths = defined(widths.get(y));
227 for (let x = 0; x < numColumns; x++) {
228 const colWidth = defined(columnWidths.get(x));
229 const src = row.get(x) || { kind: "text", text: "" };
230 const srcWidth = rowWidths.get(x) || 0;
231 serializeToStringArray(src);
232 if (x < numColumns - 1 && srcWidth < colWidth) {
233 currentLine.push(_.repeat(" ", colWidth - srcWidth));
234 }
235 }
236 if (y < numRows - 1) {
237 finishLine();
238 indentNeeded = indent;
239 }
240 }
241 break;
242 case "annotated":
243 const start = currentLocation();
244 serializeToStringArray(source.source);
245 const end = currentLocation();
246 annotations.push({ annotation: source.annotation, span: { start, end } });
247 break;
248 case "name":
249 assert(names.has(source.named), "No name for Named");
250 indentIfNeeded();
251 currentLine.push(defined(names.get(source.named)));
252 break;
253 case "modified":
254 const serialized = serializeRenderResult({ rootSource: source.source, names }, indentation).lines;

Callers 1

serializeRenderResultFunction · 0.85

Calls 9

definedFunction · 0.90
assertFunction · 0.90
assertNeverFunction · 0.90
indentIfNeededFunction · 0.85
finishLineFunction · 0.85
sourceLineLengthFunction · 0.85
currentLocationFunction · 0.85
serializeRenderResultFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…