|
1
|
import { ExpressionJsVar, ExpressionJsVarLiteral } from "types" |
|
2
|
import { isExpressionJsVarLiteral, isExpressionJsVarObj } from "docs-utils" |
|
3
|
|
|
4
|
export const performActionOnLiteral = ( |
|
5
|
item: ExpressionJsVar[] | ExpressionJsVar | { |
|
6
|
// handle the case when the literal has a name property, |
|
7
|
// such as for workflow diagram links |
|
8
|
name: string |
|
9
|
value?: ExpressionJsVar | ExpressionJsVar[] |
|
10
|
}, |
|
11
|
action: (item: ExpressionJsVarLiteral) => void |
|
12
|
) => { |
|
13
|
if (Array.isArray(item)) { |
|
14
|
item.forEach((i) => performActionOnLiteral(i, action)) |
|
15
|
} else if (isExpressionJsVarLiteral(item)) { |
|
16
|
action(item) |
|
17
|
} else { |
|
18
|
Object.values(item).forEach((value) => { |
|
19
|
if (Array.isArray(value) || isExpressionJsVarObj(value)) { |
|
20
|
return performActionOnLiteral(value, action) |
|
21
|
} |
|
22
|
|
|
23
|
if (!isExpressionJsVarLiteral(value)) { |
|
24
|
return |
|
25
|
} |
|
26
|
|
|
27
|
action(value) |
|
28
|
}) |
|
29
|
} |
|
30
|
} |