MCPcopy
hub / github.com/lebab/lebab / enter

Function enter

src/transform/destructParam.js:15–46  ·  view source on GitHub ↗
(fnNode, parent, scope)

Source from the content-addressed store, hash-verified

13
14 traverser.traverse(ast, withScope(ast, {
15 enter(fnNode, parent, scope) {
16 if (functionType.isFunction(fnNode)) {
17 scope.variables
18 .filter(isParameter)
19 .map(v => ({variable: v, exs: getMemberExpressions(v, hierarchy)}))
20 .filter(({exs}) => exs.length > 0)
21 .forEach(({variable, exs}) => {
22 // Replace parameter with destruct-pattern
23 const index = fnNode.params.findIndex(param => param === variable.defs[0].name);
24 if (index === -1) {
25 return;
26 }
27
28 if (uniqPropNames(exs).length > MAX_PROPS) {
29 logger.warn(
30 fnNode,
31 `${uniqPropNames(exs).length} different props found, will not transform more than ${MAX_PROPS}`,
32 'destruct-param'
33 );
34 return;
35 }
36
37 fnNode.params[index] = createDestructPattern(exs);
38
39 // Replace references of obj.foo with simply foo
40 exs.forEach(ex => {
41 ex.type = ex.property.type;
42 ex.name = ex.property.name;
43 });
44 });
45 }
46 }
47 }));
48}
49

Callers

nothing calls this directly

Calls 4

getMemberExpressionsFunction · 0.85
uniqPropNamesFunction · 0.85
createDestructPatternFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…