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