Skip to content

Commit 817c62f

Browse files
committed
make the record label check lenient
1 parent 75680aa commit 817c62f

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

jscomp/core/record_attributes_check.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ let rec check_duplicated_labels_aux
7373
| {pld_name= ({txt} as pld_name); pld_attributes}::rest ->
7474
if String_set.mem coll txt then Some pld_name
7575
else
76-
let coll = String_set.add coll txt in
76+
let coll_with_lbl = String_set.add coll txt in
7777
match Ext_list.find_opt pld_attributes find_name_with_loc with
78-
| None -> check_duplicated_labels_aux rest coll
78+
| None -> check_duplicated_labels_aux rest coll_with_lbl
7979
| Some ({txt = s;} as l) ->
80-
if String_set.mem coll s then
80+
if String_set.mem coll s
81+
(*use coll to make check a bit looser
82+
allow cases like [ x : int [@bs.as "x"]]
83+
*) then
8184
Some l
8285
else
83-
check_duplicated_labels_aux rest (String_set.add coll s)
86+
check_duplicated_labels_aux rest (String_set.add coll_with_lbl s)
8487

8588
let check_duplicated_labels lbls =
8689
check_duplicated_labels_aux lbls String_set.empty

jscomp/test/record_name_test.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ and obj = {
6464

6565
let f4 ({ x; y; z = {hi }}: entry) =
6666
(x + y + hi) * 2
67-
67+
68+
6869
#if 0 then
6970
type t5 = {
7071
x : int ;
@@ -73,4 +74,10 @@ type t5 = {
7374
}
7475

7576
let v5 = {x = 3 ; y = 2}
76-
#end
77+
#end
78+
79+
type t6 = {
80+
x : int [@bs.as "x"];
81+
y : int [@bs.as "y"]
82+
}
83+
(* allow this case *)

lib/4.06.1/bsdep.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28010,14 +28010,17 @@ let rec check_duplicated_labels_aux
2801028010
| {pld_name= ({txt} as pld_name); pld_attributes}::rest ->
2801128011
if String_set.mem coll txt then Some pld_name
2801228012
else
28013-
let coll = String_set.add coll txt in
28013+
let coll_with_lbl = String_set.add coll txt in
2801428014
match Ext_list.find_opt pld_attributes find_name_with_loc with
28015-
| None -> check_duplicated_labels_aux rest coll
28015+
| None -> check_duplicated_labels_aux rest coll_with_lbl
2801628016
| Some ({txt = s;} as l) ->
28017-
if String_set.mem coll s then
28017+
if String_set.mem coll s
28018+
(*use coll to make check a bit looser
28019+
allow cases like [ x : int [@bs.as "x"]]
28020+
*) then
2801828021
Some l
2801928022
else
28020-
check_duplicated_labels_aux rest (String_set.add coll s)
28023+
check_duplicated_labels_aux rest (String_set.add coll_with_lbl s)
2802128024

2802228025
let check_duplicated_labels lbls =
2802328026
check_duplicated_labels_aux lbls String_set.empty

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56189,14 +56189,17 @@ let rec check_duplicated_labels_aux
5618956189
| {pld_name= ({txt} as pld_name); pld_attributes}::rest ->
5619056190
if String_set.mem coll txt then Some pld_name
5619156191
else
56192-
let coll = String_set.add coll txt in
56192+
let coll_with_lbl = String_set.add coll txt in
5619356193
match Ext_list.find_opt pld_attributes find_name_with_loc with
56194-
| None -> check_duplicated_labels_aux rest coll
56194+
| None -> check_duplicated_labels_aux rest coll_with_lbl
5619556195
| Some ({txt = s;} as l) ->
56196-
if String_set.mem coll s then
56196+
if String_set.mem coll s
56197+
(*use coll to make check a bit looser
56198+
allow cases like [ x : int [@bs.as "x"]]
56199+
*) then
5619756200
Some l
5619856201
else
56199-
check_duplicated_labels_aux rest (String_set.add coll s)
56202+
check_duplicated_labels_aux rest (String_set.add coll_with_lbl s)
5620056203

5620156204
let check_duplicated_labels lbls =
5620256205
check_duplicated_labels_aux lbls String_set.empty

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56189,14 +56189,17 @@ let rec check_duplicated_labels_aux
5618956189
| {pld_name= ({txt} as pld_name); pld_attributes}::rest ->
5619056190
if String_set.mem coll txt then Some pld_name
5619156191
else
56192-
let coll = String_set.add coll txt in
56192+
let coll_with_lbl = String_set.add coll txt in
5619356193
match Ext_list.find_opt pld_attributes find_name_with_loc with
56194-
| None -> check_duplicated_labels_aux rest coll
56194+
| None -> check_duplicated_labels_aux rest coll_with_lbl
5619556195
| Some ({txt = s;} as l) ->
56196-
if String_set.mem coll s then
56196+
if String_set.mem coll s
56197+
(*use coll to make check a bit looser
56198+
allow cases like [ x : int [@bs.as "x"]]
56199+
*) then
5619756200
Some l
5619856201
else
56199-
check_duplicated_labels_aux rest (String_set.add coll s)
56202+
check_duplicated_labels_aux rest (String_set.add coll_with_lbl s)
5620056203

5620156204
let check_duplicated_labels lbls =
5620256205
check_duplicated_labels_aux lbls String_set.empty

lib/4.06.1/whole_compiler.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41637,14 +41637,17 @@ let rec check_duplicated_labels_aux
4163741637
| {pld_name= ({txt} as pld_name); pld_attributes}::rest ->
4163841638
if String_set.mem coll txt then Some pld_name
4163941639
else
41640-
let coll = String_set.add coll txt in
41640+
let coll_with_lbl = String_set.add coll txt in
4164141641
match Ext_list.find_opt pld_attributes find_name_with_loc with
41642-
| None -> check_duplicated_labels_aux rest coll
41642+
| None -> check_duplicated_labels_aux rest coll_with_lbl
4164341643
| Some ({txt = s;} as l) ->
41644-
if String_set.mem coll s then
41644+
if String_set.mem coll s
41645+
(*use coll to make check a bit looser
41646+
allow cases like [ x : int [@bs.as "x"]]
41647+
*) then
4164541648
Some l
4164641649
else
41647-
check_duplicated_labels_aux rest (String_set.add coll s)
41650+
check_duplicated_labels_aux rest (String_set.add coll_with_lbl s)
4164841651

4164941652
let check_duplicated_labels lbls =
4165041653
check_duplicated_labels_aux lbls String_set.empty

0 commit comments

Comments
 (0)