Skip to content

Commit b6a7a00

Browse files
committed
add bs-unafe-empty-array
1 parent bf464a3 commit b6a7a00

File tree

13 files changed

+49
-10
lines changed

13 files changed

+49
-10
lines changed

jscomp/common/js_config.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ let no_export = ref false
114114

115115
let record_as_js_object = ref false (* otherwise has an attribute *)
116116

117-
let as_ppx = ref false
117+
let as_ppx = ref false
118+
119+
let mono_empty_array = ref true

jscomp/common/js_config.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@ val all_module_aliases : bool ref
109109
val no_stdlib: bool ref
110110
val no_export: bool ref
111111
val record_as_js_object : bool ref
112-
val as_ppx : bool ref
112+
val as_ppx : bool ref
113+
114+
val mono_empty_array : bool ref

jscomp/main/js_main.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ let buckle_script_flags : (string * Arg.spec * string) list =
206206
" Define conditional variable e.g, -D DEBUG=true"
207207
)
208208
::
209-
("-bs-quiet", Arg.Unit (fun _ -> ()),
210-
" (Deprecated using -w a) Quiet mode (no warnings printed)"
209+
("-bs-unsafe-empty-array", Arg.Clear Js_config.mono_empty_array,
210+
" Allow [||] to be polymorphic"
211211
)
212212
::
213213
("-nostdlib", Arg.Set Js_config.no_stdlib,

jscomp/syntax/bs_builtin_ppx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
7676
(s, (Some delim)))
7777
->
7878
Ast_utf8_string_interp.transform e s delim
79-
| Pexp_array [] when
79+
| Pexp_array [] when !Js_config.mono_empty_array &&
8080
not (Ext_list.exists e.pexp_attributes (fun ({txt},_) -> txt = ""))->
8181
(* `ocamlfind query ppx_tools`/dumpast -loc_underscore -e 'let emptyArray () = [||] in emptyArray ()'*)
8282
let loc = e.pexp_loc in

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ build test/parser_api.cmi test/parser_api.cmj : cc test/parser_api.ml | $stdlib
465465
build test/parser_api_test.cmi test/parser_api_test.cmj : cc test/parser_api_test.ml | test/mt.cmj test/parser_api.cmj $stdlib
466466
build test/pipe_send_readline.cmi test/pipe_send_readline.cmj : cc test/pipe_send_readline.ml | $stdlib
467467
build test/pipe_syntax.cmi test/pipe_syntax.cmj : cc test/pipe_syntax.ml | $stdlib
468+
build test/poly_empty_array.cmi test/poly_empty_array.cmj : cc test/poly_empty_array.ml | $stdlib
468469
build test/poly_type.cmi test/poly_type.cmj : cc test/poly_type.ml | $stdlib
469470
build test/poly_variant_test.cmj : cc_cmi test/poly_variant_test.ml | test/mt.cmj test/poly_variant_test.cmi $stdlib
470471
build test/poly_variant_test.cmi : cc test/poly_variant_test.mli | $stdlib

jscomp/test/poly_empty_array.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
4+
var a = [];
5+
6+
exports.a = a;
7+
/* No side effect */

jscomp/test/poly_empty_array.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
[@@@bs.config {flags = [|"-bs-unsafe-empty-array"|] } ]
3+
let a = [||]

lib/4.06.1/unstable/all_ounit_tests.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7776,6 +7776,8 @@ val no_stdlib: bool ref
77767776
val no_export: bool ref
77777777
val record_as_js_object : bool ref
77787778
val as_ppx : bool ref
7779+
7780+
val mono_empty_array : bool ref
77797781
end = struct
77807782
#1 "js_config.ml"
77817783
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -7895,6 +7897,8 @@ let no_export = ref false
78957897
let record_as_js_object = ref false (* otherwise has an attribute *)
78967898

78977899
let as_ppx = ref false
7900+
7901+
let mono_empty_array = ref true
78987902
end
78997903
module Map_gen
79007904
= struct

lib/4.06.1/unstable/bspack.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11351,6 +11351,8 @@ val no_stdlib: bool ref
1135111351
val no_export: bool ref
1135211352
val record_as_js_object : bool ref
1135311353
val as_ppx : bool ref
11354+
11355+
val mono_empty_array : bool ref
1135411356
end = struct
1135511357
#1 "js_config.ml"
1135611358
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -11470,6 +11472,8 @@ let no_export = ref false
1147011472
let record_as_js_object = ref false (* otherwise has an attribute *)
1147111473

1147211474
let as_ppx = ref false
11475+
11476+
let mono_empty_array = ref true
1147311477
end
1147411478
module Map_gen
1147511479
= struct

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298844,6 +298844,8 @@ val no_stdlib: bool ref
298844298844
val no_export: bool ref
298845298845
val record_as_js_object : bool ref
298846298846
val as_ppx : bool ref
298847+
298848+
val mono_empty_array : bool ref
298847298849
end = struct
298848298850
#1 "js_config.ml"
298849298851
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -298963,6 +298965,8 @@ let no_export = ref false
298963298965
let record_as_js_object = ref false (* otherwise has an attribute *)
298964298966

298965298967
let as_ppx = ref false
298968+
298969+
let mono_empty_array = ref true
298966298970
end
298967298971
module Ast_config : sig
298968298972
#1 "ast_config.mli"
@@ -308258,7 +308262,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
308258308262
(s, (Some delim)))
308259308263
->
308260308264
Ast_utf8_string_interp.transform e s delim
308261-
| Pexp_array [] when
308265+
| Pexp_array [] when !Js_config.mono_empty_array &&
308262308266
not (Ext_list.exists e.pexp_attributes (fun ({txt},_) -> txt = ""))->
308263308267
(* `ocamlfind query ppx_tools`/dumpast -loc_underscore -e 'let emptyArray () = [||] in emptyArray ()'*)
308264308268
let loc = e.pexp_loc in

0 commit comments

Comments
 (0)