Skip to content

Commit 985bf35

Browse files
cknittclaude
andauthored
Deprecate @deriving(abstract) and @deriving(jsConverter) for 12.3.2 (#8808)
* Deprecate @deriving(abstract) and @deriving(jsConverter) Both are removed in v13 (#8729); warn with the same replacement hints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ju652DvPkBXpeHxN3ZoLb5 Signed-off-by: Christoph Knittel <ck@cca.io> * Add PR link to changelog entry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ju652DvPkBXpeHxN3ZoLb5 Signed-off-by: Christoph Knittel <ck@cca.io> --------- Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 00578c6 commit 985bf35

6 files changed

Lines changed: 129 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
- Deprecate `Stdlib_Error` and `Stdlib_Exn` modules in favor of `JsError/JsExn`. https://github.com/rescript-lang/rescript/pull/8404
2222
- Deprecate `List.has` in favor of `List.some`. https://github.com/rescript-lang/rescript/pull/8807
23+
- Deprecate `@deriving(abstract)` and `@deriving(jsConverter)`, which will be removed in v13. https://github.com/rescript-lang/rescript/pull/8808
2324

2425
# 12.3.1
2526

‎compiler/frontend/ast_attributes.ml‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ let has_await_payload (attrs : t) = Ext_list.exists attrs Ast_await.is_await
143143

144144
type derive_attr = {bs_deriving: Ast_payload.action list option} [@@unboxed]
145145

146+
(* Derivers removed in v13, with the replacement to point to. *)
147+
let deprecated_deriver_hint = function
148+
| "abstract" ->
149+
Some
150+
"Use a record type instead. Records compile to plain JavaScript objects \
151+
and support optional fields (`field?: t`), mutable fields and `@as` \
152+
field renaming."
153+
| "jsConverter" ->
154+
Some
155+
"Records already compile to plain JavaScript objects and polymorphic \
156+
variants to their (`@as`-renamed) names, so the conversion functions \
157+
are no longer needed."
158+
| _ -> None
159+
160+
let warn_deprecated_derivers (actions : Ast_payload.action list) =
161+
Ext_list.iter actions (fun ({txt = name; loc}, _) ->
162+
match deprecated_deriver_hint name with
163+
| Some hint ->
164+
Location.deprecated loc
165+
(Printf.sprintf
166+
"@deriving(%s) is deprecated and will be removed in v13. %s" name
167+
hint)
168+
| None -> ())
169+
146170
let process_derive_type (attrs : t) : derive_attr * t =
147171
Ext_list.fold_left attrs
148172
({bs_deriving = None}, [])
@@ -151,11 +175,9 @@ let process_derive_type (attrs : t) : derive_attr * t =
151175
| "deriving" -> (
152176
match st.bs_deriving with
153177
| None ->
154-
( {
155-
bs_deriving =
156-
Some (Ast_payload.ident_or_record_as_config loc payload);
157-
},
158-
acc )
178+
let actions = Ast_payload.ident_or_record_as_config loc payload in
179+
warn_deprecated_derivers actions;
180+
({bs_deriving = Some actions}, acc)
159181
| Some _ -> Bs_syntaxerr.err loc Duplicated_bs_deriving)
160182
| _ -> (st, attr :: acc))
161183

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Warning number 3
3+
/.../fixtures/deriving_abstract_deprecated.res:8:13-20
4+
5+
6 │
6+
7 │ module type S = {
7+
8 │ @deriving(abstract)
8+
9 │ type t = {name: string}
9+
10 │ }
10+
11+
deprecated: @deriving(abstract) is deprecated and will be removed in v13. Use a record type instead. Records compile to plain JavaScript objects and support optional fields (`field?: t`), mutable fields and `@as` field renaming.
12+
13+
14+
Warning number 3
15+
/.../fixtures/deriving_abstract_deprecated.res:4:12-19
16+
17+
2 │ type t = {name: string}
18+
3 │
19+
4 │ @deriving({abstract: light})
20+
5 │ type u = {age: int}
21+
6 │
22+
23+
deprecated: @deriving(abstract) is deprecated and will be removed in v13. Use a record type instead. Records compile to plain JavaScript objects and support optional fields (`field?: t`), mutable fields and `@as` field renaming.
24+
25+
26+
Warning number 3
27+
/.../fixtures/deriving_abstract_deprecated.res:1:11-18
28+
29+
1 │ @deriving(abstract)
30+
2 │ type t = {name: string}
31+
3 │
32+
33+
deprecated: @deriving(abstract) is deprecated and will be removed in v13. Use a record type instead. Records compile to plain JavaScript objects and support optional fields (`field?: t`), mutable fields and `@as` field renaming.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
Warning number 3
3+
/.../fixtures/deriving_js_converter_deprecated.res:11:13-23
4+
5+
9 │
6+
10 │ module type S = {
7+
11 │ @deriving(jsConverter)
8+
12 │ type t = [#a | #b]
9+
13 │ }
10+
11+
deprecated: @deriving(jsConverter) is deprecated and will be removed in v13. Records already compile to plain JavaScript objects and polymorphic variants to their (`@as`-renamed) names, so the conversion functions are no longer needed.
12+
13+
14+
Warning number 3
15+
/.../fixtures/deriving_js_converter_deprecated.res:7:12-22
16+
17+
5 │ type u = {c: int}
18+
6 │
19+
7 │ @deriving({jsConverter: newType})
20+
8 │ type v = [#e | #f]
21+
9 │
22+
23+
deprecated: @deriving(jsConverter) is deprecated and will be removed in v13. Records already compile to plain JavaScript objects and polymorphic variants to their (`@as`-renamed) names, so the conversion functions are no longer needed.
24+
25+
26+
Warning number 3
27+
/.../fixtures/deriving_js_converter_deprecated.res:4:23-33
28+
29+
2 │ type t = [#a | #b]
30+
3 │
31+
4 │ @deriving({accessors, jsConverter})
32+
5 │ type u = {c: int}
33+
6 │
34+
35+
deprecated: @deriving(jsConverter) is deprecated and will be removed in v13. Records already compile to plain JavaScript objects and polymorphic variants to their (`@as`-renamed) names, so the conversion functions are no longer needed.
36+
37+
38+
Warning number 3
39+
/.../fixtures/deriving_js_converter_deprecated.res:1:11-21
40+
41+
1 │ @deriving(jsConverter)
42+
2 │ type t = [#a | #b]
43+
3 │
44+
45+
deprecated: @deriving(jsConverter) is deprecated and will be removed in v13. Records already compile to plain JavaScript objects and polymorphic variants to their (`@as`-renamed) names, so the conversion functions are no longer needed.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@deriving(abstract)
2+
type t = {name: string}
3+
4+
@deriving({abstract: light})
5+
type u = {age: int}
6+
7+
module type S = {
8+
@deriving(abstract)
9+
type t = {name: string}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@deriving(jsConverter)
2+
type t = [#a | #b]
3+
4+
@deriving({accessors, jsConverter})
5+
type u = {c: int}
6+
7+
@deriving({jsConverter: newType})
8+
type v = [#e | #f]
9+
10+
module type S = {
11+
@deriving(jsConverter)
12+
type t = [#a | #b]
13+
}

0 commit comments

Comments
 (0)