rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

JSX preserve mode: unused import of "react/jsx-runtime"

Open cknitt opened this issue 7 months ago • 6 comments

When JSX preserve mode is active, the import statement

import * as JsxRuntime from "react/jsx-runtime";

is still emitted to the JS output, but is unused there.

cknitt avatar May 06 '25 09:05 cknitt

@cristianoc do you have any ideas when the import * line is constructed? In which phase would that happen? I think tackling it there might be the safer than avoid it in js_dump (since other code might need it).

nojaf avatar May 08 '25 06:05 nojaf

Do we really need to care about this for v12? Bundlers will just remove it because it's dead anyway.

zth avatar May 08 '25 07:05 zth

@cristianoc do you have any ideas when the import * line is constructed? In which phase would that happen? I think tackling it there might be the safer than avoid it in js_dump (since other code might need it).

Looks like it's coming from a react external. I guess the code is generated that makes use of jsx runtime, but later on dump is customised to emit preserve mode so it appears to be unused (but it was used, before dumping).

cristianoc avatar May 08 '25 07:05 cristianoc

Yes, I'm aware of that, it makes sense why it is there. I'm just wondering, where in the codebase it will organize the imports and how that part works?

nojaf avatar May 08 '25 07:05 nojaf

Yes, I'm aware of that, it makes sense why it is there. I'm just wondering, where in the codebase it will organize the imports and how that part works?

I think it's in Lam_compile_main.compile, which does the last phase of compilation and determines dependencies.

cristianoc avatar May 08 '25 07:05 cristianoc

Do we really need to care about this for v12? Bundlers will just remove it because it's dead anyway.

Certainly not a blocker, but still a bit weird to emit unused imports, we never did that before.

cknitt avatar May 08 '25 08:05 cknitt