Skip to content

Commit 5e49799

Browse files
authored
Merge pull request #3823 from BuckleScript/allow_name_diff_string_literal
tentative fix reason language server
2 parents bdf0280 + 2e98138 commit 5e49799

File tree

15 files changed

+89
-38
lines changed

15 files changed

+89
-38
lines changed

jscomp/common/js_config.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ let jsx_version = ref (-1)
107107

108108
let refmt = ref None
109109

110-
let is_reason = ref false
110+
let is_reason = ref false
111+
112+
let js_stdout = ref true

jscomp/common/js_config.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@ val force_cmj : bool ref
101101

102102
val jsx_version : int ref
103103
val refmt : string option ref
104-
val is_reason : bool ref
104+
val is_reason : bool ref
105+
106+
val js_stdout : bool ref

jscomp/common/ml_binary.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let read_ast (type t ) (kind : t kind) ic : t =
3636
| Mli -> Config.ast_intf_magic_number in
3737
let buffer = really_input_string ic (String.length magic) in
3838
assert(buffer = magic); (* already checked by apply_rewriter *)
39-
Location.input_name := input_value ic;
39+
Location.set_input_name @@ input_value ic;
4040
input_value ic
4141

4242
let write_ast (type t) (kind : t kind)

jscomp/core/lam_compile_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ let lambda_as_module
301301
(if !Js_config.bs_suffix then Literals.suffix_bs_js else Literals.suffix_js)
302302
in
303303
let package_info = Js_packages_state.get_packages_info () in
304-
if Js_packages_info.is_empty package_info then
304+
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
305305
Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout
306306
else
307307
Js_packages_info.iter package_info (fun {module_system; path = _path} ->

jscomp/main/js_main.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let process_file ppf sourcefile =
4949
The {!Location.input_name} relies on that we write the binary ast
5050
properly
5151
*)
52-
Location.input_name := sourcefile;
52+
Location.set_input_name sourcefile;
5353
let ext = Ext_filename.get_extension_maybe sourcefile in
5454
let input =
5555
if ext = Literals.suffix_ml then
@@ -329,8 +329,10 @@ let buckle_script_flags : (string * Arg.spec * string) list =
329329
" no code for assert false"
330330
)
331331

332-
:: Ocaml_options.mk_impl impl
333-
:: Ocaml_options.mk_intf intf
332+
:: Ocaml_options.mk_impl
333+
(fun file -> Js_config.js_stdout := false; impl file )
334+
:: Ocaml_options.mk_intf
335+
(fun file -> Js_config.js_stdout := false ; intf file)
334336
:: Ocaml_options.mk__ anonymous
335337
:: Ocaml_options.ocaml_options
336338

jscomp/syntax/ppx_driver.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let apply_lazy ~source ~target
3535
if magic <> Config.ast_impl_magic_number
3636
&& magic <> Config.ast_intf_magic_number then
3737
failwith "Bs_ast_mapper: OCaml version mismatch or malformed input";
38-
Location.input_name := input_value ic;
38+
Location.set_input_name @@ input_value ic;
3939
let ast = input_value ic in
4040
close_in ic;
4141

lib/4.02.3/bsdep.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,7 @@ val symbol_gloc: unit -> t
20562056
val rhs_loc: int -> t
20572057

20582058
val input_name: string ref
2059+
val set_input_name: string -> unit
20592060
val input_lexbuf: Lexing.lexbuf option ref
20602061

20612062
val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
@@ -2217,7 +2218,8 @@ let rhs_loc n = {
22172218

22182219
let input_name = ref "_none_"
22192220
let input_lexbuf = ref (None : lexbuf option)
2220-
2221+
let set_input_name name =
2222+
if name <> "" then input_name := name
22212223
(* Terminal info *)
22222224

22232225
let status = ref Terminfo.Uninitialised
@@ -22420,7 +22422,7 @@ let apply_lazy ~source ~target mapper =
2242022422
if magic <> Config.ast_impl_magic_number
2242122423
&& magic <> Config.ast_intf_magic_number then
2242222424
failwith "Ast_mapper: OCaml version mismatch or malformed input";
22423-
Location.input_name := input_value ic;
22425+
Location.set_input_name @@ input_value ic;
2242422426
let ast = input_value ic in
2242522427
close_in ic;
2242622428

@@ -22831,7 +22833,7 @@ let read_ast magic fn =
2283122833
try
2283222834
let buffer = really_input_string ic (String.length magic) in
2283322835
assert(buffer = magic); (* already checked by apply_rewriter *)
22834-
Location.input_name := input_value ic;
22836+
Location.set_input_name @@ input_value ic;
2283522837
let ast = input_value ic in
2283622838
close_in ic;
2283722839
Misc.remove_file fn;
@@ -22899,11 +22901,11 @@ let file ppf ~tool_name inputfile parse_fun ast_magic =
2289922901
(* FIXME make this a proper warning *)
2290022902
fprintf ppf "@[Warning: %s@]@."
2290122903
"option -unsafe used with a preprocessor returning a syntax tree";
22902-
Location.input_name := input_value ic;
22904+
Location.set_input_name @@ input_value ic;
2290322905
input_value ic
2290422906
end else begin
2290522907
seek_in ic 0;
22906-
Location.input_name := inputfile;
22908+
Location.set_input_name inputfile;
2290722909
let lexbuf = Lexing.from_channel ic in
2290822910
Location.init lexbuf inputfile;
2290922911
parse_fun lexbuf
@@ -22930,7 +22932,7 @@ let () =
2293022932
)
2293122933

2293222934
let parse_all ~tool_name parse_fun magic ppf sourcefile =
22933-
Location.input_name := sourcefile;
22935+
Location.set_input_name sourcefile;
2293422936
let inputfile = preprocess sourcefile in
2293522937
let ast =
2293622938
try file ppf ~tool_name inputfile parse_fun magic
@@ -29740,6 +29742,8 @@ val force_cmj : bool ref
2974029742
val jsx_version : int ref
2974129743
val refmt : string option ref
2974229744
val is_reason : bool ref
29745+
29746+
val no_js_stdout : bool ref
2974329747
end = struct
2974429748
#1 "js_config.ml"
2974529749
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -29852,6 +29856,8 @@ let jsx_version = ref (-1)
2985229856
let refmt = ref None
2985329857

2985429858
let is_reason = ref false
29859+
29860+
let no_js_stdout = ref false
2985529861
end
2985629862
module Bs_warnings : sig
2985729863
#1 "bs_warnings.mli"

lib/4.02.3/bspp.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ val symbol_gloc: unit -> t
19931993
val rhs_loc: int -> t
19941994

19951995
val input_name: string ref
1996+
val set_input_name: string -> unit
19961997
val input_lexbuf: Lexing.lexbuf option ref
19971998

19981999
val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
@@ -2154,7 +2155,8 @@ let rhs_loc n = {
21542155

21552156
let input_name = ref "_none_"
21562157
let input_lexbuf = ref (None : lexbuf option)
2157-
2158+
let set_input_name name =
2159+
if name <> "" then input_name := name
21582160
(* Terminal info *)
21592161

21602162
let status = ref Terminfo.Uninitialised

lib/4.02.3/bsppx.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ val symbol_gloc: unit -> t
19931993
val rhs_loc: int -> t
19941994

19951995
val input_name: string ref
1996+
val set_input_name: string -> unit
19961997
val input_lexbuf: Lexing.lexbuf option ref
19971998

19981999
val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
@@ -2154,7 +2155,8 @@ let rhs_loc n = {
21542155

21552156
let input_name = ref "_none_"
21562157
let input_lexbuf = ref (None : lexbuf option)
2157-
2158+
let set_input_name name =
2159+
if name <> "" then input_name := name
21582160
(* Terminal info *)
21592161

21602162
let status = ref Terminfo.Uninitialised
@@ -2645,6 +2647,8 @@ val force_cmj : bool ref
26452647
val jsx_version : int ref
26462648
val refmt : string option ref
26472649
val is_reason : bool ref
2650+
2651+
val no_js_stdout : bool ref
26482652
end = struct
26492653
#1 "js_config.ml"
26502654
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2757,6 +2761,8 @@ let jsx_version = ref (-1)
27572761
let refmt = ref None
27582762

27592763
let is_reason = ref false
2764+
2765+
let no_js_stdout = ref false
27602766
end
27612767
(** Interface as module *)
27622768
module Asttypes
@@ -3790,7 +3796,7 @@ let apply_lazy ~source ~target
37903796
if magic <> Config.ast_impl_magic_number
37913797
&& magic <> Config.ast_intf_magic_number then
37923798
failwith "Bs_ast_mapper: OCaml version mismatch or malformed input";
3793-
Location.input_name := input_value ic;
3799+
Location.set_input_name @@ input_value ic;
37943800
let ast = input_value ic in
37953801
close_in ic;
37963802

@@ -23820,7 +23826,7 @@ let apply_lazy ~source ~target mapper =
2382023826
if magic <> Config.ast_impl_magic_number
2382123827
&& magic <> Config.ast_intf_magic_number then
2382223828
failwith "Ast_mapper: OCaml version mismatch or malformed input";
23823-
Location.input_name := input_value ic;
23829+
Location.set_input_name @@ input_value ic;
2382423830
let ast = input_value ic in
2382523831
close_in ic;
2382623832

lib/4.02.3/unstable/all_ounit_tests.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7394,6 +7394,8 @@ val force_cmj : bool ref
73947394
val jsx_version : int ref
73957395
val refmt : string option ref
73967396
val is_reason : bool ref
7397+
7398+
val no_js_stdout : bool ref
73977399
end = struct
73987400
#1 "js_config.ml"
73997401
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -7506,6 +7508,8 @@ let jsx_version = ref (-1)
75067508
let refmt = ref None
75077509

75087510
let is_reason = ref false
7511+
7512+
let no_js_stdout = ref false
75097513
end
75107514
module Ml_binary : sig
75117515
#1 "ml_binary.mli"
@@ -7584,7 +7588,7 @@ let read_ast (type t ) (kind : t kind) ic : t =
75847588
| Mli -> Config.ast_intf_magic_number in
75857589
let buffer = really_input_string ic (String.length magic) in
75867590
assert(buffer = magic); (* already checked by apply_rewriter *)
7587-
Location.input_name := input_value ic;
7591+
Location.set_input_name @@ input_value ic;
75887592
input_value ic
75897593

75907594
let write_ast (type t) (kind : t kind)

0 commit comments

Comments
 (0)