Skip to content

Commit 6390057

Browse files
tatchicristianoc
andauthored
Support renaming fields in inline records (#6391)
* add test for @as in inline records * support renaming fields in inline records * add changelog entry * Update build.ninja --------- Co-authored-by: Cristiano Calcagno <[email protected]>
1 parent dc41b21 commit 6390057

6 files changed

+34
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 11.0.0-rc.4 (Unreleased)
1414

15+
#### :rocket: New Feature
16+
17+
- Support renaming fields in inline records with `@as` attribute. [#6391](https://github.com/rescript-lang/rescript-compiler/pull/6391)
18+
1519
# 11.0.0-rc.3
1620

1721
#### :bug: Bug Fix

jscomp/core/bs_conditional_initial.ml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let setup_env () =
4747
Lambda.fld_record := Record_attributes_check.fld_record;
4848
Lambda.fld_record_set := Record_attributes_check.fld_record_set;
4949
Lambda.blk_record := Record_attributes_check.blk_record;
50+
Lambda.blk_record_inlined := Record_attributes_check.blk_record_inlined;
5051
Matching.names_from_construct_pattern :=
5152
Matching_polyfill.names_from_construct_pattern;
5253

jscomp/core/record_attributes_check.ml

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ let blk_record (fields : (label * _) array) mut record_repr =
7070
Lambda.Blk_record
7171
{ fields = all_labels_info; mutable_flag = mut; record_repr }
7272

73+
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
74+
let fields =
75+
Array.map
76+
(fun ((lbl : label), _) ->
77+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
78+
fields
79+
in
80+
Lambda.Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }
81+
7382
let check_bs_attributes_inclusion (attrs1 : Parsetree.attributes)
7483
(attrs2 : Parsetree.attributes) lbl_name =
7584
let a = Ext_list.find_def attrs1 find_name lbl_name in

jscomp/test/as_inline_record_test.js

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/as_inline_record_test.res

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type user =
2+
| User({
3+
@as("renamed")
4+
name: string,
5+
})
6+
7+
let user = User({name: "Corentin"})

jscomp/test/build.ninja

+2-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)