MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / extractPreviews

Function extractPreviews

scripts/experimental/swiftui-preview.mjs:958–988  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

956}
957
958function extractPreviews(source) {
959 const previews = [];
960 let searchFrom = 0;
961 while (true) {
962 const macroIndex = source.indexOf("#Preview", searchFrom);
963 if (macroIndex < 0) {
964 break;
965 }
966 let cursor = macroIndex + "#Preview".length;
967 cursor = skipWhitespace(source, cursor);
968 let name = "";
969 if (source[cursor] === "(") {
970 const parens = readBalanced(source, cursor, "(", ")");
971 name = firstStringLiteral(parens.text) ?? "";
972 cursor = skipWhitespace(source, parens.end + 1);
973 }
974 if (source[cursor] !== "{") {
975 searchFrom = cursor + 1;
976 continue;
977 }
978 const body = readBalanced(source, cursor, "{", "}");
979 previews.push({
980 body: body.text.trim(),
981 index: previews.length,
982 name,
983 range: [macroIndex, body.end + 1],
984 });
985 searchFrom = body.end + 1;
986 }
987 return previews;
988}
989
990function selectPreview(previews, selector) {
991 if (selector == null || selector === "") {

Callers 1

reloadPreviewFunction · 0.85

Calls 3

skipWhitespaceFunction · 0.85
readBalancedFunction · 0.85
firstStringLiteralFunction · 0.85

Tested by

no test coverage detected