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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#### :bug: Bug fix

- Preserve `@as(...)` decorator on record fields when creating interface. https://github.com/rescript-lang/rescript/pull/7779
- Fix parse error with nested record types and attributes on the field name that has the nested record type. https://github.com/rescript-lang/rescript/pull/7781

#### :memo: Documentation

Expand Down
21 changes: 15 additions & 6 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type inline_types_context = {
params: (Parsetree.core_type * Asttypes.variance) list;
}

let extend_current_type_name_path current_type_name_path field_name =
match current_type_name_path with
| None -> None
| Some path -> Some (path @ [field_name])

module Recover = struct
let default_expr () =
let id = Location.mknoloc "rescript.exprhole" in
Expand Down Expand Up @@ -4667,7 +4672,7 @@ and parse_string_field_declaration p =
(* field-decl ::=
* | [mutable] field-name : poly-typexpr
* | attributes field-decl *)
and parse_field_declaration p =
and parse_field_declaration ?current_type_name_path ?inline_types_context p =
let start_pos = p.Parser.start_pos in
let attrs = parse_attributes p in
let mut =
Expand All @@ -4684,7 +4689,10 @@ and parse_field_declaration p =
match p.Parser.token with
| Colon ->
Parser.next p;
parse_poly_type_expr p
let current_type_name_path =
extend_current_type_name_path current_type_name_path name.txt
in
parse_poly_type_expr ?current_type_name_path ?inline_types_context p
| _ ->
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
in
Expand Down Expand Up @@ -4718,9 +4726,7 @@ and parse_field_declaration_region ?current_type_name_path ?inline_types_context
let lident, loc = parse_lident p in
let name = Location.mkloc lident loc in
let current_type_name_path =
match current_type_name_path with
| None -> None
| Some current_type_name_path -> Some (current_type_name_path @ [name.txt])
extend_current_type_name_path current_type_name_path name.txt
in
let optional = parse_optional_label p in
let typ =
Expand Down Expand Up @@ -5379,7 +5385,10 @@ and parse_record_or_object_decl ?current_type_name_path ?inline_types_context p
p
| attr :: _ as attrs ->
let first =
let field = parse_field_declaration p in
let field =
parse_field_declaration ?current_type_name_path
?inline_types_context p
in
Parser.optional p Comma |> ignore;
{
field with
Expand Down
8 changes: 8 additions & 0 deletions tests/tests/src/nested_records.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ let options = {
}
};

let location = {
location_area: {
name: "test",
url: "test"
}
};

export {
options,
location,
}
/* No side effect */
15 changes: 15 additions & 0 deletions tests/tests/src/nested_records.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ let options = {
otherExtra: Some({test: true, anotherInlined: {record: true}}),
},
}

type location = {
@as("location_area")
locationArea: {
name: string,
url: string,
},
}

let location = {
locationArea: {
name: "test",
url: "test",
},
}
Loading