-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.js
76 lines (69 loc) · 1.67 KB
/
constants.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { matches } = require("@bigbinary/neeto-cist");
const { test, isEmpty, mergeDeepLeft, all, includes, __ } = require("ramda");
const { matchesWithLength } = require("../utils");
const VALID_ARRAY_ELEMENT_TYPES = [
"StringLiteral",
"Identifier",
"NumericLiteral",
"BooleanLiteral",
];
const VALID_PICK_ARGUMENT_TYPES = [
"StringLiteral",
"Identifier",
"ArrayExpression",
];
const VALID_PICK_ARGUMENT = {
type: includes(__, VALID_PICK_ARGUMENT_TYPES),
elements: (elements, root) =>
root.type !== "ArrayExpression" ||
elements.every(({ type }) => VALID_ARRAY_ELEMENT_TYPES.includes(type)),
};
const PICK_GENERIC_PATTERN = {
type: "VariableDeclarator",
init: {
type: "CallExpression",
callee: {
type: "MemberExpression",
computed: false,
object: {
type: "Identifier",
name: test(/^use[a-zA-Z0-9]*Store$/),
},
property: {
type: "Identifier",
name: "pick",
},
},
},
};
const PICK_STRICT_PATTERN = {
type: "VariableDeclaration",
declarations: matchesWithLength([
mergeDeepLeft(
{
id: {
type: "ObjectPattern",
properties: all(
matches({
type: "ObjectProperty",
method: false,
value: {
type: includes(__, ["Identifier", "AssignmentPattern"]),
},
})
),
},
init: {
arguments: args =>
isEmpty(args) ||
(args.length === 1 && matches(VALID_PICK_ARGUMENT, args[0])),
},
},
PICK_GENERIC_PATTERN
),
]),
};
module.exports = {
PICK_GENERIC_PATTERN,
PICK_STRICT_PATTERN,
};