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.
Files changed (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +44 -38
  3. package/llms-full.txt +371 -0
  4. package/llms.txt +154 -0
  5. package/package.json +31 -109
  6. package/src/env.d.ts +174 -0
  7. package/src/env.js +4 -4
  8. package/src/index.d.ts +86 -0
  9. package/src/index.js +10 -7
  10. package/src/traverse/assemble.d.ts +59 -0
  11. package/src/traverse/assemble.js +4 -3
  12. package/src/traverse/clone.d.ts +57 -0
  13. package/src/traverse/clone.js +4 -2
  14. package/src/traverse/deref.d.ts +59 -0
  15. package/src/traverse/deref.js +3 -2
  16. package/src/traverse/preprocess.d.ts +65 -0
  17. package/src/traverse/preprocess.js +2 -1
  18. package/src/traverse/walk.d.ts +219 -0
  19. package/src/traverse/walk.js +9 -4
  20. package/src/unifiers/matchCondition.d.ts +45 -0
  21. package/src/unifiers/matchCondition.js +1 -0
  22. package/src/unifiers/matchInstanceOf.d.ts +37 -0
  23. package/src/unifiers/matchInstanceOf.js +1 -0
  24. package/src/unifiers/matchString.d.ts +56 -0
  25. package/src/unifiers/matchString.js +1 -0
  26. package/src/unifiers/matchTypeOf.d.ts +37 -0
  27. package/src/unifiers/matchTypeOf.js +1 -0
  28. package/src/unifiers/ref.d.ts +52 -0
  29. package/src/unifiers/ref.js +1 -0
  30. package/src/unify.d.ts +95 -0
  31. package/src/unify.js +130 -66
  32. package/src/utils/replaceVars.d.ts +25 -0
  33. package/src/utils/replaceVars.js +23 -19
  34. package/cjs/env.js +0 -227
  35. package/cjs/index.js +0 -57
  36. package/cjs/package.json +0 -1
  37. package/cjs/traverse/assemble.js +0 -145
  38. package/cjs/traverse/clone.js +0 -94
  39. package/cjs/traverse/deref.js +0 -102
  40. package/cjs/traverse/preprocess.js +0 -96
  41. package/cjs/traverse/walk.js +0 -330
  42. package/cjs/unifiers/matchCondition.js +0 -25
  43. package/cjs/unifiers/matchInstanceOf.js +0 -25
  44. package/cjs/unifiers/matchString.js +0 -49
  45. package/cjs/unifiers/matchTypeOf.js +0 -25
  46. package/cjs/unifiers/ref.js +0 -30
  47. package/cjs/unify.js +0 -549
  48. package/cjs/utils/replaceVars.js +0 -37
package/cjs/env.js DELETED
@@ -1,227 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.any = exports._ = exports.isVariable = exports.variable = exports.Variable = exports.isUnifier = exports.Unifier = exports.Env = void 0;
7
- // Env
8
- const keyDepth = Symbol.for('deep6.env.depth');
9
-
10
- const collectSymbols = object => {
11
- const symbols = new Set();
12
-
13
- while (object && typeof object == 'object') {
14
- Object.getOwnPropertySymbols(object).forEach(symbol => symbols.add(symbol));
15
- object = Object.getPrototypeOf(object);
16
- }
17
-
18
- symbols.delete(keyDepth);
19
- return Array.from(symbols);
20
- };
21
-
22
- const ensure = (object, depth) => {
23
- while (object[keyDepth] > depth) object = object.getPrototypeOf(object);
24
-
25
- if (object[keyDepth] < depth) {
26
- object = Object.create(object);
27
- object[keyDepth] = depth;
28
- }
29
-
30
- return object;
31
- };
32
-
33
- class Env {
34
- constructor() {
35
- this.variables = Object.create(null);
36
- this.values = Object.create(null);
37
- this.depth = this.variables[keyDepth] = this.values[keyDepth] = 0;
38
- }
39
-
40
- push() {
41
- ++this.depth;
42
- }
43
-
44
- pop() {
45
- if (this.depth < 1) throw new Error('attempt to pop a frame with an empty stack');
46
- --this.depth;
47
-
48
- while (this.variables[keyDepth] > this.depth) this.variables = Object.getPrototypeOf(this.variables);
49
-
50
- while (this.values[keyDepth] > this.depth) this.values = Object.getPrototypeOf(this.values);
51
- }
52
-
53
- revert(depth) {
54
- if (this.depth < depth) throw new Error('attempt to revert a stack to a higher depth');
55
-
56
- while (this.variables[keyDepth] > depth) this.variables = Object.getPrototypeOf(this.variables);
57
-
58
- while (this.values[keyDepth] > depth) this.values = Object.getPrototypeOf(this.values);
59
-
60
- this.depth = depth;
61
- }
62
-
63
- bindVar(name1, name2) {
64
- const depth = this.depth,
65
- vars = this.variables = ensure(this.variables, depth);
66
- let u1 = vars[name1],
67
- u2 = vars[name2];
68
- u1 && (u1 = vars[name1] = ensure(u1, depth));
69
- u2 && (u2 = vars[name2] = ensure(u2, depth));
70
-
71
- if (u1) {
72
- if (u2) {
73
- for (const k in u2) {
74
- vars[k] = u1;
75
- u1[k] = 1;
76
- }
77
-
78
- collectSymbols(u2).forEach(k => (vars[k] = u1, u1[k] = 1));
79
- } else {
80
- vars[name2] = u1;
81
- u1[name2] = 1;
82
- }
83
- } else {
84
- if (u2) {
85
- vars[name1] = u2;
86
- u2[name1] = 1;
87
- } else {
88
- u2 = Object.create(null);
89
- u2[keyDepth] = depth;
90
- vars[name1] = vars[name2] = u2;
91
- u2[name1] = u2[name2] = 1;
92
- }
93
- }
94
- }
95
-
96
- bindVal(name, val) {
97
- const depth = this.depth,
98
- values = this.values = ensure(this.values, depth),
99
- vars = this.variables = ensure(this.variables, depth);
100
- let u = vars[name];
101
- u && (u = vars[name] = ensure(u, depth));
102
-
103
- if (u) {
104
- for (const k in u) {
105
- values[k] = val;
106
- vars[k] = null;
107
- }
108
-
109
- collectSymbols(u).forEach(k => (values[k] = val, vars[k] = null));
110
- } else {
111
- values[name] = val;
112
- }
113
- } // helpers
114
-
115
-
116
- isBound(name) {
117
- return name in env.values;
118
- }
119
-
120
- isAlias(name1, name2) {
121
- const u = env.variables[name2];
122
- return u && u[name1] === 1;
123
- }
124
-
125
- get(name) {
126
- return env.values[name];
127
- } // debugging
128
-
129
-
130
- getAllValues() {
131
- const values = this.values,
132
- result = collectSymbols(values).map(k => ({
133
- name: k,
134
- value: values[k]
135
- }));
136
-
137
- for (const k in values) {
138
- result.push({
139
- name: k,
140
- value: values[k]
141
- });
142
- }
143
-
144
- return result;
145
- }
146
-
147
- } // Custom unifier
148
-
149
-
150
- exports.Env = Env;
151
-
152
- class Unifier {}
153
-
154
- exports.Unifier = Unifier;
155
-
156
- const isUnifier = x => x instanceof Unifier; // Unifier should define a method:
157
- // unify(val, ls, rs, env):
158
- // val is a value we are unifying with
159
- // ls is a stack of left arguments
160
- // rs is a stack of right arguments corresponding to ls
161
- // env is an environment
162
- // the result should be true/false for success/failure
163
- // AnyVar
164
-
165
-
166
- exports.isUnifier = isUnifier;
167
-
168
- const _ = Symbol.for('deep6.any'),
169
- any = _; // Variable
170
-
171
-
172
- exports.any = any;
173
- exports._ = _;
174
-
175
- class Variable extends Unifier {
176
- constructor(name) {
177
- super();
178
- this.name = name || Symbol();
179
- }
180
-
181
- isBound(env) {
182
- return this.name in env.values;
183
- }
184
-
185
- isAlias(name, env) {
186
- const u = env.variables[this.name];
187
- return u && u[name instanceof Variable ? name.name : name] === 1;
188
- }
189
-
190
- get(env) {
191
- return env.values[this.name];
192
- }
193
-
194
- unify(val, ls, rs, env) {
195
- if (this.name in env.values) {
196
- // isBound
197
- ls.push(env.values[this.name]);
198
- rs.push(val);
199
- return true;
200
- }
201
-
202
- if (val === _ || val === this) return true;
203
-
204
- if (val instanceof Variable) {
205
- if (val.name in env.values) {
206
- // isBound
207
- env.bindVal(this.name, env.values[val.name]);
208
- return true;
209
- }
210
-
211
- env.bindVar(this.name, val.name);
212
- return true;
213
- }
214
-
215
- env.bindVal(this.name, val);
216
- return true;
217
- }
218
-
219
- }
220
-
221
- exports.Variable = Variable;
222
-
223
- const isVariable = x => x instanceof Variable,
224
- variable = name => new Variable(name);
225
-
226
- exports.variable = variable;
227
- exports.isVariable = isVariable;
package/cjs/index.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "any", {
7
- enumerable: true,
8
- get: function () {
9
- return _env.any;
10
- }
11
- });
12
- Object.defineProperty(exports, "_", {
13
- enumerable: true,
14
- get: function () {
15
- return _env._;
16
- }
17
- });
18
- exports.default = exports.isShape = exports.match = exports.clone = exports.equal = void 0;
19
-
20
- var _env = require("./env.js");
21
-
22
- var _unify = _interopRequireDefault(require("./unify.js"));
23
-
24
- var _clone = _interopRequireDefault(require("./traverse/clone.js"));
25
-
26
- var _preprocess = _interopRequireDefault(require("./traverse/preprocess.js"));
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- const defaultOptions = {
31
- circular: true
32
- };
33
-
34
- const equal = (a, b, options = defaultOptions) => !!(0, _unify.default)(a, b, null, options);
35
-
36
- exports.equal = equal;
37
- const defaultMatchOptions = {
38
- openObjects: true,
39
- openMaps: true,
40
- openSets: true,
41
- circular: true
42
- };
43
-
44
- const match = (object, pattern, options = defaultMatchOptions) => !!(0, _unify.default)(object, (0, _preprocess.default)(pattern, options), null, {
45
- circular: options.circular,
46
- symbols: options.symbols,
47
- loose: options.loose,
48
- ignoreFunctions: options.ignoreFunctions
49
- });
50
-
51
- exports.isShape = exports.match = match;
52
-
53
- const clone = (a, options = defaultOptions) => (0, _clone.default)(a, null, options);
54
-
55
- exports.clone = clone;
56
- var _default = equal;
57
- exports.default = _default;
package/cjs/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,145 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.filters = exports.registry = void 0;
7
-
8
- var _unify = require("../unify.js");
9
-
10
- var _walk = _interopRequireWildcard(require("./walk.js"));
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- const empty = {};
17
-
18
- function postProcess(context) {
19
- const stackOut = context.stackOut,
20
- s = this.s,
21
- {
22
- descriptors,
23
- keys
24
- } = (0, _walk.getObjectData)(s, context);
25
- let j = stackOut.length - 1;
26
- const result = keys.some(k => {
27
- const d = descriptors[k];
28
- if (d.get || d.set) return false;
29
- const t = stackOut[j--];
30
- return typeof t == 'number' && isNaN(t) ? typeof s[k] == 'number' && !isNaN(s[k]) : s[k] !== t;
31
- });
32
-
33
- if (result) {
34
- (0, _walk.buildNewObject)(s, descriptors, keys, stackOut);
35
- } else {
36
- (0, _walk.replaceObject)(j, s, stackOut);
37
- }
38
- }
39
-
40
- function postProcessSeen(context) {
41
- const stackOut = context.stackOut,
42
- s = this.s,
43
- {
44
- descriptors,
45
- keys
46
- } = (0, _walk.getObjectData)(s, context);
47
- let j = stackOut.length - 1;
48
- const result = keys.some(k => {
49
- const d = descriptors[k];
50
- if (d.get || d.set) return false;
51
- const t = stackOut[j--];
52
- return typeof t == 'number' && isNaN(t) ? typeof s[k] == 'number' && !isNaN(s[k]) : s[k] !== t;
53
- });
54
-
55
- if (result) {
56
- (0, _walk.postObjectCircular)(s, descriptors, keys, context);
57
- } else {
58
- (0, _walk.replaceObject)(j, s, stackOut);
59
- }
60
- }
61
-
62
- const postProcessMap = context => {
63
- const stackOut = context.stackOut,
64
- s = (void 0).s;
65
- let j = stackOut.length - 1;
66
- const result = Array.from(s.values()).some(v => {
67
- const t = stackOut[j--];
68
- return typeof t == 'number' && isNaN(t) ? typeof v == 'number' && !isNaN(v) : v !== t;
69
- });
70
-
71
- if (result) {
72
- (0, _walk.buildNewMap)(s.keys(), stackOut);
73
- } else {
74
- (0, _walk.replaceObject)(j, s, stackOut);
75
- }
76
- };
77
-
78
- function postProcessMapSeen(context) {
79
- const stackOut = context.stackOut,
80
- s = this.s;
81
- let j = stackOut.length - 1;
82
- const result = Array.from(s.values()).some(v => {
83
- const t = stackOut[j--];
84
- return typeof t == 'number' && isNaN(t) ? typeof v == 'number' && !isNaN(v) : v !== t;
85
- });
86
-
87
- if (result) {
88
- (0, _walk.postMapCircular)(s, context);
89
- } else {
90
- (0, _walk.replaceObject)(j, s, stackOut);
91
- }
92
- }
93
-
94
- const registry = [_walk.default.Command, _walk.processCommand, Array, (0, _walk.processObject)(postProcess, postProcessSeen), _unify.Variable, _walk.processVariable, _unify.Unifier, _walk.processOther, Date, _walk.processOther, RegExp, _walk.processOther, Map, (0, _walk.processMap)(postProcessMap, postProcessMapSeen), Set, _walk.processOther, Promise, _walk.processOther],
95
- filters = []; // add more types
96
-
97
- exports.filters = filters;
98
- exports.registry = registry;
99
-
100
- const addType = (Type, process) => registry.push(Type, process || _walk.processOther);
101
-
102
- typeof Int8Array == 'function' && addType(Int8Array);
103
- typeof Uint8Array == 'function' && addType(Uint8Array);
104
- typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
105
- typeof Int16Array == 'function' && addType(Int16Array);
106
- typeof Uint16Array == 'function' && addType(Uint16Array);
107
- typeof Int32Array == 'function' && addType(Int32Array);
108
- typeof Uint32Array == 'function' && addType(Uint32Array);
109
- typeof Float32Array == 'function' && addType(Float32Array);
110
- typeof Float64Array == 'function' && addType(Float64Array);
111
- typeof BigInt64Array == 'function' && addType(BigInt64Array);
112
- typeof BigUint64Array == 'function' && addType(BigUint64Array);
113
- typeof DataView == 'function' && addType(DataView);
114
- typeof ArrayBuffer == 'function' && addType(ArrayBuffer); // main
115
-
116
- const assemble = (source, env, options) => {
117
- if (env && !(env instanceof _unify.Env)) {
118
- options = env;
119
- env = null;
120
- }
121
-
122
- options = options || empty;
123
- const context = options.context || {},
124
- stackOut = [];
125
- context.stackOut = stackOut;
126
- context.env = env;
127
- (0, _walk.default)(source, {
128
- processObject: options.processObject || (0, _walk.processObject)(postProcess, postProcessSeen),
129
- processOther: options.processOther || _walk.processOther,
130
- processCircular: options.processCircular || _walk.processCircular,
131
- registry: options.registry || assemble.registry,
132
- filters: options.filters || assemble.filters,
133
- circular: options.circular,
134
- symbols: options.symbols,
135
- allProps: options.allProps,
136
- context: context
137
- }); // ice.assert(stackOut.length == 1);
138
-
139
- return stackOut[0];
140
- };
141
-
142
- assemble.registry = registry;
143
- assemble.filters = filters;
144
- var _default = assemble;
145
- exports.default = _default;
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.filters = exports.registry = void 0;
7
-
8
- var _unify = require("../unify.js");
9
-
10
- var _walk = _interopRequireWildcard(require("./walk.js"));
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- const empty = {};
17
-
18
- function postProcess(context) {
19
- const {
20
- descriptors,
21
- keys
22
- } = (0, _walk.getObjectData)(this.s, context);
23
- (0, _walk.buildNewObject)(this.s, descriptors, keys, context.stackOut);
24
- }
25
-
26
- function postProcessSeen(context) {
27
- const {
28
- descriptors,
29
- keys
30
- } = (0, _walk.getObjectData)(this.s, context);
31
- (0, _walk.postObjectCircular)(this.s, descriptors, keys, context);
32
- }
33
-
34
- function postProcessMap(context) {
35
- (0, _walk.buildNewMap)(this.s.keys(), context.stackOut);
36
- }
37
-
38
- function postProcessMapSeen(context) {
39
- (0, _walk.postMapCircular)(this.s, context);
40
- }
41
-
42
- const registry = [_walk.default.Command, _walk.processCommand, Array, (0, _walk.processObject)(postProcess, postProcessSeen), _unify.Variable, _walk.processVariable, _unify.Unifier, _walk.processOther, Date, (val, context) => context.stackOut.push(new Date(val.getTime())), RegExp, (val, context) => context.stackOut.push(new RegExp(val.source, (val.global ? 'g' : '') + (val.multiline ? 'm' : '') + (val.ignoreCase ? 'i' : ''))), Map, (0, _walk.processMap)(postProcessMap, postProcessMapSeen), Promise, _walk.processOther],
43
- filters = []; // add more types
44
-
45
- exports.filters = filters;
46
- exports.registry = registry;
47
-
48
- const addType = (Type, process) => registry.push(Type, process || ((val, context) => context.stackOut.push(new Type(val))));
49
-
50
- addType(Set);
51
- typeof Int8Array == 'function' && addType(Int8Array);
52
- typeof Uint8Array == 'function' && addType(Uint8Array);
53
- typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
54
- typeof Int16Array == 'function' && addType(Int16Array);
55
- typeof Uint16Array == 'function' && addType(Uint16Array);
56
- typeof Int32Array == 'function' && addType(Int32Array);
57
- typeof Uint32Array == 'function' && addType(Uint32Array);
58
- typeof Float32Array == 'function' && addType(Float32Array);
59
- typeof Float64Array == 'function' && addType(Float64Array);
60
- typeof BigInt64Array == 'function' && addType(BigInt64Array);
61
- typeof BigUint64Array == 'function' && addType(BigUint64Array);
62
- typeof DataView == 'function' && addType(DataView);
63
- typeof ArrayBuffer == 'function' && addType(ArrayBuffer); // main
64
-
65
- const clone = (source, env, options) => {
66
- if (env && !(env instanceof _unify.Env)) {
67
- options = env;
68
- env = null;
69
- }
70
-
71
- options = options || empty;
72
- const context = options.context || {},
73
- stackOut = [];
74
- context.stackOut = stackOut;
75
- context.env = env;
76
- (0, _walk.default)(source, {
77
- processObject: options.processObject || (0, _walk.processObject)(postProcess, postProcessSeen),
78
- processOther: options.processOther || _walk.processOther,
79
- processCircular: options.processCircular || _walk.processCircular,
80
- registry: options.registry || clone.registry,
81
- filters: options.filters || clone.filters,
82
- circular: options.circular,
83
- symbols: options.symbols,
84
- allProps: options.allProps,
85
- context: context
86
- }); // ice.assert(stackOut.length == 1);
87
-
88
- return stackOut[0];
89
- };
90
-
91
- clone.registry = registry;
92
- clone.filters = filters;
93
- var _default = clone;
94
- exports.default = _default;
@@ -1,102 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.filters = exports.registry = void 0;
7
-
8
- var _unify = require("../unify.js");
9
-
10
- var _walk = _interopRequireWildcard(require("./walk.js"));
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- const empty = {};
17
-
18
- function postProcess(context) {
19
- const stackOut = context.stackOut,
20
- s = this.s,
21
- {
22
- descriptors,
23
- keys
24
- } = (0, _walk.getObjectData)(s, context);
25
- let j = stackOut.length - 1;
26
-
27
- for (const key of keys) {
28
- const d = descriptors[key];
29
-
30
- if (!(d.get || d.set)) {
31
- d.value = stackOut[j--];
32
- Object.defineProperty(s, key, d);
33
- }
34
- }
35
-
36
- (0, _walk.replaceObject)(j, s, stackOut);
37
- }
38
-
39
- function postProcessMap(context) {
40
- const stackOut = context.stackOut,
41
- s = this.s;
42
- let j = stackOut.length - 1;
43
-
44
- for (const key of s) {
45
- s.set(key, stackOut[j--]);
46
- }
47
-
48
- (0, _walk.replaceObject)(j, s, stackOut);
49
- }
50
-
51
- const registry = [_walk.default.Command, _walk.processCommand, Array, (0, _walk.processObject)(postProcess), _unify.Variable, _walk.processVariable, _unify.Unifier, _walk.processOther, Date, _walk.processOther, RegExp, _walk.processOther, Map, (0, _walk.processMap)(postProcessMap), Set, _walk.processOther, Promise, _walk.processOther],
52
- filters = []; // add more types
53
-
54
- exports.filters = filters;
55
- exports.registry = registry;
56
-
57
- const addType = (Type, process) => registry.push(Type, process || _walk.processOther);
58
-
59
- typeof Int8Array == 'function' && addType(Int8Array);
60
- typeof Uint8Array == 'function' && addType(Uint8Array);
61
- typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
62
- typeof Int16Array == 'function' && addType(Int16Array);
63
- typeof Uint16Array == 'function' && addType(Uint16Array);
64
- typeof Int32Array == 'function' && addType(Int32Array);
65
- typeof Uint32Array == 'function' && addType(Uint32Array);
66
- typeof Float32Array == 'function' && addType(Float32Array);
67
- typeof Float64Array == 'function' && addType(Float64Array);
68
- typeof BigInt64Array == 'function' && addType(BigInt64Array);
69
- typeof BigUint64Array == 'function' && addType(BigUint64Array);
70
- typeof DataView == 'function' && addType(DataView);
71
- typeof ArrayBuffer == 'function' && addType(ArrayBuffer); // main
72
-
73
- const deref = (source, env, options) => {
74
- if (env && !(env instanceof _unify.Env)) {
75
- options = env;
76
- env = null;
77
- }
78
-
79
- options = options || empty;
80
- const context = options.context || {},
81
- stackOut = [];
82
- context.stackOut = stackOut;
83
- context.env = env;
84
- (0, _walk.default)(source, {
85
- processObject: options.processObject || (0, _walk.processObject)(postProcess),
86
- processOther: options.processOther || _walk.processOther,
87
- processCircular: options.processCircular || _walk.processOther,
88
- registry: options.registry || deref.registry,
89
- filters: options.filters || deref.filters,
90
- circular: options.circular,
91
- symbols: options.symbols,
92
- allProps: options.allProps,
93
- context: context
94
- }); // ice.assert(stackOut.length == 1);
95
-
96
- return stackOut[0];
97
- };
98
-
99
- deref.registry = registry;
100
- deref.filters = filters;
101
- var _default = deref;
102
- exports.default = _default;