Skip to content

Commit 139b5f4

Browse files
committed
add test case
1 parent 10b0bc2 commit 139b5f4

File tree

9 files changed

+140
-19
lines changed

9 files changed

+140
-19
lines changed

jscomp/test/inline_const.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33

44
var N = {};
55

6-
function N1($star) {
7-
return {};
8-
}
6+
console.log([
7+
3e-6,
8+
3e-6
9+
]);
910

1011
var x = true;
1112

13+
function N1(funarg) {
14+
return {};
15+
}
16+
1217
var h = "hello";
1318

1419
var hh = "hellohello";
@@ -18,4 +23,4 @@ exports.N = N;
1823
exports.N1 = N1;
1924
exports.h = h;
2025
exports.hh = hh;
21-
/* No side effect */
26+
/* Not a pure module */

jscomp/test/inline_const.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ end
1919

2020
module N1 = functor () -> struct
2121
let f4 = {j|中文|j} [@@bs.inline]
22+
let xx = 3e-6 [@@bs.inline]
23+
let xx0 = 3e-6
2224
end
2325
let h = f
2426

@@ -41,3 +43,5 @@ let f9 = 100L [@@bs.inline]
4143

4244
let v = 100L [@@bs.inline]
4345
let u = 1L [@@bs.inline]
46+
47+
let () = Js.log (xx,xx0)

jscomp/test/inline_const.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818
module N1 : functor () -> sig
1919
val f4 : string
2020
[@@bs.inline {j|中文|j}]
21+
val xx : float [@@bs.inline 3e-6]
2122
end
2223

2324
val h : string

jscomp/test/inline_const_test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Mt = require("./mt.js");
44
var Int64 = require("../../lib/js/int64.js");
55
var Caml_int64 = require("../../lib/js/caml_int64.js");
6+
var Inline_const = require("./inline_const.js");
67

78
var suites = {
89
contents: /* [] */0
@@ -28,28 +29,32 @@ var f3 = "中文";
2829

2930
var f4 = "中文";
3031

31-
eq("File \"inline_const_test.ml\", line 27, characters 5-12", f, "hello");
32+
eq("File \"inline_const_test.ml\", line 29, characters 5-12", f, "hello");
3233

33-
eq("File \"inline_const_test.ml\", line 28, characters 5-12", f1, "a");
34+
eq("File \"inline_const_test.ml\", line 30, characters 5-12", f1, "a");
3435

35-
eq("File \"inline_const_test.ml\", line 29, characters 5-12", f2, "中文");
36+
eq("File \"inline_const_test.ml\", line 31, characters 5-12", f2, "中文");
3637

37-
eq("File \"inline_const_test.ml\", line 30, characters 5-12", f3, "中文");
38+
eq("File \"inline_const_test.ml\", line 32, characters 5-12", f3, "中文");
3839

39-
eq("File \"inline_const_test.ml\", line 31, characters 5-12", f4, "中文");
40+
eq("File \"inline_const_test.ml\", line 33, characters 5-12", f4, "中文");
4041

41-
eq("File \"inline_const_test.ml\", line 32, characters 5-12", true, true);
42+
eq("File \"inline_const_test.ml\", line 34, characters 5-12", true, true);
4243

43-
eq("File \"inline_const_test.ml\", line 33, characters 5-12", 1, 1);
44+
eq("File \"inline_const_test.ml\", line 35, characters 5-12", 1, 1);
45+
46+
eq("File \"inline_const_test.ml\", line 36, characters 5-12", 3e-6, 0.000003);
4447

4548
var h = Caml_int64.add(Caml_int64.add(Caml_int64.mk(100, 0), Int64.one), Caml_int64.one);
4649

47-
Mt.from_pair_suites("File \"inline_const_test.ml\", line 41, characters 22-29", suites.contents);
50+
Mt.from_pair_suites("File \"inline_const_test.ml\", line 43, characters 22-29", suites.contents);
4851

4952
var f5 = true;
5053

5154
var f6 = 1;
5255

56+
var f7 = 3e-6;
57+
5358
exports.suites = suites;
5459
exports.test_id = test_id;
5560
exports.eq = eq;
@@ -61,5 +66,6 @@ exports.f3 = f3;
6166
exports.f4 = f4;
6267
exports.f5 = f5;
6368
exports.f6 = f6;
69+
exports.f7 = f7;
6470
exports.h = h;
6571
/* Not a pure module */

jscomp/test/inline_const_test.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ let f ,
1010
f3,
1111
f4,
1212
f5,
13-
f6
13+
f6,
14+
f7
1415
=
1516

1617
Inline_const.(
@@ -20,7 +21,8 @@ let f ,
2021
N.f3,
2122
H.f4,
2223
f5,
23-
f6
24+
f6,
25+
H.xx
2426
)
2527

2628
let () =
@@ -30,8 +32,8 @@ let () =
3032
eq __LOC__ f3 {j|中文|j};
3133
eq __LOC__ f4 {j|中文|j};
3234
eq __LOC__ f5 true;
33-
eq __LOC__ f6 1
34-
35+
eq __LOC__ f6 1 ;
36+
eq __LOC__ f7 0.000003
3537

3638
let h =
3739
let open Inline_const in

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93854,6 +93854,9 @@ val inline_int64_primitive :
9385493854
int64 ->
9385593855
string list
9385693856

93857+
val inline_float_primitive :
93858+
string -> string list
93859+
9385793860
val ffi_bs:
9385893861
External_arg_spec.params ->
9385993862
return_wrapper ->
@@ -94191,6 +94194,11 @@ let inline_int64_primitive (i : int64) : string list =
9419194194
(Const_int64 i))
9419294195
]
9419394196

94197+
let inline_float_primitive (i : string) : string list =
94198+
["";
94199+
to_string
94200+
(Ffi_inline_const (Const_float i))
94201+
]
9419494202
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
9419594203
match params with
9419694204
| {arg_type = Nothing; arg_label = Arg_empty}
@@ -400636,6 +400644,7 @@ val type_string : core_type_lit
400636400644
val type_bool : core_type_lit
400637400645
val type_int : core_type_lit
400638400646
val type_int64 : Parsetree.core_type
400647+
val type_float : Parsetree.core_type
400639400648
val type_any : core_type_lit
400640400649

400641400650
val pat_unit : pattern_lit
@@ -400778,6 +400787,10 @@ let type_int64 =
400778400787
Ast_helper.Typ.mk
400779400788
(Ptyp_constr ({ txt = Lident "int64"; loc = Location.none}, []))
400780400789

400790+
let type_float =
400791+
Ast_helper.Typ.mk
400792+
(Ptyp_constr ({ txt = Lident "float"; loc = Location.none}, []))
400793+
400781400794
let type_any ?loc () =
400782400795
match loc with
400783400796
| None -> No_loc.type_any
@@ -409406,7 +409419,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
409406409419
value_desc with
409407409420
pval_prim = External_ffi_types.inline_int64_primitive s;
409408409421
pval_attributes = [];
409409-
} }
409422+
} }
409423+
| Pexp_constant (Pconst_float(s,None)) ->
409424+
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
409425+
{sigi with psig_desc = Psig_value {
409426+
value_desc with
409427+
pval_prim = External_ffi_types.inline_float_primitive s;
409428+
pval_attributes = [];
409429+
} }
409410409430
| Pexp_construct ({txt = Lident ("true" | "false" as txt)}, None)
409411409431
->
409412409432
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
@@ -409485,6 +409505,16 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
409485409505
pval_attributes = [];
409486409506
pval_prim = External_ffi_types.inline_int64_primitive s
409487409507
} }
409508+
| Pexp_constant(Pconst_float (s, None))
409509+
->
409510+
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
409511+
{str with pstr_desc = Pstr_primitive {
409512+
pval_name = pval_name ;
409513+
pval_type = Ast_literal.type_float;
409514+
pval_loc = pvb_loc;
409515+
pval_attributes = [];
409516+
pval_prim = External_ffi_types.inline_float_primitive s
409517+
} }
409488409518
| Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
409489409519
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
409490409520
{str with pstr_desc = Pstr_primitive {

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93854,6 +93854,9 @@ val inline_int64_primitive :
9385493854
int64 ->
9385593855
string list
9385693856

93857+
val inline_float_primitive :
93858+
string -> string list
93859+
9385793860
val ffi_bs:
9385893861
External_arg_spec.params ->
9385993862
return_wrapper ->
@@ -94191,6 +94194,11 @@ let inline_int64_primitive (i : int64) : string list =
9419194194
(Const_int64 i))
9419294195
]
9419394196

94197+
let inline_float_primitive (i : string) : string list =
94198+
["";
94199+
to_string
94200+
(Ffi_inline_const (Const_float i))
94201+
]
9419494202
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
9419594203
match params with
9419694204
| {arg_type = Nothing; arg_label = Arg_empty}
@@ -400636,6 +400644,7 @@ val type_string : core_type_lit
400636400644
val type_bool : core_type_lit
400637400645
val type_int : core_type_lit
400638400646
val type_int64 : Parsetree.core_type
400647+
val type_float : Parsetree.core_type
400639400648
val type_any : core_type_lit
400640400649

400641400650
val pat_unit : pattern_lit
@@ -400778,6 +400787,10 @@ let type_int64 =
400778400787
Ast_helper.Typ.mk
400779400788
(Ptyp_constr ({ txt = Lident "int64"; loc = Location.none}, []))
400780400789

400790+
let type_float =
400791+
Ast_helper.Typ.mk
400792+
(Ptyp_constr ({ txt = Lident "float"; loc = Location.none}, []))
400793+
400781400794
let type_any ?loc () =
400782400795
match loc with
400783400796
| None -> No_loc.type_any
@@ -409406,7 +409419,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
409406409419
value_desc with
409407409420
pval_prim = External_ffi_types.inline_int64_primitive s;
409408409421
pval_attributes = [];
409409-
} }
409422+
} }
409423+
| Pexp_constant (Pconst_float(s,None)) ->
409424+
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
409425+
{sigi with psig_desc = Psig_value {
409426+
value_desc with
409427+
pval_prim = External_ffi_types.inline_float_primitive s;
409428+
pval_attributes = [];
409429+
} }
409410409430
| Pexp_construct ({txt = Lident ("true" | "false" as txt)}, None)
409411409431
->
409412409432
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
@@ -409485,6 +409505,16 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
409485409505
pval_attributes = [];
409486409506
pval_prim = External_ffi_types.inline_int64_primitive s
409487409507
} }
409508+
| Pexp_constant(Pconst_float (s, None))
409509+
->
409510+
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
409511+
{str with pstr_desc = Pstr_primitive {
409512+
pval_name = pval_name ;
409513+
pval_type = Ast_literal.type_float;
409514+
pval_loc = pvb_loc;
409515+
pval_attributes = [];
409516+
pval_prim = External_ffi_types.inline_float_primitive s
409517+
} }
409488409518
| Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
409489409519
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
409490409520
{str with pstr_desc = Pstr_primitive {

lib/4.06.1/unstable/native_ppx.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11484,6 +11484,7 @@ val type_string : core_type_lit
1148411484
val type_bool : core_type_lit
1148511485
val type_int : core_type_lit
1148611486
val type_int64 : Parsetree.core_type
11487+
val type_float : Parsetree.core_type
1148711488
val type_any : core_type_lit
1148811489

1148911490
val pat_unit : pattern_lit
@@ -11626,6 +11627,10 @@ let type_int64 =
1162611627
Ast_helper.Typ.mk
1162711628
(Ptyp_constr ({ txt = Lident "int64"; loc = Location.none}, []))
1162811629

11630+
let type_float =
11631+
Ast_helper.Typ.mk
11632+
(Ptyp_constr ({ txt = Lident "float"; loc = Location.none}, []))
11633+
1162911634
let type_any ?loc () =
1163011635
match loc with
1163111636
| None -> No_loc.type_any
@@ -18421,6 +18426,9 @@ val inline_int64_primitive :
1842118426
int64 ->
1842218427
string list
1842318428

18429+
val inline_float_primitive :
18430+
string -> string list
18431+
1842418432
val ffi_bs:
1842518433
External_arg_spec.params ->
1842618434
return_wrapper ->
@@ -18758,6 +18766,11 @@ let inline_int64_primitive (i : int64) : string list =
1875818766
(Const_int64 i))
1875918767
]
1876018768

18769+
let inline_float_primitive (i : string) : string list =
18770+
["";
18771+
to_string
18772+
(Ffi_inline_const (Const_float i))
18773+
]
1876118774
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
1876218775
match params with
1876318776
| {arg_type = Nothing; arg_label = Arg_empty}

0 commit comments

Comments
 (0)