Skip to content

Commit bf0ce1e

Browse files
Format & review fixes
1 parent b76d611 commit bf0ce1e

6 files changed

Lines changed: 72 additions & 59 deletions

File tree

compiler/core/js_source_map.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let make ~source_contents ~generated_file ~source_root ~sources_content =
130130
let load_content builder filename =
131131
match Hashtbl.find_opt builder.provided_source_contents filename with
132132
| Some content -> Some content
133-
| None -> (try Some (Ext_io.load_file filename) with _ -> None)
133+
| None -> ( try Some (Ext_io.load_file filename) with _ -> None)
134134

135135
let add_source builder filename =
136136
let filename =

compiler/jsoo/jsoo_playground_main.ml

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ module Compile = struct
539539
platform_lib = "rescript";
540540
project_root;
541541
bsb_project_root = project_root;
542+
suffix = Literals.suffix_js;
542543
}
543544
in
544545
let source_file = sourcefile in
@@ -557,7 +558,7 @@ module Compile = struct
557558
|> Emit_js.emit_translation_as_string ~config ~file_name
558559
~output_file_relative ~resolver
559560
~input_cmt_translate_type_declarations:
560-
Gentype_main.input_cmt_translate_type_declarations
561+
Gentype_main.input_cmt_translate_type_declarations
561562
in
562563
Emit_type.file_header ~source_file:(Filename.basename source_file)
563564
^ "\n" ^ code_text ^ "\n"
@@ -576,13 +577,15 @@ module Compile = struct
576577
| Js_config.No_source_map -> None
577578
| Linked | Inline | Hidden ->
578579
Some
579-
(Js_source_map.make ~source_contents:[(filename, source)] ~generated_file
580-
~source_root:source_map_root
580+
(Js_source_map.make
581+
~source_contents:[(filename, source)]
582+
~generated_file ~source_root:source_map_root
581583
~sources_content:source_map_sources_content)
582584
in
583585
let print_javascript () =
584586
Js_dump_program.pp_deps_program ~output_prefix:"" module_system
585-
lambda_output (Ext_pp.from_buffer buffer)
587+
lambda_output
588+
(Ext_pp.from_buffer buffer)
586589
in
587590
(match source_map_builder with
588591
| None -> print_javascript ()
@@ -892,59 +895,56 @@ module Export = struct
892895
( "setJsxPreserveMode",
893896
inject
894897
@@ Js.wrap_meth_callback (fun _ value ->
895-
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
898+
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
896899
( "setGentypeEnabled",
897900
inject
898901
@@ Js.wrap_meth_callback (fun _ value ->
899-
Js.bool (set_gentype_enabled (Js.to_bool value))) );
902+
Js.bool (set_gentype_enabled (Js.to_bool value))) );
900903
( "setSourceMapMode",
901904
inject
902905
@@ Js.wrap_meth_callback (fun _ value ->
903-
Js.bool (set_source_map_mode (Js.to_string value))) );
906+
Js.bool (set_source_map_mode (Js.to_string value))) );
904907
( "setSourceMapSourcesContent",
905908
inject
906909
@@ Js.wrap_meth_callback (fun _ value ->
907-
Js.bool
908-
(set_source_map_sources_content (Js.to_bool value))) );
910+
Js.bool (set_source_map_sources_content (Js.to_bool value))) );
909911
( "setSourceMapRoot",
910912
inject
911913
@@ Js.wrap_meth_callback (fun _ value ->
912-
Js.bool (set_source_map_root (Js.to_string value))) );
914+
Js.bool (set_source_map_root (Js.to_string value))) );
913915
( "getConfig",
914916
inject
915917
@@ Js.wrap_meth_callback (fun _ ->
916-
Js.Unsafe.(
917-
obj
918-
[|
919-
( "module_system",
920-
inject
921-
@@ (config.module_system
922-
|> Bundle_config.string_of_module_system
923-
|> Js.string) );
924-
("warn_flags", inject @@ Js.string config.warn_flags);
925-
( "jsx_preserve_mode",
926-
inject @@ (config.jsx_preserve_mode |> Js.bool) );
927-
( "gentype_enabled",
928-
inject @@ (config.gentype_enabled |> Js.bool) );
929-
( "source_map_mode",
930-
inject
931-
@@ (config.source_map_mode
932-
|> Bundle_config.string_of_source_map |> Js.string)
933-
);
934-
( "source_map_sources_content",
935-
inject
936-
@@ (config.source_map_sources_content |> Js.bool) );
937-
( "source_map_root",
938-
inject @@ Js.string config.source_map_root );
939-
( "experimental_features",
940-
inject
941-
@@ (config.experimental_features |> Array.of_list
942-
|> Js.array) );
943-
( "open_modules",
944-
inject
945-
@@ (config.open_modules |> Array.of_list |> Js.array)
946-
);
947-
|])) );
918+
Js.Unsafe.(
919+
obj
920+
[|
921+
( "module_system",
922+
inject
923+
@@ (config.module_system
924+
|> Bundle_config.string_of_module_system |> Js.string
925+
) );
926+
("warn_flags", inject @@ Js.string config.warn_flags);
927+
( "jsx_preserve_mode",
928+
inject @@ (config.jsx_preserve_mode |> Js.bool) );
929+
( "gentype_enabled",
930+
inject @@ (config.gentype_enabled |> Js.bool) );
931+
( "source_map_mode",
932+
inject
933+
@@ (config.source_map_mode
934+
|> Bundle_config.string_of_source_map |> Js.string) );
935+
( "source_map_sources_content",
936+
inject @@ (config.source_map_sources_content |> Js.bool)
937+
);
938+
( "source_map_root",
939+
inject @@ Js.string config.source_map_root );
940+
( "experimental_features",
941+
inject
942+
@@ (config.experimental_features |> Array.of_list
943+
|> Js.array) );
944+
( "open_modules",
945+
inject
946+
@@ (config.open_modules |> Array.of_list |> Js.array) );
947+
|])) );
948948
|])
949949
end
950950

packages/dev-playground/src/Bindings.res

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ module Element = {
169169
@send external removeChild: (Dom.element, Dom.element) => unit = "removeChild"
170170
@send external focus: Dom.element => unit = "focus"
171171
@send
172-
external scrollIntoView: (Dom.element, scrollIntoViewOptions) => unit =
173-
"scrollIntoView"
172+
external scrollIntoView: (Dom.element, scrollIntoViewOptions) => unit = "scrollIntoView"
174173
@get external style: Dom.element => CssStyle.t = "style"
175174
@get @return(nullable)
176175
external getScrollHandler: Dom.element => option<Dom.event => unit> =

packages/dev-playground/src/Main.res

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ let offsetForPosition = (source, position: SourceMapNavigation.position) => {
192192
let col = ref(0)
193193
let length = source->String.length
194194

195-
while index.contents < length &&
196-
(line.contents < position.line ||
197-
(line.contents === position.line && col.contents < position.col)) {
195+
while (
196+
index.contents < length &&
197+
(line.contents < position.line ||
198+
(line.contents === position.line && col.contents < position.col))
199+
) {
198200
if source->String.charAt(index.contents) === "\n" {
199201
line := line.contents + 1
200202
col := 0
@@ -320,9 +322,8 @@ let mappedJavaScriptNode = (
320322
let className = isSelected
321323
? "source-map-mapped-segment source-map-mapped-segment-active"
322324
: "source-map-mapped-segment"
323-
let title = `${original.source}:${original.position.line->Int.toString}:${(
324-
original.position.col + 1
325-
)->Int.toString} — click to reveal in source`
325+
let title = `${original.source}:${original.position.line->Int.toString}:${(original.position.col + 1)
326+
->Int.toString} — click to reveal in source`
326327
nodes->Array.push(
327328
<span
328329
id={isSelected ? "generated-map-selection" : ""}
@@ -726,8 +727,7 @@ module App = {
726727
let scrollToGeneratedMapping = () =>
727728
Window.requestAnimationFrame(() =>
728729
switch Document.current->Document.getElementById("generated-map-selection") {
729-
| Some(element) =>
730-
element->Element.scrollIntoView({block: "center", inline: "nearest"})
730+
| Some(element) => element->Element.scrollIntoView({block: "center", inline: "nearest"})
731731
| None => ()
732732
}
733733
)
@@ -765,10 +765,13 @@ module App = {
765765
switch Signal.peek(compileResult) {
766766
| Some(Ok({sourceMap: Some(sourceMap)})) => {
767767
let mappings = SourceMapNavigation.decode(sourceMap)
768-
switch SourceMapNavigation.generatedForOriginal(mappings, {
769-
line: position.line,
770-
col: position.col,
771-
}) {
768+
switch SourceMapNavigation.generatedForOriginal(
769+
mappings,
770+
{
771+
line: position.line,
772+
col: position.col,
773+
},
774+
) {
772775
| Some(mapping) => {
773776
Signal.set(mappedSourcePosition, Some({line: position.line, col: position.col}))
774777
Signal.set(mappedGeneratedPosition, Some(mapping.generated))

packages/dev-playground/src/SourceMapNavigation.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ module RawMapping = {
3333
let decode = sourceMap => {
3434
let mappings: array<mapping> = []
3535
try {
36-
sourceMap->makeTraceMap->eachMapping(rawMapping => {
36+
sourceMap
37+
->makeTraceMap
38+
->eachMapping(rawMapping => {
3739
let original = switch (
3840
rawMapping->RawMapping.source,
3941
rawMapping->RawMapping.originalLine,

packages/playground/playground_test.cjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ if (result.js_code !== "") {
7878
console.log("-- Playground test complete --");
7979
}
8080

81+
compiler.setFilename("Playground.res");
82+
assert.equal(compiler.setGentypeEnabled(true), true);
83+
const gentypeResult = compiler.rescript.compileWithDebug("@genType let answer = 42\n");
84+
assert.equal(gentypeResult.type, "success");
85+
assert.match(gentypeResult.gentype, /require\(['"]\.\/Playground\.js['"]\)/);
86+
assert.doesNotMatch(gentypeResult.gentype, /Playground\.bs\.js/);
87+
assert.equal(compiler.setGentypeEnabled(false), true);
88+
89+
console.log("-- Playground gentype suffix test complete --");
90+
8191
const sourceMapSource = `let double = value => value * 2
8292
let result = double(21)
8393
`;
8494

85-
compiler.setFilename("Playground.res");
8695
assert.equal(compiler.setSourceMapMode("linked"), true);
8796
assert.equal(compiler.setSourceMapSourcesContent(true), true);
8897
assert.equal(compiler.setSourceMapRoot("rescript://playground/"), true);

0 commit comments

Comments
 (0)