Skip to content

Commit 3dee062

Browse files
authored
Merge pull request #4569 from BuckleScript/reduandant_bs_string_warning
redundant bs.string warning
2 parents 45d9bf3 + 97ddd98 commit 3dee062

16 files changed

+1718
-1695
lines changed

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

jscomp/others/node_buffer.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ external isBuffer : 'a -> bool = "Buffer.isBuffer"
3232
external fromString : string -> t = "Buffer.from"
3333
[@@bs.val]
3434

35-
external fromStringWithEncoding : string -> ([ `ascii | `utf8 | `utf16le | `usc2 | `base64 | `latin1 | `binary | `hex ] [@bs.string]) -> t = "from"
35+
type encoding =
36+
[ `ascii | `utf8 | `utf16le | `usc2 | `base64 | `latin1 | `binary | `hex ]
37+
external fromStringWithEncoding : string -> encoding -> t = "from"
3638
[@@bs.val] [@@bs.scope "Buffer"]
3739

3840
external toString : t -> string = "toString"
3941
[@@bs.send]
4042

41-
external toStringWithEncoding : t -> ([ `ascii | `utf8 | `utf16le | `usc2 | `base64 | `latin1 | `binary | `hex ] [@bs.string]) -> string = "toString"
43+
external toStringWithEncoding : t -> encoding -> string = "toString"
4244
[@@bs.send]
4345

4446
external concat : t array -> t = "Buffer.concat"

jscomp/others/node_fs.ml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,20 @@ external openSync :
120120
] [@bs.string]) ->
121121
unit = "openSync" [@@bs.module "fs"]
122122

123-
123+
type encoding =
124+
[
125+
`hex
126+
| `utf8
127+
| `ascii
128+
| `latin1
129+
| `base64
130+
| `ucs2
131+
| `base64
132+
| `binary
133+
| `utf16le ]
124134
external readFileSync :
125135
string ->
126-
(
127-
[
128-
`hex
129-
| `utf8
130-
| `ascii
131-
| `latin1
132-
| `base64
133-
| `ucs2
134-
| `base64
135-
| `binary
136-
| `utf16le ][@bs.string]) ->
136+
encoding ->
137137
string = "readFileSync"
138138
[@@bs.val] [@@bs.module "fs"]
139139

@@ -148,16 +148,7 @@ external existsSync : string -> bool = "existsSync"
148148
external writeFileSync :
149149
string ->
150150
string ->
151-
(
152-
[ `hex
153-
| `utf8
154-
| `ascii
155-
| `latin1
156-
| `base64
157-
| `ucs2
158-
| `base64
159-
| `binary
160-
| `utf16le ][@bs.string]) ->
151+
encoding ->
161152
unit = "writeFileSync"
162153
[@@bs.val] [@@bs.module "fs"]
163154

jscomp/syntax/ast_polyvar.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ let map_row_fields_into_strings ptyp_loc
112112
| `Nothing -> Bs_syntaxerr.err ptyp_loc Invalid_bs_string_type
113113
| `Null
114114
| `NonNull ->
115-
External_arg_spec.Poly_var {has_payload = case = `NonNull ;
116-
descr = if !has_bs_as then Some result else None }
115+
let has_payload = case = `NonNull in
116+
let descr = if !has_bs_as then Some result else None in
117+
if not has_payload && descr = None then begin
118+
Location.prerr_warning ptyp_loc (Bs_ffi_warning "bs.string is redundant here, you can safely remove it")
119+
end;
120+
External_arg_spec.Poly_var
121+
{has_payload ;
122+
descr }
117123

118124
let is_enum row_fields =
119125
List.for_all (fun (x : Parsetree.row_field) ->

0 commit comments

Comments
 (0)