@domql/utils 2.5.142 → 2.5.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,20 +163,28 @@ const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PU
163
163
  }
164
164
  return clone2;
165
165
  };
166
- const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
166
+ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
167
+ if ((0, import_types.isObjectLike)(obj)) {
168
+ if (visited.has(obj)) {
169
+ return obj;
170
+ }
171
+ visited.add(obj);
172
+ }
167
173
  const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
168
174
  for (const prop in obj) {
169
175
  if (!Object.prototype.hasOwnProperty.call(obj, prop))
170
176
  continue;
171
177
  const objProp = obj[prop];
172
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp))
178
+ if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
173
179
  continue;
180
+ }
174
181
  if ((0, import_types.isObjectLike)(objProp)) {
175
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
182
+ o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
176
183
  } else if ((0, import_types.isFunction)(objProp) && options.window) {
177
184
  o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
178
- } else
185
+ } else {
179
186
  o[prop] = objProp;
187
+ }
180
188
  }
181
189
  return o;
182
190
  };
package/object.js CHANGED
@@ -169,30 +169,46 @@ export const deepClone = (obj, exclude = [], cleanUndefined = false, visited = n
169
169
  /**
170
170
  * Deep cloning of object
171
171
  */
172
- export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) => {
172
+ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}, visited = new WeakSet()) => {
173
+ // Check if the value is object-like before trying to track it in visited
174
+ if (isObjectLike(obj)) {
175
+ if (visited.has(obj)) {
176
+ return obj // Return the object if it was already cloned
177
+ }
178
+ visited.add(obj) // Add to visited set only if it's an object
179
+ }
180
+
173
181
  const o = options.window
174
- ? isArray(obj) ? new options.window.Array([]) : new options.window.Object({})
175
- : isArray(obj) ? [] : {}
182
+ ? isArray(obj)
183
+ ? new options.window.Array([])
184
+ : new options.window.Object({})
185
+ : isArray(obj)
186
+ ? []
187
+ : {}
188
+
176
189
  for (const prop in obj) {
177
190
  if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
178
- // if (prop === 'node' || prop === 'parent' || prop === 'root' || prop === '__element') {
179
- // console.warn('recursive clonning is called', obj)
180
- // continue
181
- // }
191
+
182
192
  const objProp = obj[prop]
193
+
183
194
  if (
184
- excludeFrom.includes(prop) || prop.startsWith('__') ||
195
+ excludeFrom.includes(prop) ||
196
+ prop.startsWith('__') ||
185
197
  (options.cleanUndefined && isUndefined(objProp)) ||
186
198
  (options.cleanNull && isNull(objProp))
187
- ) continue
199
+ ) {
200
+ continue
201
+ }
202
+
188
203
  if (isObjectLike(objProp)) {
189
- // queueMicrotask(() => {
190
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options)
191
- // })
204
+ o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited)
192
205
  } else if (isFunction(objProp) && options.window) {
193
206
  o[prop] = (options.window || window).eval('(' + objProp.toString() + ')')
194
- } else o[prop] = objProp
207
+ } else {
208
+ o[prop] = objProp
209
+ }
195
210
  }
211
+
196
212
  return o
197
213
  }
198
214
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.142",
3
+ "version": "2.5.143",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -25,7 +25,7 @@
25
25
  "build": "yarn build:cjs",
26
26
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
27
27
  },
28
- "gitHead": "65537c9b9a818948e1835b75a5c8a3e79bffdecd",
28
+ "gitHead": "46440d5034244c18657bf272df1bdc3e8ff666c5",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }