-
Notifications
You must be signed in to change notification settings - Fork 38
Battle test with JSX PPX V4 #615
Comments
WIP: #614 |
I've looked into each issue and finally make my company project build successfully. |
@cristianoc I have a question about the issue no. 8. I've investigated some and found this. I think it is a breaking change for users to have to change their code. type x = {x?: int}
let x = Some(1)
let a = {x: ?x}
let b = {x: ?x->Option.map(x => x)} // error
// ^^^^^^^^^^^^^^^^^^^^ This has type: option<int>
// Somewhere wanted: int
let c = {x: ?Option.map(x, x => x)} // ok I guess it might be related to the operator precedence or just the wrong syntax usage by users. As V4 parses the props and value into the record, it causes a build error there. If users have their code base expressing |
Can you add examples with and without parens? Then we know what's going on. Examples checked in as tests. So we can look at the generated code. |
How can that be a breaking change if the syntax with |
Ah! I meant that breaking between V3 -> V4 with V10 compiler. I'll add the example in tests right a way. |
One more: @react.component
let anotherComponent = (~b) => {
React.string(b)
}
|
ead4831 The example added |
It is correct. As long as the parser do parse the uppercase jsx to EDIT: Plus, V4 allows only one react component per module. |
The component does not need to be called |
@react.component
let make = (~b) => React.string(b) It would be okay. Not sure I understand your point.
Can you elaborate little more? |
As in V3, the component can have any name. It can be called "default" to use file-level conventions for access from JS. A direct |
I finally got your point, I verified the same error. It seems an unreasonable error even without actually calling the component from outside. I'll look at it. |
I found the bug, I'll fix it soon! |
This should be fixed 42032a2 |
@mattdamon108 component definitions seems to support uncurried function definitions of Asking as it would be interesting to figure out whether uncurried components could be supported in future. (Where the component application calls |
That's not intentional, it is not in consideration actually. |
I think that's the answer. Since V4 only ever takes 1 argument, it does not really matter if curried or uncurried is used. One can switch between the two easily. |
One more issue. Example: module C = {
@react.component
let make = ( ~x, ~y) => React.string(x++y)
}
let c = <C x="abc" /> Compilation error: FAILED: src/V4.cmj
We've found a bug for you!
/Users/cristianocalcagno/GitHub/rescript-compiler/jscomp/gentype_tests/typescript-react-example/src/V4.res
Some record fields are undefined: y
FAILED: cannot make progress due to previous errors. |
I'll look into it. Anyway I'm working on the raising errors with loc. It seems related issues. |
It would be nice to have an explicit mode where after formatting, the result of running the ppx is left as normal code. |
I can confirm it is a location issue: in the following: // let c1 = C.make({x: "abc"})
// let c2 = <C x="abc" /> only |
11 shoud be Fixed 89561df
|
What's up with 8: is there an actual example that has a problem? |
It's mysterious 😄 You confirm that it is compiled just fine.#617 (comment) The same example is not compiled in my local. |
Let me try to add it to a PR then. |
Ah! I noticed it is different between V4 "classic" and "automatic" |
@@jsxConfig({version: 4})
let optionMap = (x, f) =>
switch x {
| None => None
| Some(v) => Some(f(v))
}
module A = {
@react.component
let make = (~name=?) => <div ?name />
}
module Direct = {
@react.component
let make = (~name=?) => {
<A
name=?{
optionMap(name, x => x)
}
/>
}
}
module Pipe = {
@react.component
let make = (~name=?) => {
<A
name=?{
name->optionMap(x => x)
}
/>
}
} |
Looks like it's the implementation of |
Here's a complete self-contained example without any ppx: let optionMap = (x, f) =>
switch x {
| None => None
| Some(v) => Some(f(v))
}
type props<'name> = {key?: string, name?: string}
let name = None
let ok = {name: ?optionMap(name, x => x)}
let bad = {name: ?name->optionMap(x => x)} |
Compiler bug on |
To confirm: this let ok = {name: @foo (optionMap(name, x => x))}
let bad = {name: @foo (name->optionMap(x => x))} formats to let ok = {name: @foo optionMap(name, x => x)}
let bad = {name: name->optionMap(x => x)} which means the annotation |
And to simplify further, this: let ok = @foo (optionMap(name, x => x))
let bad = @foo (name->optionMap(x => x)) formats to this: let ok = @foo optionMap(name, x => x)
let bad = name->optionMap(x => x) |
Added examples here: #621 |
Wow! yes, I've mentioned the operator precedence is suspicious though #615 (comment) I think you're right and your approach will solve this issue! |
Even though formatting is an issue, that needs to be fixed, I don't think it can be a cause of the bug you have observed (there's no printing involved, just parsing). |
The error one gets is the same as one would get by turning |
Not sure I understand what you meant. Do you mean that there is still an error in the example without |
As I said above there's no printing when you compile your original example: just parsing followed by type checking. |
Here's the bug: rescript-lang/rescript#5581 |
Merged. |
I’ll test it |
Now I get it, thanks! |
I can confirm it fixed! 👍 |
Congrats on completing the first version of PPX V4. |
@cristianoc I reopen issue no. 8. I found it has the same error with 1 arity fn. |
I'm not sure but suspicious here. https://github.com/rescript-lang/rescript-compiler/blob/e7c408ee63b86327bde3783a68cf673d475b4c8f/jscomp/frontend/ast_exp_apply.ml#L180 EDIT: Oops, maybe not |
Ah! I think |
Would you like to try to fix it directly? |
Yes, I'll give it a try! |
Start by adding an example, just like the previous PR. |
If you're not in hurry, can I start it when I get back? |
Issue no. 8 is fixed by rescript-lang/rescript#5585 |
Thank you for everything. It can't be done without your help and lead. I learned a lot. I'll keep contributing to the compiler, tools, and community as much as I can. |
props
being defined multiple times "Multiple definition of the type name props".This issue seems related to 4
This expression seems not working with V4, should work in different expression.
9. Raise error with loc
10. If a component is called
foo
notmake
the ppx tries to callmake
.11. Error without location when a required prop is not supplied.
The text was updated successfully, but these errors were encountered: