deep6 1.1.2 → 1.1.4
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/LICENSE +1 -1
- package/README.md +6 -0
- package/cjs/env.js +23 -67
- package/cjs/index.js +7 -20
- package/cjs/traverse/assemble.js +25 -41
- package/cjs/traverse/clone.js +13 -25
- package/cjs/traverse/deref.js +19 -34
- package/cjs/traverse/preprocess.js +13 -25
- package/cjs/traverse/walk.js +38 -105
- package/cjs/unifiers/matchCondition.js +1 -8
- package/cjs/unifiers/matchInstanceOf.js +1 -8
- package/cjs/unifiers/matchString.js +1 -12
- package/cjs/unifiers/matchTypeOf.js +1 -8
- package/cjs/unifiers/ref.js +1 -8
- package/cjs/unify.js +70 -146
- package/cjs/utils/replaceVars.js +1 -10
- package/package.json +4 -4
package/cjs/unifiers/ref.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _env = require("../env.js");
|
|
9
|
-
|
|
10
8
|
class Ref extends _env.Variable {
|
|
11
9
|
constructor(variable, value) {
|
|
12
10
|
const v = typeof variable == 'string' ? new _env.Variable(variable) : variable;
|
|
@@ -14,17 +12,12 @@ class Ref extends _env.Variable {
|
|
|
14
12
|
this.variable = v;
|
|
15
13
|
this.value = value;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
unify(val, ls, rs, env) {
|
|
19
16
|
ls.push(this.value, this.variable);
|
|
20
17
|
rs.push(val, val);
|
|
21
18
|
return true;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
const ref = (variable, value) => new Ref(variable, value);
|
|
27
|
-
|
|
28
22
|
ref.Ref = Ref;
|
|
29
|
-
var _default = ref;
|
|
30
|
-
exports.default = _default;
|
|
23
|
+
var _default = exports.default = ref;
|
package/cjs/unify.js
CHANGED
|
@@ -3,59 +3,59 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "Env", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _env.
|
|
9
|
+
return _env.Env;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "Unifier", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return _env.
|
|
15
|
+
return _env.Unifier;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "Variable", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return _env.
|
|
21
|
+
return _env.Variable;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "_", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return _env.
|
|
27
|
+
return _env._;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "any", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return _env.
|
|
33
|
+
return _env._;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
exports.isSoft = exports.isOpen = exports.default = void 0;
|
|
37
|
+
Object.defineProperty(exports, "isUnifier", {
|
|
37
38
|
enumerable: true,
|
|
38
39
|
get: function () {
|
|
39
|
-
return _env.
|
|
40
|
+
return _env.isUnifier;
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
43
|
+
Object.defineProperty(exports, "isVariable", {
|
|
43
44
|
enumerable: true,
|
|
44
45
|
get: function () {
|
|
45
|
-
return _env.
|
|
46
|
+
return _env.isVariable;
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
|
-
|
|
49
|
+
exports.soft = exports.open = exports.isWrapped = void 0;
|
|
50
|
+
Object.defineProperty(exports, "variable", {
|
|
49
51
|
enumerable: true,
|
|
50
52
|
get: function () {
|
|
51
|
-
return _env.
|
|
53
|
+
return _env.variable;
|
|
52
54
|
}
|
|
53
55
|
});
|
|
54
|
-
exports.default = exports.isWrapped = exports.isSoft = exports.isOpen = exports.soft = exports.open = void 0;
|
|
55
|
-
|
|
56
56
|
var _env = require("./env.js");
|
|
57
|
-
|
|
58
57
|
// Command
|
|
58
|
+
|
|
59
59
|
class Command {
|
|
60
60
|
constructor(f, l, r, e) {
|
|
61
61
|
this.f = f;
|
|
@@ -63,9 +63,9 @@ class Command {
|
|
|
63
63
|
this.r = r;
|
|
64
64
|
this.e = e;
|
|
65
65
|
}
|
|
66
|
+
}
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
// type wrapper
|
|
69
69
|
|
|
70
70
|
class Wrap extends _env.Unifier {
|
|
71
71
|
constructor(type, o) {
|
|
@@ -73,67 +73,50 @@ class Wrap extends _env.Unifier {
|
|
|
73
73
|
this.type = type;
|
|
74
74
|
this.object = o;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
76
|
unify(val, ls, rs, env) {
|
|
78
77
|
const isWrapped = val instanceof Wrap,
|
|
79
|
-
|
|
78
|
+
value = isWrapped ? val.object : val;
|
|
80
79
|
if (!value || typeof value != 'object' || Array.isArray(this.object) !== Array.isArray(value)) return false;
|
|
81
|
-
|
|
82
80
|
if (Array.isArray(this.object)) {
|
|
83
81
|
if (!Array.isArray(value)) return false;
|
|
84
82
|
return isWrapped ? unifyObjects(this.object, this.type, this, val.object, val.type, val, ls, rs, env) : unifyObjects(this.object, this.type, this, val, env.openArrays ? 'open' : 'exact', null, ls, rs, env);
|
|
85
83
|
}
|
|
86
|
-
|
|
87
84
|
if (typeof Map == 'function' && this.object instanceof Map) {
|
|
88
85
|
if (!(value instanceof Map)) return false;
|
|
89
86
|
return isWrapped ? unifyMaps(this.object, this.type, this, val.object, val.type, val, ls, rs, env) : unifyMaps(this.object, this.type, this, val, env.openMaps ? 'open' : 'exact', null, ls, rs, env);
|
|
90
87
|
}
|
|
91
|
-
|
|
92
88
|
if (typeof Set == 'function' && this.object instanceof Set) {
|
|
93
89
|
if (!(value instanceof Set)) return false;
|
|
94
90
|
return isWrapped ? unifySets(this.object, this.type, this, val.object, val.type, val, ls, rs, env) : unifySets(this.object, this.type, this, val, env.openSets ? 'open' : 'exact', null, ls, rs, env);
|
|
95
91
|
}
|
|
96
|
-
|
|
97
92
|
return isWrapped ? unifyObjects(this.object, this.type, this, val.object, val.type, val, ls, rs, env) : unifyObjects(this.object, this.type, this, val, env.openObjects ? 'open' : 'exact', null, ls, rs, env);
|
|
98
93
|
}
|
|
99
|
-
|
|
100
94
|
}
|
|
101
|
-
|
|
102
95
|
const isWrapped = o => o instanceof Wrap;
|
|
103
|
-
|
|
104
96
|
exports.isWrapped = isWrapped;
|
|
105
|
-
|
|
106
97
|
const open = o => new Wrap('open', o);
|
|
107
|
-
|
|
108
98
|
exports.open = open;
|
|
109
|
-
|
|
110
99
|
const isOpen = o => o instanceof Wrap && o.type === 'open';
|
|
111
|
-
|
|
112
100
|
exports.isOpen = isOpen;
|
|
113
|
-
|
|
114
101
|
const soft = o => new Wrap('soft', o);
|
|
115
|
-
|
|
116
102
|
exports.soft = soft;
|
|
103
|
+
const isSoft = o => o instanceof Wrap && o.type === 'soft';
|
|
117
104
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
// registry of well-known constructors and filters
|
|
121
106
|
exports.isSoft = isSoft;
|
|
122
107
|
const registry = [Date, (l, r) => l instanceof Date && r instanceof Date && l.getTime() == r.getTime(), RegExp, (l, r) => l instanceof RegExp && r instanceof RegExp && l.source == r.source && l.global == r.global && l.multiline == r.multiline && l.ignoreCase == r.ignoreCase],
|
|
123
|
-
|
|
108
|
+
filters = [];
|
|
109
|
+
|
|
110
|
+
// possible well-known constructors
|
|
124
111
|
|
|
125
112
|
const unifyTypedArrays = Type => (l, r, ls, rs, env) => {
|
|
126
113
|
if (!(l instanceof Type) || !(r instanceof Type) || l.length != r.length) return false;
|
|
127
|
-
|
|
128
114
|
for (let i = 0; i < l.length; ++i) {
|
|
129
115
|
if (l[i] != r[i]) return false;
|
|
130
116
|
}
|
|
131
|
-
|
|
132
117
|
return true;
|
|
133
118
|
};
|
|
134
|
-
|
|
135
119
|
const addType = Type => registry.push(Type, unifyTypedArrays(Type));
|
|
136
|
-
|
|
137
120
|
typeof Int8Array == 'function' && addType(Int8Array);
|
|
138
121
|
typeof Uint8Array == 'function' && addType(Uint8Array);
|
|
139
122
|
typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
|
|
@@ -145,51 +128,39 @@ typeof Float32Array == 'function' && addType(Float32Array);
|
|
|
145
128
|
typeof Float64Array == 'function' && addType(Float64Array);
|
|
146
129
|
typeof BigInt64Array == 'function' && addType(BigInt64Array);
|
|
147
130
|
typeof BigUint64Array == 'function' && addType(BigUint64Array);
|
|
148
|
-
|
|
149
131
|
const unifyDataView = (l, r, ls, rs, env) => {
|
|
150
132
|
if (!(l instanceof DataView) || !(r instanceof DataView) || l.byteLength != r.byteLength) return false;
|
|
151
|
-
|
|
152
133
|
for (let i = 0; i < l.byteLength; ++i) {
|
|
153
134
|
if (l.getUint8(i) != r.getUint8(i)) return false;
|
|
154
135
|
}
|
|
155
|
-
|
|
156
136
|
return true;
|
|
157
137
|
};
|
|
158
|
-
|
|
159
138
|
typeof DataView == 'function' && registry.push(DataView, unifyDataView);
|
|
160
|
-
|
|
161
139
|
const unifyArrayBuffer = (l, r, ls, rs, env) => {
|
|
162
140
|
if (!(l instanceof ArrayBuffer) || !(r instanceof ArrayBuffer) || l.byteLength != r.byteLength) return false;
|
|
163
141
|
return unifyTypedArrays(Uint8Array)(new Uint8Array(l), new Uint8Array(r), ls, rs, env);
|
|
164
142
|
};
|
|
165
|
-
|
|
166
143
|
typeof ArrayBuffer == 'function' && typeof Uint8Array == 'function' && registry.push(ArrayBuffer, unifyArrayBuffer);
|
|
167
|
-
|
|
168
144
|
const unifySet = (l, r, ls, rs, env) => {
|
|
169
145
|
if (!(l instanceof Set) || !(r instanceof Set) || l.size != r.size) return false;
|
|
170
|
-
|
|
171
146
|
for (const item of l) {
|
|
172
147
|
if (!r.has(item)) return false;
|
|
173
148
|
}
|
|
174
|
-
|
|
175
149
|
return true;
|
|
176
150
|
};
|
|
177
|
-
|
|
178
151
|
registry.push(Set, unifySet);
|
|
179
|
-
|
|
180
152
|
const unifyMap = (l, r, ls, rs, env) => {
|
|
181
153
|
if (!(l instanceof Map) || !(r instanceof Map) || l.size != r.size) return false;
|
|
182
|
-
|
|
183
154
|
for (const [key, value] of l) {
|
|
184
155
|
if (!r.has(key)) return false;
|
|
185
156
|
ls.push(value);
|
|
186
157
|
rs.push(r.get(key));
|
|
187
158
|
}
|
|
188
|
-
|
|
189
159
|
return true;
|
|
190
160
|
};
|
|
161
|
+
registry.push(Map, unifyMap);
|
|
191
162
|
|
|
192
|
-
|
|
163
|
+
// unification of maps
|
|
193
164
|
|
|
194
165
|
const mapOps = {
|
|
195
166
|
exact: {
|
|
@@ -198,7 +169,6 @@ const mapOps = {
|
|
|
198
169
|
for (const key of l.keys()) {
|
|
199
170
|
if (!r.has(key)) return false;
|
|
200
171
|
}
|
|
201
|
-
|
|
202
172
|
return true;
|
|
203
173
|
}
|
|
204
174
|
},
|
|
@@ -219,7 +189,6 @@ const mapOps = {
|
|
|
219
189
|
for (const [key, value] of this.l) {
|
|
220
190
|
!this.r.has(key) && this.r.set(key, value);
|
|
221
191
|
}
|
|
222
|
-
|
|
223
192
|
for (const [key, value] of this.r) {
|
|
224
193
|
!this.l.has(key) && this.l.set(key, value);
|
|
225
194
|
}
|
|
@@ -227,47 +196,40 @@ const mapOps = {
|
|
|
227
196
|
}
|
|
228
197
|
}
|
|
229
198
|
};
|
|
230
|
-
|
|
231
199
|
mapOps.exact.exact.compare = mapOps.exact.open.compare = mapOps.exact.soft.compare = (l, r, ls, rs) => {
|
|
232
200
|
for (const [key, value] of r) {
|
|
233
201
|
if (!l.has(key)) return false;
|
|
234
202
|
ls.push(l.get(key));
|
|
235
203
|
rs.push(value);
|
|
236
204
|
}
|
|
237
|
-
|
|
238
205
|
return true;
|
|
239
206
|
};
|
|
240
|
-
|
|
241
207
|
mapOps.open.open.compare = mapOps.open.soft.compare = mapOps.soft.soft.compare = (l, r, ls, rs) => {
|
|
242
208
|
for (const [key, value] of r) {
|
|
243
209
|
if (!l.has(key)) continue;
|
|
244
210
|
ls.push(l.get(key));
|
|
245
211
|
rs.push(value);
|
|
246
212
|
}
|
|
247
|
-
|
|
248
213
|
return true;
|
|
249
214
|
};
|
|
250
|
-
|
|
251
215
|
mapOps.exact.soft.update = mapOps.open.soft.update = function () {
|
|
252
216
|
for (const [key, value] of this.l) {
|
|
253
217
|
!this.r.has(key) && this.r.set(key, value);
|
|
254
218
|
}
|
|
255
219
|
};
|
|
256
|
-
|
|
257
220
|
const unifyMaps = (l, lt, lm, r, rt, rm, ls, rs, env) => {
|
|
258
221
|
const ols = ls;
|
|
259
|
-
|
|
260
222
|
if (lt > rt) {
|
|
261
223
|
[l, lt, lm, ls, r, rt, rm, rs] = [r, rt, rm, rs, l, lt, lm, ls];
|
|
262
224
|
}
|
|
263
|
-
|
|
264
225
|
const ops = mapOps[lt][rt];
|
|
265
226
|
if (ops.precheck && !ops.precheck(l, r)) return false;
|
|
266
227
|
if (ops.fix && rm) ols.push(new Command(ops.fix, rm));
|
|
267
228
|
if (ops.update) ols.push(new Command(ops.update, l, r));
|
|
268
229
|
return ops.compare(l, r, ls, rs, env);
|
|
269
|
-
};
|
|
230
|
+
};
|
|
270
231
|
|
|
232
|
+
// unification of sets
|
|
271
233
|
|
|
272
234
|
const setOps = {
|
|
273
235
|
exact: {
|
|
@@ -276,7 +238,6 @@ const setOps = {
|
|
|
276
238
|
for (const key of l) {
|
|
277
239
|
if (!r.has(key)) return false;
|
|
278
240
|
}
|
|
279
|
-
|
|
280
241
|
return true;
|
|
281
242
|
}
|
|
282
243
|
},
|
|
@@ -297,7 +258,6 @@ const setOps = {
|
|
|
297
258
|
for (const key of this.l) {
|
|
298
259
|
this.r.add(key);
|
|
299
260
|
}
|
|
300
|
-
|
|
301
261
|
for (const key of this.r) {
|
|
302
262
|
this.l.add(key);
|
|
303
263
|
}
|
|
@@ -305,29 +265,25 @@ const setOps = {
|
|
|
305
265
|
}
|
|
306
266
|
}
|
|
307
267
|
};
|
|
308
|
-
|
|
309
268
|
setOps.exact.exact.compare = setOps.exact.open.compare = setOps.exact.soft.compare = setOps.open.open.compare = setOps.open.soft.compare = setOps.soft.soft.compare = () => true;
|
|
310
|
-
|
|
311
269
|
setOps.exact.soft.update = setOps.open.soft.update = function () {
|
|
312
270
|
for (const key of this.l) {
|
|
313
271
|
this.r.add(key);
|
|
314
272
|
}
|
|
315
273
|
};
|
|
316
|
-
|
|
317
274
|
const unifySets = (l, lt, lm, r, rt, rm, ls, rs, env) => {
|
|
318
275
|
const ols = ls;
|
|
319
|
-
|
|
320
276
|
if (lt > rt) {
|
|
321
277
|
[l, lt, lm, ls, r, rt, rm, rs] = [r, rt, rm, rs, l, lt, lm, ls];
|
|
322
278
|
}
|
|
323
|
-
|
|
324
279
|
const ops = setOps[lt][rt];
|
|
325
280
|
if (ops.precheck && !ops.precheck(l, r)) return false;
|
|
326
281
|
if (ops.fix && rm) ols.push(new Command(ops.fix, rm));
|
|
327
282
|
if (ops.update) ols.push(new Command(ops.update, l, r));
|
|
328
283
|
return ops.compare(l, r, ls, rs, env);
|
|
329
|
-
};
|
|
284
|
+
};
|
|
330
285
|
|
|
286
|
+
// unification of objects
|
|
331
287
|
|
|
332
288
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
333
289
|
const objectOps = {
|
|
@@ -335,14 +291,12 @@ const objectOps = {
|
|
|
335
291
|
exact: {
|
|
336
292
|
precheck: (l, r, env) => {
|
|
337
293
|
let lKeys = Object.keys(l),
|
|
338
|
-
|
|
294
|
+
rKeys = Object.keys(r);
|
|
339
295
|
if (lKeys.length != rKeys.length) return false;
|
|
340
|
-
|
|
341
296
|
if (env.symbols) {
|
|
342
297
|
lKeys = lKeys.concat(Object.getOwnPropertySymbols(l));
|
|
343
298
|
rKeys = rKeys.concat(Object.getOwnPropertySymbols(r));
|
|
344
299
|
}
|
|
345
|
-
|
|
346
300
|
if (lKeys.length != rKeys.length) return false;
|
|
347
301
|
return lKeys.every(k => hasOwnProperty.call(r, k));
|
|
348
302
|
}
|
|
@@ -363,14 +317,11 @@ const objectOps = {
|
|
|
363
317
|
update: function () {
|
|
364
318
|
let keys = Object.keys(this.l);
|
|
365
319
|
if (this.e.symbols) keys = keys.concat(Object.getOwnPropertySymbols(this.l));
|
|
366
|
-
|
|
367
320
|
for (const k of keys) {
|
|
368
321
|
!hasOwnProperty.call(this.r, k) && Object.defineProperty(this.r, k, Object.getOwnPropertyDescriptor(this.l, k));
|
|
369
322
|
}
|
|
370
|
-
|
|
371
323
|
keys = Object.keys(this.r);
|
|
372
324
|
if (this.e.symbols) keys = keys.concat(Object.getOwnPropertySymbols(this.r));
|
|
373
|
-
|
|
374
325
|
for (const k of keys) {
|
|
375
326
|
!hasOwnProperty.call(this.l, k) && Object.defineProperty(this.l, k, Object.getOwnPropertyDescriptor(this.r, k));
|
|
376
327
|
}
|
|
@@ -378,7 +329,6 @@ const objectOps = {
|
|
|
378
329
|
}
|
|
379
330
|
}
|
|
380
331
|
};
|
|
381
|
-
|
|
382
332
|
objectOps.exact.exact.compare = objectOps.exact.open.compare = objectOps.exact.soft.compare = (l, r, ls, rs, env) => {
|
|
383
333
|
let keys = Object.keys(r);
|
|
384
334
|
if (env.symbols) keys = keys.concat(Object.getOwnPropertySymbols(r));
|
|
@@ -388,162 +338,136 @@ objectOps.exact.exact.compare = objectOps.exact.open.compare = objectOps.exact.s
|
|
|
388
338
|
rs.push(r[k]);
|
|
389
339
|
return true;
|
|
390
340
|
}
|
|
391
|
-
|
|
392
341
|
return false;
|
|
393
342
|
});
|
|
394
343
|
};
|
|
395
|
-
|
|
396
344
|
objectOps.open.open.compare = objectOps.open.soft.compare = objectOps.soft.soft.compare = (l, r, ls, rs, env) => {
|
|
397
345
|
let keys = Object.keys(r);
|
|
398
346
|
if (env.symbols) keys = keys.concat(Object.getOwnPropertySymbols(r));
|
|
399
|
-
|
|
400
347
|
for (const k of keys) {
|
|
401
348
|
if (hasOwnProperty.call(l, k)) {
|
|
402
349
|
ls.push(l[k]);
|
|
403
350
|
rs.push(r[k]);
|
|
404
351
|
}
|
|
405
352
|
}
|
|
406
|
-
|
|
407
353
|
return true;
|
|
408
354
|
};
|
|
409
|
-
|
|
410
355
|
objectOps.exact.soft.update = objectOps.open.soft.update = function () {
|
|
411
356
|
let keys = Object.keys(this.l);
|
|
412
357
|
if (this.e.symbols) keys = keys.concat(Object.getOwnPropertySymbols(this.l));
|
|
413
|
-
|
|
414
358
|
for (const k of keys) {
|
|
415
359
|
!hasOwnProperty.call(this.r, k) && Object.defineProperty(this.r, k, Object.getOwnPropertyDescriptor(this.l, k));
|
|
416
360
|
}
|
|
417
361
|
};
|
|
418
|
-
|
|
419
362
|
const unifyObjects = (l, lt, lm, r, rt, rm, ls, rs, env) => {
|
|
420
363
|
const ols = ls;
|
|
421
|
-
|
|
422
364
|
if (lt > rt) {
|
|
423
365
|
[l, lt, lm, ls, r, rt, rm, rs] = [r, rt, rm, rs, l, lt, lm, ls];
|
|
424
366
|
}
|
|
425
|
-
|
|
426
367
|
const ops = objectOps[lt][rt];
|
|
427
368
|
if (ops.precheck && !ops.precheck(l, r, env)) return false;
|
|
428
369
|
if (ops.fix && rm) ols.push(new Command(ops.fix, rm, null, env));
|
|
429
370
|
if (ops.update) ols.push(new Command(ops.update, l, r, env));
|
|
430
371
|
return ops.compare(l, r, ls, rs, env);
|
|
431
|
-
};
|
|
372
|
+
};
|
|
432
373
|
|
|
374
|
+
// unification
|
|
433
375
|
|
|
434
376
|
const unify = (l, r, env, options) => {
|
|
435
377
|
if (env && !(env instanceof _env.Env)) {
|
|
436
378
|
options = env;
|
|
437
379
|
env = null;
|
|
438
380
|
}
|
|
439
|
-
|
|
440
381
|
if (!env) {
|
|
441
382
|
env = new _env.Env();
|
|
442
383
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
384
|
+
env = Object.assign(env, options);
|
|
385
|
+
// options: openObjects, openArrays, openMaps, openSets, circular, loose, ignoreFunctions, signedZero, symbols.
|
|
446
386
|
const ls = [l],
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
387
|
+
rs = [r],
|
|
388
|
+
lSeen = new Map(),
|
|
389
|
+
rSeen = new Map();
|
|
451
390
|
main: while (ls.length) {
|
|
452
391
|
// perform a command, or extract a pair
|
|
453
392
|
l = ls.pop();
|
|
454
|
-
|
|
455
393
|
if (l instanceof Command) {
|
|
456
394
|
l.f();
|
|
457
395
|
continue;
|
|
458
396
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
397
|
+
r = rs.pop();
|
|
398
|
+
// direct equality
|
|
462
399
|
if (l === r) {
|
|
463
400
|
if (env.circular && l && typeof l == 'object' && lSeen.has(l) ^ rSeen.has(r)) return null;
|
|
464
401
|
if (env.signedZero && l === 0 && 1 / l !== 1 / r) return null;
|
|
465
402
|
continue;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
403
|
+
}
|
|
404
|
+
// anyvar
|
|
405
|
+
if (l === _env._ || r === _env._) continue;
|
|
406
|
+
// process variables (variables have priority)
|
|
471
407
|
if (l instanceof _env.Variable) {
|
|
472
408
|
if (l.unify(r, ls, rs, env)) continue;
|
|
473
409
|
return null;
|
|
474
410
|
}
|
|
475
|
-
|
|
476
411
|
if (r instanceof _env.Variable) {
|
|
477
412
|
if (r.unify(l, ls, rs, env)) continue;
|
|
478
413
|
return null;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
414
|
+
}
|
|
415
|
+
// process circular dependencies
|
|
482
416
|
if (env.circular) {
|
|
483
417
|
const lIndex = lSeen.get(l);
|
|
484
|
-
|
|
485
418
|
if (typeof lIndex == 'number') {
|
|
486
419
|
if (lIndex === rSeen.get(r)) continue main;
|
|
487
420
|
return null;
|
|
488
421
|
} else {
|
|
489
422
|
if (rSeen.has(r)) return null;
|
|
490
423
|
}
|
|
491
|
-
|
|
492
424
|
l && typeof l == 'object' && lSeen.set(l, lSeen.size);
|
|
493
425
|
r && typeof r == 'object' && rSeen.set(r, rSeen.size);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
426
|
+
}
|
|
427
|
+
// invoke custom unifiers
|
|
497
428
|
if (l instanceof _env.Unifier) {
|
|
498
429
|
if (l.unify(r, ls, rs, env)) continue;
|
|
499
430
|
return null;
|
|
500
431
|
}
|
|
501
|
-
|
|
502
432
|
if (r instanceof _env.Unifier) {
|
|
503
433
|
if (r.unify(l, ls, rs, env)) continue;
|
|
504
434
|
return null;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
435
|
+
}
|
|
436
|
+
// process loose equality for non-objects and nulls
|
|
437
|
+
if (env.loose && !(l && r && typeof l == 'object' && typeof r == 'object') && l == r) continue main;
|
|
438
|
+
// check rough types
|
|
439
|
+
if (typeof l != typeof r) return null;
|
|
440
|
+
// reject unequal functions
|
|
441
|
+
if (typeof l == 'function' && env.ignoreFunctions) continue;
|
|
442
|
+
// special case: NaN
|
|
443
|
+
if (typeof l == 'number' && isNaN(l) && isNaN(r)) continue;
|
|
444
|
+
// cut off impossible combinations
|
|
445
|
+
if (typeof l != 'object' || !l || !r) return null;
|
|
446
|
+
// process registered constructors
|
|
518
447
|
const registry = unify.registry;
|
|
519
|
-
|
|
520
448
|
for (let i = 0; i < registry.length; i += 2) {
|
|
521
449
|
if (l instanceof registry[i] || r instanceof registry[i]) {
|
|
522
450
|
if (registry[i + 1](l, r, ls, rs, env)) continue main;
|
|
523
451
|
return null;
|
|
524
452
|
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
453
|
+
}
|
|
454
|
+
// process registered filters
|
|
528
455
|
const filters = unify.filters;
|
|
529
|
-
|
|
530
456
|
for (let i = 0; i < filters.length; i += 2) {
|
|
531
457
|
if (filters[i](l, r)) {
|
|
532
458
|
if (filters[i + 1](l, r, ls, rs, env)) continue main;
|
|
533
459
|
return null;
|
|
534
460
|
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
461
|
+
}
|
|
462
|
+
// process naked objects and arrays
|
|
538
463
|
const objectType = env.openObjects ? 'open' : 'exact';
|
|
539
464
|
if (!unifyObjects(l, objectType, null, r, objectType, null, ls, rs, env)) return null;
|
|
540
465
|
}
|
|
541
|
-
|
|
542
466
|
return env;
|
|
543
|
-
};
|
|
467
|
+
};
|
|
544
468
|
|
|
469
|
+
// exports
|
|
545
470
|
|
|
546
471
|
unify.registry = registry;
|
|
547
472
|
unify.filters = filters;
|
|
548
|
-
var _default = unify;
|
|
549
|
-
exports.default = _default;
|
|
473
|
+
var _default = exports.default = unify;
|
package/cjs/utils/replaceVars.js
CHANGED
|
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _env = require("../env.js");
|
|
9
|
-
|
|
10
8
|
const replaceVars = env => (strings, ...vars) => {
|
|
11
9
|
let buffer = strings[0];
|
|
12
|
-
|
|
13
10
|
for (let i = 0; i < vars.length;) {
|
|
14
11
|
const v = vars[i];
|
|
15
|
-
|
|
16
12
|
if ((0, _env.isVariable)(v)) {
|
|
17
13
|
buffer += v.get(env);
|
|
18
14
|
} else switch (typeof v) {
|
|
@@ -21,17 +17,12 @@ const replaceVars = env => (strings, ...vars) => {
|
|
|
21
17
|
case 'symbol':
|
|
22
18
|
buffer += env.values[v];
|
|
23
19
|
break;
|
|
24
|
-
|
|
25
20
|
default:
|
|
26
21
|
buffer += v;
|
|
27
22
|
break;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
buffer += strings[++i];
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
return buffer;
|
|
34
27
|
};
|
|
35
|
-
|
|
36
|
-
var _default = replaceVars;
|
|
37
|
-
exports.default = _default;
|
|
28
|
+
var _default = exports.default = replaceVars;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep6",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "No dependency mini-library: unification, deep equivalence, deep cloning.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -114,9 +114,9 @@
|
|
|
114
114
|
"author": "Eugene Lazutkin <eugene.lazutkin@gmail.com> (https://www.lazutkin.com/)",
|
|
115
115
|
"license": "BSD-3-Clause",
|
|
116
116
|
"devDependencies": {
|
|
117
|
-
"@babel/cli": "^7.
|
|
118
|
-
"@babel/core": "^7.
|
|
119
|
-
"@babel/preset-env": "^7.
|
|
117
|
+
"@babel/cli": "^7.24.7",
|
|
118
|
+
"@babel/core": "^7.24.7",
|
|
119
|
+
"@babel/preset-env": "^7.24.7"
|
|
120
120
|
},
|
|
121
121
|
"files": [
|
|
122
122
|
"/src",
|