forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatSymbols.js
More file actions
69 lines (54 loc) · 1.92 KB
/
Copy pathformatSymbols.js
File metadata and controls
69 lines (54 loc) · 1.92 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
58
59
60
61
62
63
64
65
66
67
68
69
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import { getSymbols } from "../getSymbols";
import type { SourceId } from "../../../types";
function formatLocation(loc) {
if (!loc) {
return "";
}
const { start, end } = loc;
const startLoc = `(${start.line}, ${start.column})`;
const endLoc = `(${end.line}, ${end.column})`;
return `[${startLoc}, ${endLoc}]`;
}
function summarize(symbol) {
if (typeof symbol == "boolean") {
return symbol ? "true" : "false";
}
const loc = formatLocation(symbol.location);
const params = symbol.parameterNames
? `(${symbol.parameterNames.join(", ")})`
: "";
const expression = symbol.expression || "";
const klass = symbol.klass || "";
const name = symbol.name == undefined ? "" : symbol.name;
const names = symbol.specifiers ? symbol.specifiers.join(", ") : "";
const values = symbol.values ? symbol.values.join(", ") : "";
const index = symbol.index ? symbol.index : "";
return `${loc} ${expression} ${name}${params} ${klass} ${names} ${values} ${index}`.trim(); // eslint-disable-line max-len
}
const bools = ["hasJsx", "hasTypes", "loading"];
const strings = ["framework"];
function formatBool(name, symbols) {
return `${name}: ${symbols[name] ? "true" : "false"}`;
}
function formatString(name, symbols) {
return `${name}: ${symbols[name]}`;
}
function formatKey(name: string, symbols: any) {
if (bools.includes(name)) {
return formatBool(name, symbols);
}
if (strings.includes(name)) {
return formatString(name, symbols);
}
return `${name}:\n${symbols[name].map(summarize).join("\n")}`;
}
export function formatSymbols(sourceId: SourceId) {
const symbols = getSymbols(sourceId);
return Object.keys(symbols)
.map(name => formatKey(name, symbols))
.join("\n\n");
}