bunshin-clone 1.8.11 → 1.8.12
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.
- package/dist/index.cjs +30 -13
- package/dist/index.js +30 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -81,11 +81,15 @@ function clone(value, settings, refs) {
|
|
|
81
81
|
refs.set(value, value);
|
|
82
82
|
return value;
|
|
83
83
|
}
|
|
84
|
+
var IS_ENUMERABLE = Object.prototype.propertyIsEnumerable;
|
|
85
|
+
var OWN_DESCS = Object.getOwnPropertyDescriptors;
|
|
86
|
+
var OWN_NAMES = Object.getOwnPropertyNames;
|
|
87
|
+
var OWN_SYMBOLS = Object.getOwnPropertySymbols;
|
|
84
88
|
function cloneWithDescriptors(object, settings, refs) {
|
|
85
89
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
86
90
|
refs.set(object, result);
|
|
87
|
-
const descs =
|
|
88
|
-
for (const key of
|
|
91
|
+
const descs = OWN_DESCS(object);
|
|
92
|
+
for (const key of OWN_NAMES(object)) {
|
|
89
93
|
if (isUnsafeKey(key)) {
|
|
90
94
|
continue;
|
|
91
95
|
}
|
|
@@ -101,6 +105,21 @@ function cloneWithDescriptors(object, settings, refs) {
|
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
108
|
+
if (settings.preserveSymbolKeys) {
|
|
109
|
+
for (const symbol of OWN_SYMBOLS(object)) {
|
|
110
|
+
const desc = { ...descs[symbol] };
|
|
111
|
+
if ("value" in desc) {
|
|
112
|
+
desc.value = clone(desc.value, settings, refs);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
Object.defineProperty(result, symbol, desc);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (settings.strictDescriptors) {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
104
123
|
return result;
|
|
105
124
|
}
|
|
106
125
|
function cloneArray(array, settings, refs) {
|
|
@@ -111,19 +130,17 @@ function cloneArray(array, settings, refs) {
|
|
|
111
130
|
function clonePlainObject(object, settings, refs) {
|
|
112
131
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
113
132
|
refs.set(object, result);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
result[key] = clone(object[key], settings, refs);
|
|
133
|
+
for (const key of Object.keys(object)) {
|
|
134
|
+
if (isUnsafeKey(key)) {
|
|
135
|
+
continue;
|
|
120
136
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
result[key] = clone(object[key], settings, refs);
|
|
138
|
+
}
|
|
139
|
+
if (settings.preserveSymbolKeys) {
|
|
140
|
+
for (const symbol of OWN_SYMBOLS(object)) {
|
|
141
|
+
if (IS_ENUMERABLE.call(object, symbol)) {
|
|
142
|
+
result[symbol] = clone(object[symbol], settings, refs);
|
|
125
143
|
}
|
|
126
|
-
result[key] = clone(object[key], settings, refs);
|
|
127
144
|
}
|
|
128
145
|
}
|
|
129
146
|
return result;
|
package/dist/index.js
CHANGED
|
@@ -79,11 +79,15 @@ function clone(value, settings, refs) {
|
|
|
79
79
|
refs.set(value, value);
|
|
80
80
|
return value;
|
|
81
81
|
}
|
|
82
|
+
var IS_ENUMERABLE = Object.prototype.propertyIsEnumerable;
|
|
83
|
+
var OWN_DESCS = Object.getOwnPropertyDescriptors;
|
|
84
|
+
var OWN_NAMES = Object.getOwnPropertyNames;
|
|
85
|
+
var OWN_SYMBOLS = Object.getOwnPropertySymbols;
|
|
82
86
|
function cloneWithDescriptors(object, settings, refs) {
|
|
83
87
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
84
88
|
refs.set(object, result);
|
|
85
|
-
const descs =
|
|
86
|
-
for (const key of
|
|
89
|
+
const descs = OWN_DESCS(object);
|
|
90
|
+
for (const key of OWN_NAMES(object)) {
|
|
87
91
|
if (isUnsafeKey(key)) {
|
|
88
92
|
continue;
|
|
89
93
|
}
|
|
@@ -99,6 +103,21 @@ function cloneWithDescriptors(object, settings, refs) {
|
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
}
|
|
106
|
+
if (settings.preserveSymbolKeys) {
|
|
107
|
+
for (const symbol of OWN_SYMBOLS(object)) {
|
|
108
|
+
const desc = { ...descs[symbol] };
|
|
109
|
+
if ("value" in desc) {
|
|
110
|
+
desc.value = clone(desc.value, settings, refs);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
Object.defineProperty(result, symbol, desc);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (settings.strictDescriptors) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
102
121
|
return result;
|
|
103
122
|
}
|
|
104
123
|
function cloneArray(array, settings, refs) {
|
|
@@ -109,19 +128,17 @@ function cloneArray(array, settings, refs) {
|
|
|
109
128
|
function clonePlainObject(object, settings, refs) {
|
|
110
129
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
111
130
|
refs.set(object, result);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
result[key] = clone(object[key], settings, refs);
|
|
131
|
+
for (const key of Object.keys(object)) {
|
|
132
|
+
if (isUnsafeKey(key)) {
|
|
133
|
+
continue;
|
|
118
134
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
result[key] = clone(object[key], settings, refs);
|
|
136
|
+
}
|
|
137
|
+
if (settings.preserveSymbolKeys) {
|
|
138
|
+
for (const symbol of OWN_SYMBOLS(object)) {
|
|
139
|
+
if (IS_ENUMERABLE.call(object, symbol)) {
|
|
140
|
+
result[symbol] = clone(object[symbol], settings, refs);
|
|
123
141
|
}
|
|
124
|
-
result[key] = clone(object[key], settings, refs);
|
|
125
142
|
}
|
|
126
143
|
}
|
|
127
144
|
return result;
|