Skip to content

Commit

Permalink
Playground: Make sure to reset compiler on every compile
Browse files Browse the repository at this point in the history
This fixes an issue where warnings would disappear after a second
compile (part of the AlreadySeen mechanism I think). Also it makes
sure to reset the environment to a point where it doesn't delete
the already loaded cmi cache (in case of ReasonReact, every compile
would take several seconds otherwise)
  • Loading branch information
ryyppy committed Jul 28, 2020
1 parent f218848 commit abc58b4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions jscomp/refmt/jsoo_refmt_main.ml
Expand Up @@ -303,7 +303,9 @@ module Compile = struct

let flush_warning_buffer () =
Format.pp_print_flush warning_ppf ();
Buffer.contents warning_buffer
let str = Buffer.contents warning_buffer in
Buffer.reset warning_buffer;
str

let super_warning_printer loc ppf w =
match Warnings.report w with
Expand Down Expand Up @@ -370,12 +372,19 @@ module Compile = struct
ErrorRet.fromSyntaxErrors [|error|]
| _ -> ErrorRet.makeUnexpectedError msg)

(* Responsible for resetting all compiler state as if it were a new instance *)
let reset_compiler () =
warning_infos := [||];
flush_warning_buffer () |> ignore;
Location.reset();
Warnings.reset_fatal ();
Env.reset_cache_toplevel ()


let implementation ~(config: BundleConfig.t) ~lang str : Js.Unsafe.obj =
let {BundleConfig.module_system; warn_flags; warn_error_flags} = config in
try
(* Wanna make sure that we don't carry any uncleared warnings *)
warning_infos := [||];

reset_compiler ();
Warnings.parse_options false warn_flags;
Warnings.parse_options true warn_error_flags;
let filename = get_filename ~lang config.filename in
Expand Down

0 comments on commit abc58b4

Please sign in to comment.