INNER CODE UNIT · TypeScript

addPackagesToExistingListOf

margelo/react-native-runtimes · packages/core/plugin/src/index.ts:181

function addPackagesToExistingListOf(contents: string, missingFQNs: string[]): string {
  const providerIdx = contents.indexOf('setExtraReactPackagesProvider');
  if (providerIdx < 0) return contents;

  const listOfIdx = contents.indexOf('listOf(', providerIdx);
  if (listOfIdx < 0) return contents;

  const lineStart = contents.lastIndexOf('\n', listOfIdx) + 1;
  const listOfLineIndent =
    contents.slice(lineStart, listOfIdx).match(/^([ \t]+)/)?.[1] ?? '      ';
  const deepIndent = listOfLineIndent + '  ';
  const insertPos = listOfIdx + 'listOf('.length;

  const toInsert = missingFQNs
    .map((fqn) => `\n${deepIndent}${getSimpleClassName(fqn)}(),`)
    .join('');

  return contents.slice(0, insertPos) + toInsert + contents.slice(insertPos);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…