"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.iterateModulesInChunk = iterateModulesInChunk;

var _ConcatenatedModule = _interopRequireDefault(require("webpack/lib/optimize/ConcatenatedModule"));

var _getChunkModules = require("./utils/getChunkModules");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function iterateModulesInChunk({
  chunk,
  cb,
  compilation
}) {
  let canStopLoop = false;

  function stopLoop() {
    canStopLoop = true;
  }

  function iterateNestedModules(mod) {
    if (mod.resource) {
      cb({
        module: mod,
        stop: stopLoop
      });
      return canStopLoop;
    }

    if (mod instanceof _ConcatenatedModule.default) {
      const {
        modules
      } = mod;
      return Array.from(modules).some(mod => iterateNestedModules(mod));
    }

    return canStopLoop;
  } // eslint-disable-next-line no-restricted-syntax


  for (const mod of (0, _getChunkModules.getChunkModules)(chunk, compilation)) {
    if (iterateNestedModules(mod)) {
      return;
    }
  }
}