Skip to content

Commit 13d880d

Browse files
committed
Fix issue with preserve mode where jsx is declared as an external without a @module attribute
Fixes #7577
1 parent a20fa10 commit 13d880d

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- 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
4141
- Pass location to children prop in jsx ppx. https://github.com/rescript-lang/rescript/pull/7540
4242
- Fix crash when `bs-g` is used with untagged variants. https://github.com/rescript-lang/rescript/pull/7575
43+
- Fix issue with preserve mode where `jsx` is declared as an external without a `@module` attribute. https://github.com/rescript-lang/rescript/pull/7591
4344

4445
#### :nail_care: Polish
4546

compiler/core/js_dump.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
533533
( ({
534534
expression_desc =
535535
J.Var
536-
(J.Qualified
537-
( _,
538-
Some fnName
539-
(* We care about the function name when it is jsxs,
536+
( Id {name = fnName}
537+
| J.Qualified
538+
( _,
539+
Some fnName
540+
(* We care about the function name when it is jsxs,
540541
If this is the case, we need to unpack an array later on *)
541-
));
542+
) );
542543
} as e),
543544
el,
544545
{call_transformed_jsx = true} )

tests/tests/src/jsx_preserve_test.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ let _props_with_hyphen = <label
208208
data-testid={"test"}
209209
/>;
210210

211+
let React = {};
212+
213+
let _fragment = <Fragment>
214+
{"Hello, world!"}
215+
</Fragment>;
216+
211217
export {
212218
Icon,
213219
_single_element_child,
@@ -234,5 +240,7 @@ export {
234240
ComponentWithOptionalProps,
235241
_optional_props,
236242
_props_with_hyphen,
243+
React,
244+
_fragment,
237245
}
238246
/* _single_element_child Not a pure module */

tests/tests/src/jsx_preserve_test.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,16 @@ module ComponentWithOptionalProps = {
128128
let _optional_props = <ComponentWithOptionalProps i=1 s="test" element={<div />} />
129129

130130
let _props_with_hyphen = <label ariaLabel={"close sidebar"} dataTestId="test" />
131+
132+
module React = {
133+
type component<'props> = Jsx.component<'props>
134+
type element = Jsx.element
135+
136+
external jsx: (component<'props>, 'props) => element = "jsx"
137+
138+
type fragmentProps = {children?: element}
139+
140+
external jsxFragment: component<fragmentProps> = "Fragment"
141+
}
142+
143+
let _fragment = <> {Jsx.string("Hello, world!")} </>

0 commit comments

Comments
 (0)