Skip to content

Commit 71402ce

Browse files
Format & review fixes
1 parent 919658a commit 71402ce

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 ()
@@ -893,59 +896,56 @@ module Export = struct
893896
( "setJsxPreserveMode",
894897
inject
895898
@@ Js.wrap_meth_callback (fun _ value ->
896-
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
899+
Js.bool (set_jsx_preserve_mode (Js.to_bool value))) );
897900
( "setGentypeEnabled",
898901
inject
899902
@@ Js.wrap_meth_callback (fun _ value ->
900-
Js.bool (set_gentype_enabled (Js.to_bool value))) );
903+
Js.bool (set_gentype_enabled (Js.to_bool value))) );
901904
( "setSourceMapMode",
902905
inject
903906
@@ Js.wrap_meth_callback (fun _ value ->
904-
Js.bool (set_source_map_mode (Js.to_string value))) );
907+
Js.bool (set_source_map_mode (Js.to_string value))) );
905908
( "setSourceMapSourcesContent",
906909
inject
907910
@@ Js.wrap_meth_callback (fun _ value ->
908-
Js.bool
909-
(set_source_map_sources_content (Js.to_bool value))) );
911+
Js.bool (set_source_map_sources_content (Js.to_bool value))) );
910912
( "setSourceMapRoot",
911913
inject
912914
@@ Js.wrap_meth_callback (fun _ value ->
913-
Js.bool (set_source_map_root (Js.to_string value))) );
915+
Js.bool (set_source_map_root (Js.to_string value))) );
914916
( "getConfig",
915917
inject
916918
@@ Js.wrap_meth_callback (fun _ ->
917-
Js.Unsafe.(
918-
obj
919-
[|
920-
( "module_system",
921-
inject
922-
@@ (config.module_system
923-
|> Bundle_config.string_of_module_system
924-
|> Js.string) );
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-
);
935-
( "source_map_sources_content",
936-
inject
937-
@@ (config.source_map_sources_content |> Js.bool) );
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-
);
948-
|])) );
919+
Js.Unsafe.(
920+
obj
921+
[|
922+
( "module_system",
923+
inject
924+
@@ (config.module_system
925+
|> Bundle_config.string_of_module_system |> Js.string
926+
) );
927+
("warn_flags", inject @@ Js.string config.warn_flags);
928+
( "jsx_preserve_mode",
929+
inject @@ (config.jsx_preserve_mode |> Js.bool) );
930+
( "gentype_enabled",
931+
inject @@ (config.gentype_enabled |> Js.bool) );
932+
( "source_map_mode",
933+
inject
934+
@@ (config.source_map_mode
935+
|> Bundle_config.string_of_source_map |> Js.string) );
936+
( "source_map_sources_content",
937+
inject @@ (config.source_map_sources_content |> Js.bool)
938+
);
939+
( "source_map_root",
940+
inject @@ Js.string config.source_map_root );
941+
( "experimental_features",
942+
inject
943+
@@ (config.experimental_features |> Array.of_list
944+
|> Js.array) );
945+
( "open_modules",
946+
inject
947+
@@ (config.open_modules |> Array.of_list |> Js.array) );
948+
|])) );
949949
|])
950950
end
951951

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)