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