Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Fix build error where aliasing argument to _ in make function with …
Browse files Browse the repository at this point in the history
…jsx v4 (#720)
  • Loading branch information
mununki authored Dec 7, 2022
1 parent d56c139 commit 2a017ca
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Fix issue where the JSX fragment without children build error https://github.com/rescript-lang/syntax/pull/704
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707
- Treat await as almost-unary operator weaker than pipe so `await foo->bar` means `await (foo->bar)` https://github.com/rescript-lang/syntax/pull/711
- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/syntax/pull/720

#### :eyeglasses: Spec Compliance

Expand Down
5 changes: 1 addition & 4 deletions cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,7 @@ let transformStructureItem ~config mapper item =
| Pexp_fun
( _arg_label,
_default,
{
ppat_desc =
Ppat_construct ({txt = Lident "()"}, _) | Ppat_any;
},
{ppat_desc = Ppat_construct ({txt = Lident "()"}, _)},
expr ) ->
(patternsWithLabel, patternsWithNolabel, expr)
| Pexp_fun
Expand Down
11 changes: 11 additions & 0 deletions tests/ppx/react/aliasProps.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@@jsxConfig({version: 4, mode: "automatic"})

module C0 = {
@react.component
let make = (~priority as _, ~text="Test") => React.string(text)
}

module C1 = {
@react.component
let make = (~priority as p, ~text="Test") => React.string(p ++ text)
}
45 changes: 45 additions & 0 deletions tests/ppx/react/expected/aliasProps.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@@jsxConfig({version: 4, mode: "automatic"})

module C0 = {
type props<'priority, 'text> = {
priority: 'priority,
text?: 'text,
}

@react.component
let make = ({priority: _, ?text, _}: props<'priority, 'text>) => {
let text = switch text {
| Some(text) => text
| None => "Test"
}

React.string(text)
}
let make = {
let \"AliasProps$C0" = (props: props<_>) => make(props)

\"AliasProps$C0"
}
}

module C1 = {
type props<'priority, 'text> = {
priority: 'priority,
text?: 'text,
}

@react.component
let make = ({priority: p, ?text, _}: props<'priority, 'text>) => {
let text = switch text {
| Some(text) => text
| None => "Test"
}

React.string(p ++ text)
}
let make = {
let \"AliasProps$C1" = (props: props<_>) => make(props)

\"AliasProps$C1"
}
}

0 comments on commit 2a017ca

Please sign in to comment.