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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#### :nail_care: Polish

- Allow skipping the leading pipe in variant definition with a leading constructor with an attribute. https://github.com/rescript-lang/rescript/pull/7782

#### :house: Internal

# 12.0.0-beta.6
Expand Down
32 changes: 31 additions & 1 deletion compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5044,7 +5044,7 @@ and parse_type_representation ?current_type_name_path ?inline_types_context p =
in
let kind =
match p.Parser.token with
| Bar | Uident _ | DocComment _ ->
| Bar | Uident _ | DocComment _ | At ->
Parsetree.Ptype_variant (parse_type_constructor_declarations p)
| Lbrace ->
Parsetree.Ptype_record
Expand Down Expand Up @@ -5602,6 +5602,36 @@ and parse_type_equation_and_representation ?current_type_name_path
| Bar | DotDot | DocComment _ ->
let priv, kind = parse_type_representation p in
(None, priv, kind)
| At -> (
(* Attribute can start a variant constructor or a type manifest.
Look ahead past attributes; if a constructor-like token follows (Uident not immediately
followed by a Dot, or DotDotDot/Bar/DocComment), treat as variant; otherwise manifest *)
let is_variant_after_attrs =
Parser.lookahead p (fun state ->
ignore (parse_attributes state);
match state.Parser.token with
| Uident _ -> (
Parser.next state;
match state.Parser.token with
| Dot -> false
| _ -> true)
| DotDotDot | Bar | DocComment _ -> true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be DotDot as above or DotDotDot as here?

| _ -> false)
in
if is_variant_after_attrs then
let priv, kind = parse_type_representation p in
(None, priv, kind)
else
let manifest = Some (parse_typ_expr p) in
match p.Parser.token with
| Equal ->
Parser.next p;
let priv, kind =
parse_type_representation ?current_type_name_path
?inline_types_context p
in
(manifest, priv, kind)
| _ -> (manifest, Public, Parsetree.Ptype_abstract))
| _ -> (
let manifest = Some (parse_typ_expr p) in
match p.Parser.token with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type nonrec t =
| One [@as {js|one|js}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type t = @as("one") One

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type t = | @as("one") One
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type t = @as("one") One

Loading