Skip to content

Fix issue with preserve mode where jsx is declared as an external w… #7591

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

Merged
merged 1 commit into from
Jul 3, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Prop punning when types don't match results in I/O error: _none_: No such file or directory. https://github.com/rescript-lang/rescript/pull/7533
- Pass location to children prop in jsx ppx. https://github.com/rescript-lang/rescript/pull/7540
- Fix crash when `bs-g` is used with untagged variants. https://github.com/rescript-lang/rescript/pull/7575
- Fix issue with preserve mode where `jsx` is declared as an external without a `@module` attribute. https://github.com/rescript-lang/rescript/pull/7591

#### :nail_care: Polish

Expand Down
11 changes: 6 additions & 5 deletions compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
( ({
expression_desc =
J.Var
(J.Qualified
( _,
Some fnName
(* We care about the function name when it is jsxs,
( Id {name = fnName}
| J.Qualified
( _,
Some fnName
(* We care about the function name when it is jsxs,
If this is the case, we need to unpack an array later on *)
));
) );
} as e),
el,
{call_transformed_jsx = true} )
Expand Down
8 changes: 8 additions & 0 deletions tests/tests/src/jsx_preserve_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ let _props_with_hyphen = <label
data-testid={"test"}
/>;

let React = {};

let _fragment = <Fragment>
{"Hello, world!"}
</Fragment>;

export {
Icon,
_single_element_child,
Expand All @@ -234,5 +240,7 @@ export {
ComponentWithOptionalProps,
_optional_props,
_props_with_hyphen,
React,
_fragment,
}
/* _single_element_child Not a pure module */
13 changes: 13 additions & 0 deletions tests/tests/src/jsx_preserve_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,16 @@ module ComponentWithOptionalProps = {
let _optional_props = <ComponentWithOptionalProps i=1 s="test" element={<div />} />

let _props_with_hyphen = <label ariaLabel={"close sidebar"} dataTestId="test" />

module React = {
type component<'props> = Jsx.component<'props>
type element = Jsx.element

external jsx: (component<'props>, 'props) => element = "jsx"

type fragmentProps = {children?: element}

external jsxFragment: component<fragmentProps> = "Fragment"
}

let _fragment = <> {Jsx.string("Hello, world!")} </>