MCPcopy
hub / github.com/lebab/lebab / transformDefaultParams

Function transformDefaultParams

src/transform/defaultParam/index.js:21–44  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

19}
20
21function transformDefaultParams(fn) {
22 const detectedDefaults = findDefaults(fn.body.body);
23
24 fn.params = fn.params.map((param, i) => {
25 // Ignore params that use destructuring or already have a default
26 if (param.type !== 'Identifier') {
27 return param;
28 }
29
30 const detected = detectedDefaults[param.name];
31 // Transform when default value detected
32 // and default does not contain this or any of the remaining parameters
33 if (detected && !containsParams(detected.value, remainingParams(fn, i))) {
34 multiReplaceStatement({
35 parent: fn.body,
36 node: detected.node,
37 replacements: []
38 });
39 return withDefault(param, detected.value);
40 }
41
42 return param;
43 });
44}
45
46function withDefault(param, value) {
47 return {

Callers 1

enterFunction · 0.85

Calls 5

findDefaultsFunction · 0.85
containsParamsFunction · 0.85
remainingParamsFunction · 0.85
multiReplaceStatementFunction · 0.85
withDefaultFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…