Skip to content
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

fix(napi/transformer): refresh plugin doesn't work even after passing the refresh option #5702

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
2 changes: 1 addition & 1 deletion napi/transform/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl From<ReactBindingOptions> for ReactOptions {
pragma_frag: options.pragma_frag,
use_built_ins: options.use_built_ins,
use_spread: options.use_spread,
refresh: ops.refresh.map(Into::into),
refresh: options.refresh.map(Into::into),
..Default::default()
}
}
Expand Down
32 changes: 32 additions & 0 deletions napi/transform/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,35 @@ test(oxc.transform('test.ts', 'class A<T> {}', { sourcemap: true }), {
version: 3,
},
});

// Test react refresh plugin
test(
oxc.transform(
'test.tsx',
`
import { useState } from "react";
export const App = () => {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>count is {count}</button>;
};
`,
{ react: { refresh: {} } },
),
{
code: 'var _s = $RefreshSig$();\n' +
'import { useState } from "react";\n' +
'import { jsxs as _jsxs } from "react/jsx-runtime";\n' +
'export const App = () => {\n' +
'\t_s();\n' +
'\tconst [count, setCount] = useState(0);\n' +
'\treturn _jsxs("button", {\n' +
'\t\tonClick: () => setCount(count + 1),\n' +
'\t\tchildren: ["count is ", count]\n' +
'\t});\n' +
'};\n' +
'_s(App, "oDgYfYHkD9Wkv4hrAPCkI/ev3YU=");\n' +
'_c = App;\n' +
'var _c;\n' +
'$RefreshReg$(_c, "App");\n',
},
);