Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# 11.0.0-rc.4 (Unreleased)

#### :rocket: New Feature

- Support renaming fields in inline records with `@as` attribute. [#6391](https://github.com/rescript-lang/rescript-compiler/pull/6391)

# 11.0.0-rc.3

#### :bug: Bug Fix
Expand Down
1 change: 1 addition & 0 deletions jscomp/core/bs_conditional_initial.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let setup_env () =
Lambda.fld_record := Record_attributes_check.fld_record;
Lambda.fld_record_set := Record_attributes_check.fld_record_set;
Lambda.blk_record := Record_attributes_check.blk_record;
Lambda.blk_record_inlined := Record_attributes_check.blk_record_inlined;
Matching.names_from_construct_pattern :=
Matching_polyfill.names_from_construct_pattern;

Expand Down
9 changes: 9 additions & 0 deletions jscomp/core/record_attributes_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ let blk_record (fields : (label * _) array) mut record_repr =
Lambda.Blk_record
{ fields = all_labels_info; mutable_flag = mut; record_repr }

let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
let fields =
Array.map
(fun ((lbl : label), _) ->
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
fields
in
Lambda.Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }

let check_bs_attributes_inclusion (attrs1 : Parsetree.attributes)
(attrs2 : Parsetree.attributes) lbl_name =
let a = Ext_list.find_def attrs1 find_name lbl_name in
Expand Down
11 changes: 11 additions & 0 deletions jscomp/test/as_inline_record_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions jscomp/test/as_inline_record_test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type user =
| User({
@as("renamed")
name: string,
})

let user = User({name: "Corentin"})
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.