diff --git a/napi/transform/src/options.rs b/napi/transform/src/options.rs index b07a71e916a50..8717836679e4b 100644 --- a/napi/transform/src/options.rs +++ b/napi/transform/src/options.rs @@ -161,7 +161,7 @@ impl From 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() } } diff --git a/napi/transform/test.mjs b/napi/transform/test.mjs index e8484f12fc494..12219fda777f1 100644 --- a/napi/transform/test.mjs +++ b/napi/transform/test.mjs @@ -35,3 +35,35 @@ test(oxc.transform('test.ts', 'class A {}', { 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 ; + }; +`, + { 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', + }, +);