"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mutate_exports = {};
__export(mutate_exports, {
  merge: () => merge,
  objectAssign: () => objectAssign,
  objectFreeze: () => objectFreeze
});
module.exports = __toCommonJS(mutate_exports);
var import_sentinels = require("../constants/sentinels");
var import_predicates = require("../arrays/predicates");
var import_error = require("../primordials/error");
var import_reflect = require("../primordials/reflect");
var import_predicates2 = require("./predicates");
// @__NO_SIDE_EFFECTS__
function merge(target, source) {
  if (!(0, import_predicates2.isObject)(target) || !(0, import_predicates2.isObject)(source)) {
    return target;
  }
  const queue = [[target, source]];
  let pos = 0;
  let { length: queueLength } = queue;
  while (pos < queueLength) {
    if (pos === import_sentinels.LOOP_SENTINEL) {
      throw new import_error.ErrorCtor("Detected infinite loop in object crawl of merge");
    }
    const { 0: currentTarget, 1: currentSource } = queue[pos++];
    if (!currentSource || !currentTarget) {
      continue;
    }
    const isSourceArray = (0, import_predicates.isArray)(currentSource);
    const isTargetArray = (0, import_predicates.isArray)(currentTarget);
    if (isSourceArray || isTargetArray) {
      continue;
    }
    const keys = (0, import_reflect.ReflectOwnKeys)(currentSource);
    for (let i = 0, { length } = keys; i < length; i += 1) {
      const key = keys[i];
      const srcVal = currentSource[key];
      const targetVal = currentTarget[key];
      if ((0, import_predicates.isArray)(srcVal)) {
        currentTarget[key] = srcVal;
      } else if ((0, import_predicates2.isObject)(srcVal)) {
        if ((0, import_predicates2.isObject)(targetVal) && !(0, import_predicates.isArray)(targetVal)) {
          queue[queueLength++] = [targetVal, srcVal];
        } else {
          currentTarget[key] = srcVal;
        }
      } else {
        currentTarget[key] = srcVal;
      }
    }
  }
  return target;
}
const objectAssign = Object.assign;
const objectFreeze = Object.freeze;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  merge,
  objectAssign,
  objectFreeze
});
