Skip to content

Commit 4b5c3db

Browse files
Format & review fixes
1 parent d093014 commit 4b5c3db

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 ()
@@ -891,59 +894,56 @@ module Export = struct
891894
( "setJsxPreserveMode",
892895
inject
893896
@@ Js.wrap_meth_callback (fun _ value ->
894-
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
897+
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
895898
( "setGentypeEnabled",
896899
inject
897900
@@ Js.wrap_meth_callback (fun _ value ->
898-
Js.bool (set_gentype_enabled (Js.to_bool value))) );
901+
Js.bool (set_gentype_enabled (Js.to_bool value))) );
899902
( "setSourceMapMode",
900903
inject
901904
@@ Js.wrap_meth_callback (fun _ value ->
902-
Js.bool (set_source_map_mode (Js.to_string value))) );
905+
Js.bool (set_source_map_mode (Js.to_string value))) );
903906
( "setSourceMapSourcesContent",
904907
inject
905908
@@ Js.wrap_meth_callback (fun _ value ->
906-
Js.bool
907-
(set_source_map_sources_content (Js.to_bool value))) );
909+
Js.bool (set_source_map_sources_content (Js.to_bool value))) );
908910
( "setSourceMapRoot",
909911
inject
910912
@@ Js.wrap_meth_callback (fun _ value ->
911-
Js.bool (set_source_map_root (Js.to_string value))) );
913+
Js.bool (set_source_map_root (Js.to_string value))) );
912914
( "getConfig",
913915
inject
914916
@@ Js.wrap_meth_callback (fun _ ->
915-
Js.Unsafe.(
916-
obj
917-
[|
918-
( "module_system",
919-
inject
920-
@@ (config.module_system
921-
|> Bundle_config.string_of_module_system
922-
|> Js.string) );
923-
("warn_flags", inject @@ Js.string config.warn_flags);
924-
( "jsx_preserve_mode",
925-
inject @@ (config.jsx_preserve_mode |> Js.bool) );
926-
( "gentype_enabled",
927-
inject @@ (config.gentype_enabled |> Js.bool) );
928-
( "source_map_mode",
929-
inject
930-
@@ (config.source_map_mode
931-
|> Bundle_config.string_of_source_map |> Js.string)
932-
);
933-
( "source_map_sources_content",
934-
inject
935-
@@ (config.source_map_sources_content |> Js.bool) );
936-
( "source_map_root",
937-
inject @@ Js.string config.source_map_root );
938-
( "experimental_features",
939-
inject
940-
@@ (config.experimental_features |> Array.of_list
941-
|> Js.array) );
942-
( "open_modules",
943-
inject
944-
@@ (config.open_modules |> Array.of_list |> Js.array)
945-
);
946-
|])) );
917+
Js.Unsafe.(
918+
obj
919+
[|
920+
( "module_system",
921+
inject
922+
@@ (config.module_system
923+
|> Bundle_config.string_of_module_system |> Js.string
924+
) );
925+
("warn_flags", inject @@ Js.string config.warn_flags);
926+
( "jsx_preserve_mode",
927+
inject @@ (config.jsx_preserve_mode |> Js.bool) );
928+
( "gentype_enabled",
929+
inject @@ (config.gentype_enabled |> Js.bool) );
930+
( "source_map_mode",
931+
inject
932+
@@ (config.source_map_mode
933+
|> Bundle_config.string_of_source_map |> Js.string) );
934+
( "source_map_sources_content",
935+
inject @@ (config.source_map_sources_content |> Js.bool)
936+
);
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+
|])) );
947947
|])
948948
end
949949

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)