Skip to content

Commit e870ed9

Browse files
committed
tweak
1 parent 8f93517 commit e870ed9

9 files changed

+519
-25
lines changed

Diff for: jscomp/core/js_dump.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ let pp_block_record f =
107107
pp_block_dot f ;
108108
P.string f L.block_record
109109

110-
let pp_block_local_module f =
110+
let dbg_local_module f =
111111
pp_block_dot f;
112112
P.string f L.block_local_module
113113

114-
let pp_block_poly_var f =
114+
let dbg_poly_var f =
115115
pp_block_dot f;
116116
P.string f L.block_poly_var
117117

118-
let pp_block_simple_variant f =
118+
let dbg_simple_variant f =
119119
pp_block_dot f ;
120120
P.string f L.block_simple_variant
121121

122-
let pp_block_variant f =
122+
let dbg_variant f =
123123
pp_block_dot f ;
124124
P.string f L.block_variant
125125

@@ -875,24 +875,24 @@ and expression_desc cxt (level:int) f x : cxt =
875875
(Ext_list.map el drop_comment) ]
876876
)
877877
| Blk_module (Some labels) ->
878-
pp_block_local_module f;
878+
dbg_local_module f;
879879
P.paren_group f 1 (fun _ -> arguments cxt f
880880
[E.array Immutable
881881
(Ext_list.map labels E.str);
882882
E.array mutable_flag
883883
(Ext_list.map el drop_comment)])
884884
| Blk_variant name ->
885-
pp_block_poly_var f;
885+
dbg_poly_var f;
886886
P.paren_group f 1 (fun _ -> arguments cxt f [
887887
E.str name;
888888
E.array mutable_flag el])
889889
| Blk_constructor(name,number) when number = 1 && Js_block_runtime.tag_is_zero tag
890890
-> (* has to be debug mode *)
891-
pp_block_simple_variant f ;
891+
dbg_simple_variant f ;
892892
P.paren_group f 1 (fun _ -> arguments cxt f
893893
[E.str name; E.array mutable_flag el])
894894
| Blk_constructor(name,number) when is_debug ->
895-
pp_block_variant f ;
895+
dbg_variant f ;
896896
P.paren_group f 1 (fun _ -> arguments cxt f
897897
[ E.str name; tag ; E.array mutable_flag el])
898898
#if OCAML_VERSION =~ ">4.03.0" then

Diff for: jscomp/core/js_dump_lit.ml

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ let plus_plus = "++"
8787
let minus_minus = "--"
8888

8989
let caml_block_create = "__"
90+
91+
(** debug symbols *)
9092
let block_record = "record"
9193
let block_local_module = "localModule"
9294
let block_poly_var = "polyVar"

Diff for: jscomp/ext/js_runtime_modules.ml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ let weak = "Caml_weak"
4848
let gc = "Caml_gc"
4949
let int32 = "Caml_int32"
5050
let block = "Block"
51+
let caml_chrome_block = "Caml_chrome_debugger"
5152
let option = "Caml_option"
5253
let module_ = "Caml_module"
5354
let missing_polyfill = "Caml_missing_polyfill"

Diff for: jscomp/runtime/caml_chrome_debugger.ml

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
type obj = Caml_obj_extern.t
26+
27+
let setupChromeDebugger : unit -> unit = fun%raw unit -> {|
28+
29+
// I don't know how to directly refer to the classes that chrome's built-in
30+
// formatters use. adding "class": "foo" doesn't seem to work
31+
// tree-outline
32+
var olStyle = {"style": "list-style-type: none; padding-left: 12px; margin: 0"}
33+
// object-properties-section-separator
34+
var colonStyle = {"style": "flex-shrink: 0; padding-right: 5px"}
35+
var recordNumberStyle = {"style": "flex-shrink: 0; padding-right: 5px; color: rgb(145, 145, 145)"}
36+
37+
var showObject = function (value) {
38+
if (value == undefined) {
39+
return value + ''
40+
} else {
41+
return ["object", {"object": value}]
42+
}
43+
}
44+
45+
var recordCustomFormatter = function (data, labels) {
46+
return [
47+
"ol",
48+
olStyle,
49+
...data.map(function (cur, index) {
50+
return [
51+
"li",
52+
{},
53+
["span", recordNumberStyle, index],
54+
["span", {"style": "color: rgb(227, 110, 236)"}, labels[index]],
55+
["span", colonStyle, ":"],
56+
["span", {}, showObject(cur)],
57+
]
58+
})
59+
]
60+
};
61+
62+
var listToArray = function (data){
63+
var result = []
64+
var cur = data
65+
var index = 0
66+
while(typeof cur !== "number"){
67+
result.push([
68+
"li",
69+
{},
70+
["span", {"style": "color: rgb(227, 110, 236)"}, index],
71+
["span", colonStyle, ":"],
72+
showObject(cur[0])
73+
]);
74+
cur = cur[1]
75+
index++
76+
}
77+
return result
78+
};
79+
80+
var variantCustomFormatter = function (data,recordVariant){
81+
if(recordVariant === "::"){
82+
return [
83+
"ol",
84+
olStyle,
85+
... listToArray(data)
86+
]
87+
} else {
88+
return ["ol", olStyle, ...data.map(function (cur) { return showObject(cur) })]
89+
}
90+
91+
};
92+
93+
var recordPreview = function (recordLabels){
94+
var recordLastIndex = recordLabels.length - 1
95+
var preview = recordLabels.reduce(function (acc, cur, index) {
96+
if (index === recordLastIndex) {
97+
return acc + cur + "}"
98+
}
99+
return acc + cur + ", "
100+
}, "record {")
101+
return preview
102+
};
103+
104+
var variantPreview = function (x, recordVariant){
105+
if(recordVariant === "::") {
106+
// show the length, just like for array
107+
var length = listToArray(x).length;
108+
return ['span', {}, `list(${length})`]
109+
}
110+
return ['span', {}, `${recordVariant}(…)`]
111+
};
112+
var isOCamlExceptionOrExtensionHead = function(x){
113+
return Array.isArray(x) && x.tag === 248 && typeof x[0] === "string"
114+
}
115+
var isOCamlExceptionOrExtension = function(x){
116+
return Array.isArray(x) &&
117+
x[0] !== undefined &&
118+
isOCamlExceptionOrExtensionHead(x[0])
119+
}
120+
var formatter = {
121+
header: function (x) {
122+
var recordLabels
123+
var recordVariant
124+
var recordModule
125+
var recordPolyVar
126+
if ((recordLabels = x[Symbol.for('BsRecord')]) !== undefined) {
127+
return ['div', {}, recordPreview(recordLabels)]
128+
} else if ((recordVariant = x[Symbol.for('BsVariant')]) !== undefined){
129+
return variantPreview(x, recordVariant)
130+
} else if (isOCamlExceptionOrExtension(x)){
131+
return ['div',{}, `${x[0][0]}(…)`]
132+
} else if ((recordModule = x[Symbol.for('BsLocalModule')]) !== undefined){
133+
return ['div', {}, 'Module' ]
134+
} else if ((recordPolyVar = x[Symbol.for('BsPolyVar')] ) !== undefined){
135+
return ['div', {}, `\`${recordPolyVar}#${x[0]}`]
136+
}
137+
return null
138+
},
139+
hasBody: function (x) {
140+
var recordLabels
141+
var recordVariant
142+
var recordModule
143+
var recordPolyVar
144+
if ((recordLabels = x[Symbol.for('BsRecord')]) !== undefined) {
145+
return true
146+
} else if ((recordVariant = x[Symbol.for('BsVariant')] ) !== undefined){
147+
return recordVariant
148+
} else if(isOCamlExceptionOrExtension(x)){
149+
return true
150+
} else if ((recordModule = x[Symbol.for('BsLocalModule')] ) !== undefined){
151+
return true
152+
} else if( (recordPolyVar = x[Symbol.for('BsPolyVar')]) !== undefined){
153+
return true
154+
}
155+
return false
156+
},
157+
body: function (x) {
158+
var recordLabels
159+
var recordVariant
160+
var recordModule
161+
var recordPolyVar
162+
if ( (recordLabels = x[Symbol.for('BsRecord')]) !== undefined
163+
) {
164+
return recordCustomFormatter(x, recordLabels)
165+
}
166+
else if ((recordModule = x[Symbol.for('BsLocalModule')]) !== undefined){
167+
return recordCustomFormatter(x, recordModule)
168+
}
169+
else if ((recordVariant = x[Symbol.for('BsVariant')]) !== undefined) {
170+
return variantCustomFormatter(x,recordVariant)
171+
}
172+
else if ((recordPolyVar = x [Symbol.for('BsPolyVar')]) !== undefined){
173+
return showObject(x[1])
174+
}
175+
else if(isOCamlExceptionOrExtension(x)){
176+
return ["ol", olStyle, ... x.slice(1).map(cur => showObject(cur))]
177+
}
178+
179+
}
180+
181+
}
182+
if (typeof window === "undefined"){
183+
global.devtoolsFormatters = [formatter]
184+
} else {
185+
window.devtoolsFormatters = [formatter]
186+
}
187+
return 0
188+
189+
|}
190+
191+
192+
let setup = ref false
193+
let setupOnce () =
194+
if not !setup then
195+
begin
196+
setup := true;
197+
setupChromeDebugger ()
198+
end
199+
200+
type symbol
201+
202+
203+
external cacheSymbol : string -> symbol = "for"
204+
[@@bs.scope "Symbol"] [@@bs.val]
205+
external addProp : 'a -> symbol -> <value: 'b> Js.t -> 'a =
206+
"defineProperty" [@@bs.scope "Object"] [@@bs.val]
207+
208+
209+
(* It won't affect [Object.keys] using [Object.defineProperty*)
210+
let record meta xs =
211+
setupOnce ();
212+
xs |.addProp (cacheSymbol "BsRecord") [%obj {value = meta}]
213+
214+
let variant meta tag xs =
215+
setupOnce ();
216+
xs |. Caml_obj_extern.set_tag tag;
217+
xs |. addProp (cacheSymbol "BsVariant") [%obj {value = meta }]
218+
219+
let simpleVariant meta xs =
220+
setupOnce ();
221+
xs |. addProp (cacheSymbol "BsVariant") [%obj {value = meta }]
222+
223+
let localModule meta xs =
224+
setupOnce ();
225+
xs |. addProp (cacheSymbol "BsLocalModule") [%obj {value = meta}]
226+
227+
let polyVar meta xs =
228+
setupOnce ();
229+
xs |. addProp (cacheSymbol "BsPolyVar") [%obj {value = meta}]

Diff for: jscomp/runtime/caml_chrome_debugger.mli

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
type obj = Caml_obj_extern.t
26+
27+
val record : 'a -> obj -> obj
28+
29+
val variant : 'a -> int -> obj -> obj
30+
31+
val simpleVariant : 'a -> obj -> obj
32+
33+
val localModule : 'a -> obj -> obj
34+
35+
val polyVar : 'a -> obj -> obj

Diff for: jscomp/runtime/release.ninja

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ build runtime/caml_weak.cmi : cc runtime/caml_weak.mli | runtime/bs_stdlib_mini.
6767
build runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj : cc runtime/caml_array_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6868
build runtime/caml_bytes_extern.cmi runtime/caml_bytes_extern.cmj : cc runtime/caml_bytes_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6969
build runtime/caml_char.cmi runtime/caml_char.cmj : cc runtime/caml_char.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
70+
build runtime/caml_chrome_debugger.cmi runtime/caml_chrome_debugger.cmj : cc runtime/caml_chrome_debugger.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7071
build runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7172
build runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj : cc runtime/caml_int32_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7273
build runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -77,4 +78,4 @@ build runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj : cc runtime/caml_oo_c
7778
build runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7879
build runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7980
build runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.ml | runtime/bs_stdlib_mini.cmi runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj
80-
build runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/block.cmi runtime/block.cmj runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_builtin_exceptions.cmi runtime/caml_builtin_exceptions.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_gc.cmi runtime/caml_gc.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_io.cmi runtime/caml_io.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_missing_polyfill.cmi runtime/caml_missing_polyfill.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_oo.cmi runtime/caml_oo.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_primitive.cmi runtime/caml_primitive.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_utils.cmi runtime/caml_utils.cmj runtime/caml_weak.cmi runtime/caml_weak.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_bytes_extern.cmi runtime/caml_bytes_extern.cmj runtime/caml_char.cmi runtime/caml_char.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_obj_extern.cmi runtime/caml_obj_extern.cmj runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj
81+
build runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/block.cmi runtime/block.cmj runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_builtin_exceptions.cmi runtime/caml_builtin_exceptions.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_gc.cmi runtime/caml_gc.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_io.cmi runtime/caml_io.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_missing_polyfill.cmi runtime/caml_missing_polyfill.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_oo.cmi runtime/caml_oo.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_primitive.cmi runtime/caml_primitive.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_utils.cmi runtime/caml_utils.cmj runtime/caml_weak.cmi runtime/caml_weak.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_bytes_extern.cmi runtime/caml_bytes_extern.cmj runtime/caml_char.cmi runtime/caml_char.cmj runtime/caml_chrome_debugger.cmi runtime/caml_chrome_debugger.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_obj_extern.cmi runtime/caml_obj_extern.cmj runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj

0 commit comments

Comments
 (0)