-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathcaml_chrome_debugger.js
167 lines (145 loc) · 3.92 KB
/
caml_chrome_debugger.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import * as Block from "./block.js";
var setupChromeDebugger = (function(_){
// I don't know how to directly refer to the classes that chrome's built-in
// formatters use. adding "class": "foo" doesn't seem to work
// tree-outline
var olStyle = {"style": "list-style-type: none; padding-left: 12px; margin: 0"}
// object-properties-section-separator
var colonStyle = {"style": "flex-shrink: 0; padding-right: 5px"}
var showObject = function (value) {
if (value == undefined) {
return value + ''
} else {
return ["object", {"object": value}]
}
}
var listToArray = function (data){
var result = []
var cur = data
var index = 0
while(typeof cur !== "number"){
result.push([
"li",
{},
["span", {"style": "color: rgb(227, 110, 236)"}, index],
["span", colonStyle, ":"],
showObject(cur[0])
]);
cur = cur[1]
index++
}
return result
};
var variantCustomFormatter = function (data,recordVariant){
if(recordVariant === "::"){
return [
"ol",
olStyle,
... listToArray(data)
]
} else {
let spacedData = [];
data.forEach(cur => {
spacedData.push(["span", {"style": "margin-right: 12px"}, showObject(cur)]);
})
return ["ol", olStyle, ...spacedData]
}
};
var variantPreview = function (x, recordVariant){
if(recordVariant === "::") {
// show the length, just like for array
var length = listToArray(x).length;
return ['span', {}, `list(${length})`]
}
return ['span', {}, `${recordVariant}(…)`]
};
var isOCamlExceptionOrExtensionHead = function(x){
return Array.isArray(x) && x.tag === 248 && typeof x[0] === "string"
}
var isOCamlExceptionOrExtension = function(x){
return Array.isArray(x) &&
x[0] !== undefined &&
isOCamlExceptionOrExtensionHead(x[0])
}
var formatter = {
header: function (x) {
var recordVariant
var recordPolyVar
if ((recordVariant = x[Symbol.for('BsVariant')]) !== undefined){
return variantPreview(x, recordVariant)
} else if (isOCamlExceptionOrExtension(x)){
return ['div',{}, `${x[0][0]}(…)`]
} else if ((recordPolyVar = x[Symbol.for('BsPolyVar')] ) !== undefined){
return ['div', {}, `\`${recordPolyVar}#${x[0]}`]
}
return null
},
hasBody: function (x) {
var recordVariant
var recordPolyVar
if ((recordVariant = x[Symbol.for('BsVariant')] ) !== undefined){
return recordVariant
} else if(isOCamlExceptionOrExtension(x)){
return true
} else if( (recordPolyVar = x[Symbol.for('BsPolyVar')]) !== undefined){
return true
}
return false
},
body: function (x) {
var recordVariant
var recordPolyVar
if ((recordVariant = x[Symbol.for('BsVariant')]) !== undefined) {
return variantCustomFormatter(x,recordVariant)
}
else if ((recordPolyVar = x [Symbol.for('BsPolyVar')]) !== undefined){
return showObject(x[1])
}
else if(isOCamlExceptionOrExtension(x)){
return ["ol", olStyle, ... x.slice(1).map(cur => showObject(cur))]
}
}
}
if (typeof window === "undefined"){
global.devtoolsFormatters = [formatter]
} else {
window.devtoolsFormatters = [formatter]
}
return 0
});
var setup = {
contents: false
};
function setupOnce(param) {
if (!setup.contents) {
setup.contents = true;
return setupChromeDebugger(undefined);
}
}
function variant(meta, tag, xs) {
setupOnce(undefined);
xs.tag = tag;
return Object.defineProperty(xs, Symbol.for("BsVariant"), {
value: meta
});
}
function simpleVariant(meta, xs) {
setupOnce(undefined);
return Object.defineProperty(xs, Symbol.for("BsVariant"), {
value: meta
});
}
function polyVar(meta, xs) {
setupOnce(undefined);
return Object.defineProperty(xs, Symbol.for("BsPolyVar"), {
value: meta
});
}
var __ = Block.__;
export {
__ ,
variant ,
simpleVariant ,
polyVar ,
}
/* No side effect */