-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexpected.js
More file actions
31 lines (24 loc) · 968 Bytes
/
expected.js
File metadata and controls
31 lines (24 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function _hasProps(obj, props) {
return obj != null && (typeof obj === "object" || typeof obj === "function") && props.filter(function (prop) {
return prop in obj;
}).length === props.length;
}
if (_hasProps(x, ["a"])) {
const { a } = x;
a;
} else if (_hasProps(x, ["a", "b"])) {
const { a, b } = x;
a + b;
} else if (_hasProps(x, ["a"])) {
const { a, b = 1 } = x;
a + b;
} else if (_hasProps(x, ["a", "b", "c"]) && _hasProps(x.b, ["ba"]) && _hasProps(x.c, ["ca", "cb"]) && _hasProps(x.c.cb, ["cba"])) {
const { a, b: { ba, bb = 1 }, c: { ca, cb: { cba } } } = x;
a + ba + bb + ca + cba;
} else if ((x === 1 || x === 2) && _hasProps(x, ["a", "b"]) && _hasProps(x.b, ["c"])) {
const { a, b: { c } } = x;
a + c;
} else if (_hasProps(x, []) && (_hasProps(x.a, ["b"]) && _hasProps(x.a.b, ["c"]) || _hasProps(otherObj, ["b"]) && _hasProps(otherObj.b, ["c"]))) {
const { a: { b: { c } } = otherObj } = x;
c;
} //TODO: | { a, ...b }: b