forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreviewFunction.js
More file actions
57 lines (44 loc) · 1.31 KB
/
previewFunction.js
File metadata and controls
57 lines (44 loc) · 1.31 KB
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
// @flow
import { DOM as dom } from "react";
import times from "lodash/times";
import zip from "lodash/zip";
import flatten from "lodash/flatten";
import { simplifyDisplayName } from "../../utils/frame";
import "./previewFunction.css";
type FunctionType = {
name: string,
displayName?: string,
userDisplayName?: string,
parameterNames?: string[]
};
function getFunctionName(func: FunctionType) {
const name = func.userDisplayName || func.displayName || func.name;
return simplifyDisplayName(name);
}
function renderFunctionName(func: FunctionType) {
const name = getFunctionName(func);
return dom.span({ className: "function-name" }, name);
}
function renderParams(func: FunctionType) {
const { parameterNames = [] } = func;
let params = parameterNames
.filter(i => i)
.map(param => dom.span({ className: "param" }, param));
const commas = times(params.length - 1).map(() =>
dom.span({ className: "delimiter" }, ", ")
);
return flatten(zip(params, commas));
}
function renderParen(paren) {
return dom.span({ className: "paren" }, paren);
}
function previewFunction(func: FunctionType) {
return dom.span(
{ className: "function-signature" },
renderFunctionName(func),
renderParen("("),
...renderParams(func),
renderParen(")")
);
}
export default previewFunction;