-
Notifications
You must be signed in to change notification settings - Fork 478
/
functionDependencies.js
39 lines (33 loc) · 1.34 KB
/
functionDependencies.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
import { TOKEN_TYPES } from 'shared/constants';
import { callExpressionConverter } from 'builder/converters/core';
import { DefinitionsMap } from 'builder/entryDefinitionsMap';
import { getCustomFunctionDeclaration } from 'builder/abstraction-levels/functions';
const isNodeContainsFunctionCall = node => {
return node && node.type === TOKEN_TYPES.CALL_EXPRESSION;
};
const getCustomAssignmentExpression = () => {
const assignmentExpression = DefinitionsMap[TOKEN_TYPES.ASSIGNMENT_EXPRESSION];
return {
...assignmentExpression,
getName: ({ node }) => callExpressionConverter({ node: node.right }),
ignore: path =>
assignmentExpression.ignore(path) || !isNodeContainsFunctionCall(path.node.right)
};
};
const getCustomVariableDeclarator = () => {
const variableDeclarator = DefinitionsMap[TOKEN_TYPES.VARIABLE_DECLARATOR];
return {
...variableDeclarator,
getName: ({ node }) => callExpressionConverter({ node: node.init }),
ignore: path =>
variableDeclarator.ignore(path) || !isNodeContainsFunctionCall(path.node.init)
};
};
export const getFunctionDependenciesLevel = () => ({
defined: [TOKEN_TYPES.CALL_EXPRESSION],
custom: [
getCustomFunctionDeclaration(),
getCustomAssignmentExpression(),
getCustomVariableDeclarator()
]
});