public readFromCache()

in src/rosetta-translator.ts [109:162]


  public readFromCache(snippets: TypeScriptSnippet[], addToTablet = true, compiledOnly = false): ReadFromCacheResults {
    const translations = new Array<TranslatedSnippet>();
    const remaining = new Array<TypeScriptSnippet>();

    let infusedCount = 0;
    let dirtyCount = 0;
    let dirtySourceCount = 0;
    let dirtyTypesCount = 0;
    let dirtyTranslatorCount = 0;
    let dirtyDidntCompile = 0;

    for (const snippet of snippets) {
      const fromCache = tryReadFromCache(snippet, this.cache, this.fingerprinter, compiledOnly);
      switch (fromCache.type) {
        case 'hit':
          if (addToTablet) {
            this.tablet.addSnippet(fromCache.snippet);
          }
          translations.push(fromCache.snippet);

          infusedCount += fromCache.infused ? 1 : 0;
          break;

        case 'dirty':
          dirtyCount += 1;
          dirtySourceCount += fromCache.dirtySource ? 1 : 0;
          dirtyTranslatorCount += fromCache.dirtyTranslator ? 1 : 0;
          dirtyTypesCount += fromCache.dirtyTypes ? 1 : 0;
          dirtyDidntCompile += fromCache.dirtyDidntCompile ? 1 : 0;

          if (this.allowDirtyTranslations) {
            translations.push(fromCache.translation);
          } else {
            remaining.push(snippet);
          }
          break;

        case 'miss':
          remaining.push(snippet);
          break;
      }
    }

    return {
      translations,
      remaining,
      infusedCount,
      dirtyCount,
      dirtySourceCount,
      dirtyTranslatorCount,
      dirtyTypesCount,
      dirtyDidntCompile,
    };
  }