-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove raise annotations and fix locations on errors (#863)
* Enable ref in ppx * Add jest test for ref * Add test for error on key * Add locations into key * Change message on key * Fix I#843 which improves error message on react.component wrongly placed * Apply same message on similar fn, update snapshot * Add test for record-props and record-props-error * Use caller to genreate uppercase * Fix callee being always make * Remove Invalid_arguments * Add broken make_fn test and keep logic as before * Printinf on snapshot and errors has breakline * Remove test that comes with 19
- Loading branch information
Showing
13 changed files
with
231 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module X_as_main_function = { | ||
[@react.component] | ||
let x = () => <div />; | ||
}; | ||
|
||
module Create_element_as_main_function = { | ||
[@react.component] | ||
let createElement = (~lola) => <div> {React.string(lola)} </div>; | ||
}; | ||
|
||
/* This isn't valid running code, since Foo gets transformed into Foo.make, not createElement. */ | ||
module Invalid_case = { | ||
[@react.component] | ||
let make = (~lola) => { | ||
<Create_element_as_main_function lola />; | ||
}; | ||
}; | ||
|
||
/* If main function is not make, neither createElement, then it can be explicitly annotated */ | ||
/* NOTE: If you use `createElement` refmt removes it */ | ||
module Valid_case = { | ||
[@react.component] | ||
let make = () => { | ||
<Component_with_x_as_main_function.x />; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Since we generate invalid syntax for the argument of the make fn `(Props : <>)` | ||
We need to output ML syntax here, otherwise refmt could not parse it. | ||
$ ../ppx.sh --output ml input.re | ||
module X_as_main_function = | ||
struct | ||
external xProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ] | ||
let x () = ReactDOM.jsx "div" (((ReactDOM.domProps)[@merlin.hide ]) ()) | ||
let x = | ||
let Output$X_as_main_function$x (Props : < > Js.t) = x () in | ||
Output$X_as_main_function$x | ||
end | ||
module Create_element_as_main_function = | ||
struct | ||
external createElementProps : | ||
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = "" | ||
[@@mel.obj ] | ||
let createElement = | ||
((fun ~lola -> | ||
ReactDOM.jsx "div" | ||
(((ReactDOM.domProps)[@merlin.hide ]) | ||
~children:(React.string lola) ())) | ||
[@warning "-16"]) | ||
let createElement = | ||
let Output$Create_element_as_main_function$createElement | ||
(Props : < lola: 'lola > Js.t) = | ||
createElement ~lola:(Props ## lola) in | ||
Output$Create_element_as_main_function$createElement | ||
end | ||
module Invalid_case = | ||
struct | ||
external makeProps : | ||
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = "" | ||
[@@mel.obj ] | ||
let make = | ||
((fun ~lola -> | ||
React.jsx Create_element_as_main_function.make | ||
(Create_element_as_main_function.makeProps ~lola ())) | ||
[@warning "-16"]) | ||
let make = | ||
let Output$Invalid_case (Props : < lola: 'lola > Js.t) = | ||
make ~lola:(Props ## lola) in | ||
Output$Invalid_case | ||
end | ||
module Valid_case = | ||
struct | ||
external makeProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ] | ||
let make () = | ||
React.jsx Component_with_x_as_main_function.x | ||
(Component_with_x_as_main_function.xProps ()) | ||
let make = | ||
let Output$Valid_case (Props : < > Js.t) = make () in | ||
Output$Valid_case | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[@react.component] | ||
let (pageState, setPageState) = React.useState(_ => 0); | ||
let make = (~children, ()) => <div> children </div>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Test some locations in reason-react components | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.8) | ||
> (using melange 0.1) | ||
> EOF | ||
|
||
$ cat >dune <<EOF | ||
> (melange.emit | ||
> (alias foo) | ||
> (target foo) | ||
> (libraries reason-react) | ||
> (preprocess | ||
> (pps melange.ppx reason-react-ppx))) | ||
> EOF | ||
|
||
$ dune build | ||
File "component.re", lines 1-2, characters 0-54: | ||
1 | [@react.component] | ||
2 | let (pageState, setPageState) = React.useState(_ => 0). | ||
Error: [@react.component] cannot be used with a destructured binding. Please use it on a `let make = ...` binding instead. | ||
[1] |
Oops, something went wrong.