code: function loadModuleFromNodeModules(moduleName, directory, failedLookupLocations, state, checkOneLevel) {
          directory = ts.normalizeSlashes(directory);
          while (true) {
              var baseName = ts.getBaseFileName(directory);
              if (baseName !== "node_modules") {
                  // Try to load source from the package
                  var packageResult = loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state);
                  if (packageResult && ts.hasTypeScriptFileExtension(packageResult)) {
                      // Always prefer a TypeScript (.ts, .tsx, .d.ts) file shipped with the package
                      return packageResult;
                  }
                  else {
                      // Else prefer a types package over non-TypeScript results (e.g. JavaScript files)
                      var typesResult = loadModuleFromNodeModulesFolder(ts.combinePaths("@types", moduleName), directory, failedLookupLocations, state);
                      if (typesResult || packageResult) {
                          return typesResult || packageResult;
                      }
                  }
              }
              var parentPath = ts.getDirectoryPath(directory);
              if (parentPath === directory || checkOneLevel) {
                  break;
              }
              directory = parentPath;
          }
          return undefined;
      }
docs: /* @internal