-
Notifications
You must be signed in to change notification settings - Fork 471
JSX preserve mode: fix "make is not a valid component name" #7831
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
Changes from 4 commits
a1e7cc5
fc38b25
9f12bcf
941b636
bd76cf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,15 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | |
let rec simpl (lam : Lam.t) : Lam.t = | ||
match lam with | ||
| Lvar _ -> lam | ||
(* 7432: prevent optimization in JSX preserve mode *) | ||
| Lprim | ||
{ | ||
primitive = Pjs_call {prim_name = "jsx" | "jsxs"} as primitive; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark, very unlikely that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's plenty guarded against risk already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not the same check that preserve mode is on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for preserve mode is already there (below). |
||
args = (Lprim {primitive = Pfield (_, _)} as field_arg) :: rest; | ||
loc; | ||
} | ||
when !Js_config.jsx_preserve -> | ||
Lam.prim ~primitive ~args:(field_arg :: Ext_list.map rest simpl) loc | ||
| Lprim {primitive = Pfield (i, info) as primitive; args = [arg]; loc} -> ( | ||
(* ATTENTION: | ||
Main use case, we should detect inline all immutable block .. *) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ let Foo = { | |
|
||
function Async_jsx$Bar(props) { | ||
return <div> | ||
<Async_jsx$Foo /> | ||
<Foo.make /> | ||
</div>; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
||
import * as React from "react"; | ||
import * as JsxRuntime from "react/jsx-runtime"; | ||
|
||
function Jsx_preserve_test$Icon(props) { | ||
|
@@ -20,7 +21,7 @@ let _multiple_element_children = <div> | |
<h1> | ||
{"Hello, world!"} | ||
</h1> | ||
<Jsx_preserve_test$Icon /> | ||
<Icon.make /> | ||
</div>; | ||
|
||
let _single_element_fragment = <> | ||
|
@@ -141,7 +142,7 @@ let B = { | |
|
||
let _external_component_with_children = <QueryClientProvider> | ||
<strong /> | ||
<Jsx_preserve_test$B /> | ||
<B.make /> | ||
</QueryClientProvider>; | ||
|
||
function Jsx_preserve_test$MyWeirdComponent(props) { | ||
|
@@ -155,7 +156,7 @@ let MyWeirdComponent = { | |
make: Jsx_preserve_test$MyWeirdComponent | ||
}; | ||
|
||
let _escaped_jsx_prop = <Jsx_preserve_test$MyWeirdComponent | ||
let _escaped_jsx_prop = <MyWeirdComponent.make | ||
MyWeirdProp={"bar"} | ||
/>; | ||
|
||
|
@@ -197,7 +198,7 @@ let ComponentWithOptionalProps = { | |
make: Jsx_preserve_test$ComponentWithOptionalProps | ||
}; | ||
|
||
let _optional_props = <Jsx_preserve_test$ComponentWithOptionalProps | ||
let _optional_props = <ComponentWithOptionalProps.make | ||
i={1} | ||
s={"test"} | ||
element={<div />} | ||
|
@@ -208,11 +209,9 @@ let _props_with_hyphen = <label | |
data-testid={"test"} | ||
/>; | ||
|
||
let React = {}; | ||
|
||
let _fragment = <Fragment> | ||
let _fragment = <> | ||
{"Hello, world!"} | ||
</Fragment>; | ||
</>; | ||
|
||
let _youtube_iframe = <iframe | ||
allow={"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"} | ||
|
@@ -224,6 +223,47 @@ let _youtube_iframe = <iframe | |
referrerPolicy={"strict-origin-when-cross-origin"} | ||
/>; | ||
|
||
function make(_props) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding the tests! |
||
return null; | ||
} | ||
|
||
let X = { | ||
make: make | ||
}; | ||
|
||
<X.make />; | ||
|
||
function Jsx_preserve_test$Y(props) { | ||
return null; | ||
} | ||
|
||
let make$1 = React.memo(Jsx_preserve_test$Y); | ||
|
||
let Y = { | ||
x: 42, | ||
make: make$1 | ||
}; | ||
|
||
<Y.make />; | ||
|
||
let context = React.createContext(0); | ||
|
||
let make$2 = context.Provider; | ||
|
||
let ContextProvider = { | ||
make: make$2 | ||
}; | ||
|
||
function Jsx_preserve_test(props) { | ||
return <ContextProvider.make | ||
value={42} | ||
> | ||
{props.children} | ||
</ContextProvider.make>; | ||
} | ||
|
||
let make$3 = Jsx_preserve_test; | ||
|
||
export { | ||
Icon, | ||
_single_element_child, | ||
|
@@ -250,8 +290,12 @@ export { | |
ComponentWithOptionalProps, | ||
_optional_props, | ||
_props_with_hyphen, | ||
React, | ||
_fragment, | ||
_youtube_iframe, | ||
X, | ||
Y, | ||
context, | ||
ContextProvider, | ||
make$3 as make, | ||
} | ||
/* _single_element_child Not a pure module */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check could in theory affect each
make
function right?Could we add some sort of check if that
make
returns aJsx.element
type? Just to further limit the scope when this kicks in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no type this down the compiler stack