Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make external... = "" optional in reason syntax #2464

Merged
merged 1 commit into from
Dec 14, 2019
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
35 changes: 17 additions & 18 deletions formatTest/typeCheckedTests/expected_output/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,9 @@ type reactClass;

/* "react-dom" shouldn't spread the attribute over multiple lines */
[@bs.val] [@bs.module "react-dom"]
external render: (reactElement, element) => unit =
"render";
external render: (reactElement, element) => unit;

[@bs.module "f"] external f: int => int = "f";
[@bs.module "f"] external f: int => int;

[@bs.val] [@bs.module "react"] [@bs.splice]
external createCompositeElementInternalHack:
Expand All @@ -427,7 +426,7 @@ external add_nat: (int, int) => int =
[@ocaml.deprecated
"Use bar instead. It's a much cooler function. This string needs to be a little long"
]
external foo: bool => bool = "";
external foo: bool => bool;

/* Attributes on an entire polymorphic variant leaf */
[@bs.module "fs"]
Expand All @@ -439,8 +438,7 @@ external readFileSync:
| [@bs.as "ascii"] `my_name
]
) =>
string =
"";
string;

[@bs.module "fs"]
external readFileSync2:
Expand All @@ -451,35 +449,37 @@ external readFileSync2:
| [@bs.as "ascii"] `my_name
]
) =>
string =
"";
string;

/* Ensure that attributes on extensions are printed */
[@test
[@attr]
[%%extension]
];

external debounce: (int, [@bs.meth] unit) => unit =
"";
external debounce:
(int, [@bs.meth] unit) => unit;

external debounce:
(int, [@bs.meth] unit) => unit;

external debounce:
(int, [@bs.meth] unit) => unit;

external debounce:
int => [@bs.meth] (unit => unit) =
"";
int => [@bs.meth] (unit => unit);

external debounce:
(int, [@bs.meth] (unit => unit)) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

external debounce:
(
int,
[@bs.meth] (unit => unit),
[@bs.meth] (unit => unit)
) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

external debounce:
(
Expand All @@ -489,8 +489,7 @@ external debounce:
unit => [@bs.meth] (unit => unit)
)
) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

let x = "hi";

Expand Down
5 changes: 4 additions & 1 deletion formatTest/typeCheckedTests/expected_output/attributes.rei
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ external createClassInternalHack:
"createClass";

[@bs.send.pipe: array('a)]
external map: (. ('a => 'b)) => array('b) = "";
external map: (. ('a => 'b)) => array('b);

[@bs.send.pipe: array('a)]
external map: (. ('a => 'b)) => array('b);

[@bs.val] [@bs.module "react"]
external createClassInternalHack:
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/mlSyntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let pub__ = "method";
let pri_ = "private";
let pri__ = "private";

external private: unit => unit = "";
external pri_: unit => unit = "";
external private: unit => unit;
external pri_: unit => unit;

type pub_ = int;
type pub__ = int;
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let pub__ = "method";
let pri_ = "private";
let pri__ = "private";

external private: unit => unit = "";
external pri_: unit => unit = "";
external private: unit => unit;
external pri_: unit => unit;

type pub_ = int;
type pub__ = int;
8 changes: 4 additions & 4 deletions formatTest/typeCheckedTests/expected_output/reasonComments.re
Original file line number Diff line number Diff line change
Expand Up @@ -731,20 +731,20 @@ let r = {

/** doc comment */
[@bs.send]
external url: t => string = "";
external url: t => string;

/**
* Short multiline doc comment
*/
[@bs.send]
external url: t => string = "";
external url: t => string;

/** Longer doc comment before an attribute on an external. */
[@bs.send]
external url: t => string = "";
external url: t => string;

/* normal comment */
[@bs.send] external url: t => string = "";
[@bs.send] external url: t => string;

/** doc type */
type q = {
Expand Down
4 changes: 4 additions & 0 deletions formatTest/typeCheckedTests/input/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ external readFileSync2 : (
/* Ensure that attributes on extensions are printed */
[@test [@attr] [%%extension]];

external debounce : (int, [@bs.meth] unit) => unit;

external debounce : (int, [@bs.meth] unit) => unit = "debounce";

external debounce : (int, [@bs.meth] unit) => unit = "";
romanschejbal marked this conversation as resolved.
Show resolved Hide resolved

external debounce : int => ([@bs.meth] (unit => unit)) = "";
Expand Down
4 changes: 3 additions & 1 deletion formatTest/typeCheckedTests/input/attributes.rei
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ type reactElement;
[@bs.val] [@bs.module "React"]
external createClassInternalHack : (t('classSpec)) => reactClass = "createClass";

[@bs.send.pipe : array('a)] external map : [@bs] (('a) => 'b) => array('b) = "";
[@bs.send.pipe : array('a)] external map: [@bs] (('a) => 'b) => array('b) = "";

[@bs.send.pipe : array('a)] external map: [@bs] (('a) => 'b) => array('b);

[@bs.val] [@bs.module "react"]
external createClassInternalHack : (t('classSpec)) => reactClass =
Expand Down
3 changes: 1 addition & 2 deletions formatTest/unit_tests/expected_output/uncurried.re
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ type timerId;

[@bs.val]
external setTimeout:
((. unit) => unit, int) => timerId =
"setTimeout";
((. unit) => unit, int) => timerId;

let id =
setTimeout((.) => Js.log("hello"), 1000);
Expand Down
15 changes: 13 additions & 2 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,12 @@ structure_item:
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type EQUAL primitive_declaration
{ let loc = mklocation $symbolstartpos $endpos in
mkstr (Pstr_primitive (Val.mk $3 $5 ~prim:$7 ~attrs:$1 ~loc)) }
let prim = if $7 = [""] then [$3.txt] else $7 in
mkstr (Pstr_primitive (Val.mk $3 $5 ~prim ~attrs:$1 ~loc)) }
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type SEMI
{ let loc = mklocation $symbolstartpos $endpos in
mkstr (Pstr_primitive (Val.mk $3 $5 ~prim:[$3.txt] ~attrs:$1 ~loc)) }
| type_declarations
{ let (nonrec_flag, tyl) = $1 in mkstr(Pstr_type (nonrec_flag, tyl)) }
| str_type_extension
Expand Down Expand Up @@ -1817,7 +1822,13 @@ signature_item:
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type EQUAL primitive_declaration
{ let loc = mklocation $symbolstartpos $endpos in
Psig_value (Val.mk $3 $5 ~prim:$7 ~attrs:$1 ~loc)
let prim = if $7 = [""] then [$3.txt] else $7 in
Psig_value (Val.mk $3 $5 ~prim ~attrs:$1 ~loc)
}
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type SEMI
{ let loc = mklocation $symbolstartpos $endpos in
Psig_value (Val.mk $3 $5 ~prim:[$3.txt] ~attrs:$1 ~loc)
}
| type_declarations
{ let (nonrec_flag, tyl) = $1 in Psig_type (nonrec_flag, tyl) }
Expand Down
12 changes: 9 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6499,9 +6499,15 @@ let printer = object(self:'self)
[(makeList ~postSpace:true [atom "external"; protectIdentifier vd.pval_name.txt]); (atom ":")])
(self#core_type vd.pval_type)
in
let frstHalf = makeList ~postSpace:true [lblBefore; atom "="] in
let sndHalf = makeSpacedBreakableInlineList (List.map self#constant_string vd.pval_prim) in
let primDecl = label ~space:true frstHalf sndHalf in
let primDecl =
match vd.pval_prim with
| [""] -> lblBefore
| _ when vd.pval_prim = [vd.pval_name.txt] -> lblBefore
| _ ->
let frstHalf = makeList ~postSpace:true [lblBefore; atom "="] in
let sndHalf = makeSpacedBreakableInlineList (List.map self#constant_string vd.pval_prim) in
label ~space:true frstHalf sndHalf
in
match vd.pval_attributes with
| [] -> primDecl
| attrs ->
Expand Down