Skip to content

Commit 6793a9e

Browse files
committed
Remove support for @deriving(jsConverter)
1 parent 6b4478f commit 6793a9e

13 files changed

+9
-475
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ These are only breaking changes for unformatted code.
4444
- Exponentiation operator `**` is now right-associative. `2. ** 3. ** 2.` now compile to `Math.pow(2, Math.pow(3, 2))` and not anymore `Math.pow(Math.pow(2, 3), 2)`. Parentheses can be used to change precedence.
4545
- Remove unsafe ``` j`$(a)$(b)` ``` interpolation deprecated in compiler version 10 https://github.com/rescript-lang/rescript-compiler/pull/6068
4646
- Remove deprecated module `Printexc`
47+
- `@deriving(jsConverter)` not supported anymore for variant types https://github.com/rescript-lang/rescript-compiler/pull/6088
4748

4849
#### :bug: Bug Fix
4950

jscomp/build_tests/white space/yy.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
type t =
22
| Foo
3-
[@@bs.deriving jsConverter]
43

54
let u = Xx.sum 3
65

jscomp/ext/warnings.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ let message = function
480480
| Bs_polymorphic_comparison ->
481481
"Polymorphic comparison introduced (maybe unsafe)"
482482
| Bs_ffi_warning s -> "FFI warning: " ^ s
483-
| Bs_derive_warning s -> "bs.deriving warning: " ^ s
483+
| Bs_derive_warning s -> "@deriving warning: " ^ s
484484
| Bs_fragile_external s ->
485485
s
486486
^ " : using an empty string as a shorthand to infer the external's name \

jscomp/frontend/ast_derive_js_mapper.ml

Lines changed: 6 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -127,49 +127,17 @@ let app1 = Ast_compatible.app1
127127

128128
let app2 = Ast_compatible.app2
129129

130-
let app3 = Ast_compatible.app3
131-
132-
let ( <=~ ) a b = app2 (Exp.ident { loc = noloc; txt = Lident "<=" }) a b
133-
134-
let ( -~ ) a b =
135-
app2 (Exp.ident { loc = noloc; txt = Ldot (Lident "Pervasives", "-") }) a b
136-
137-
let ( +~ ) a b =
138-
app2 (Exp.ident { loc = noloc; txt = Ldot (Lident "Pervasives", "+") }) a b
139-
140-
let ( &&~ ) a b =
141-
app2 (Exp.ident { loc = noloc; txt = Ldot (Lident "Pervasives", "&&") }) a b
142-
143130
let ( ->~ ) a b = Ast_compatible.arrow a b
144131

145132
let jsMapperRt = Longident.Ldot (Lident "Js", "MapperRt")
146133

147-
let fromInt len array exp =
148-
app3
149-
(Exp.ident { loc = noloc; txt = Longident.Ldot (jsMapperRt, "fromInt") })
150-
len array exp
151-
152-
let fromIntAssert len array exp =
153-
app3
154-
(Exp.ident
155-
{ loc = noloc; txt = Longident.Ldot (jsMapperRt, "fromIntAssert") })
156-
len array exp
157-
158134
let raiseWhenNotFound x =
159135
app1
160136
(Exp.ident
161137
{ loc = noloc; txt = Longident.Ldot (jsMapperRt, "raiseWhenNotFound") })
162138
x
163-
164-
let assertExp e = Exp.assert_ e
165-
166139
let derivingName = "jsConverter"
167140

168-
(* let notApplicable loc =
169-
Location.prerr_warning
170-
loc
171-
(Warnings.Bs_derive_warning ( derivingName ^ " not applicable to this type")) *)
172-
173141
let init () =
174142
Ast_derive.register derivingName (fun (x : Parsetree.expression option) ->
175143
let createType = handle_config x in
@@ -182,7 +150,6 @@ let init () =
182150
let name = tdcl.ptype_name.txt in
183151
let toJs = name ^ "ToJs" in
184152
let fromJs = name ^ "FromJs" in
185-
let constantArray = "jsMapperConstantArray" in
186153
let loc = tdcl.ptype_loc in
187154
let patToJs = { Asttypes.loc; txt = toJs } in
188155
let patFromJs = { Asttypes.loc; txt = fromJs } in
@@ -302,95 +269,9 @@ let init () =
302269
| None ->
303270
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
304271
[])
305-
| Ptype_variant ctors ->
306-
if Ast_polyvar.is_enum_constructors ctors then
307-
let xs =
308-
Ast_polyvar.map_constructor_declarations_into_ints ctors
309-
in
310-
match xs with
311-
| `New xs ->
312-
let constantArrayExp =
313-
Exp.ident { loc; txt = Lident constantArray }
314-
in
315-
let exp_len =
316-
Ast_compatible.const_exp_int (List.length ctors)
317-
in
318-
let v =
319-
[
320-
unsafeIndexGet;
321-
eraseTypeStr;
322-
Ast_comb.single_non_rec_value
323-
{ loc; txt = constantArray }
324-
(Ast_compatible.const_exp_int_list_as_array xs);
325-
toJsBody
326-
(app2 unsafeIndexGetExp constantArrayExp exp_param);
327-
Ast_comb.single_non_rec_value patFromJs
328-
(Ast_compatible.fun_ (Pat.var pat_param)
329-
(if createType then
330-
fromIntAssert exp_len constantArrayExp
331-
(exp_param +: newType)
332-
+> core_type
333-
else
334-
fromInt exp_len constantArrayExp exp_param
335-
+> Ast_core_type.lift_option_type core_type));
336-
]
337-
in
338-
if createType then newTypeStr :: v else v
339-
| `Offset offset ->
340-
let v =
341-
[
342-
eraseTypeStr;
343-
toJsBody
344-
(coerceResultToNewType
345-
(eraseType exp_param
346-
+~ Ast_compatible.const_exp_int offset));
347-
(let len = List.length ctors in
348-
let range_low =
349-
Ast_compatible.const_exp_int (offset + 0)
350-
in
351-
let range_upper =
352-
Ast_compatible.const_exp_int (offset + len - 1)
353-
in
354-
355-
Ast_comb.single_non_rec_value { loc; txt = fromJs }
356-
(Ast_compatible.fun_ (Pat.var pat_param)
357-
(if createType then
358-
Exp.let_ Nonrecursive
359-
[
360-
Vb.mk (Pat.var pat_param)
361-
(exp_param +: newType);
362-
]
363-
(Exp.sequence
364-
(assertExp
365-
(exp_param <=~ range_upper
366-
&&~ (range_low <=~ exp_param)))
367-
(exp_param
368-
-~ Ast_compatible.const_exp_int offset))
369-
+> core_type
370-
else
371-
Exp.ifthenelse
372-
(exp_param <=~ range_upper
373-
&&~ (range_low <=~ exp_param))
374-
(Exp.construct
375-
{ loc; txt = Ast_literal.predef_some }
376-
(Some
377-
(exp_param
378-
-~ Ast_compatible.const_exp_int
379-
offset)))
380-
(Some
381-
(Exp.construct
382-
{
383-
loc;
384-
txt = Ast_literal.predef_none;
385-
}
386-
None))
387-
+> Ast_core_type.lift_option_type core_type)));
388-
]
389-
in
390-
if createType then newTypeStr :: v else v
391-
else (
392-
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
393-
[])
272+
| Ptype_variant _ ->
273+
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
274+
[]
394275
| Ptype_open ->
395276
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
396277
[]
@@ -452,23 +333,9 @@ let init () =
452333
| None ->
453334
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
454335
[])
455-
| Ptype_variant ctors ->
456-
if Ast_polyvar.is_enum_constructors ctors then
457-
let ty1 =
458-
if createType then newType else Ast_literal.type_int ()
459-
in
460-
let ty2 =
461-
if createType then core_type
462-
else Ast_core_type.lift_option_type core_type
463-
in
464-
newTypeStr
465-
+? [
466-
toJsType ty1;
467-
Ast_comb.single_non_rec_val patFromJs (ty1 ->~ ty2);
468-
]
469-
else (
470-
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
471-
[])
336+
| Ptype_variant _ ->
337+
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
338+
[]
472339
| Ptype_open ->
473340
U.notApplicable tdcl.Parsetree.ptype_loc derivingName;
474341
[]

jscomp/frontend/ast_derive_util.ml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,6 @@ let new_type_of_type_declaration (tdcl : Parsetree.type_declaration) newName =
4343
ptype_private = Public;
4444
ptype_manifest = None;
4545
} )
46-
47-
(* let mk_fun ~loc (typ : Parsetree.core_type)
48-
(value : string) body
49-
: Parsetree.expression =
50-
Ast_compatible.fun_
51-
(Pat.constraint_ (Pat.var {txt = value ; loc}) typ)
52-
body
53-
54-
let destruct_label_declarations ~loc
55-
(arg_name : string)
56-
(labels : Parsetree.label_declaration list) :
57-
(Parsetree.core_type * Parsetree.expression) list * string list
58-
=
59-
Ext_list.fold_right labels ([], [])
60-
(fun {pld_name = {txt}; pld_type}
61-
(core_type_exps, labels) ->
62-
((pld_type,
63-
Exp.field (Exp.ident {txt = Lident arg_name ; loc})
64-
{txt = Lident txt ; loc}) :: core_type_exps),
65-
txt :: labels
66-
) *)
67-
6846
let notApplicable loc derivingName =
6947
Location.prerr_warning loc
7048
(Warnings.Bs_derive_warning (derivingName ^ " not applicable to this type"))

jscomp/frontend/ast_polyvar.ml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,3 @@ let is_enum_polyvar (ty : Parsetree.type_declaration) =
115115
when is_enum row_fields ->
116116
Some row_fields
117117
| _ -> None
118-
119-
let is_enum_constructors (constructors : Parsetree.constructor_declaration list)
120-
=
121-
List.for_all
122-
(fun (x : Parsetree.constructor_declaration) ->
123-
match x with
124-
| {
125-
pcd_args =
126-
Pcstr_tuple [] (* Note the enum is encoded using [Pcstr_tuple []]*);
127-
} ->
128-
true
129-
| _ -> false)
130-
constructors

jscomp/frontend/ast_polyvar.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,3 @@ val map_row_fields_into_strings :
3838

3939
val is_enum_polyvar :
4040
Parsetree.type_declaration -> Parsetree.row_field list option
41-
42-
val is_enum_constructors : Parsetree.constructor_declaration list -> bool

jscomp/test/ast_js_mapper_test.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)