Skip to content

Commit

Permalink
fix(napi/transformer): refresh plugin doesn't work even after passing…
Browse files Browse the repository at this point in the history
… the refresh option (#5702)
  • Loading branch information
Dunqing committed Sep 11, 2024
1 parent c2997f1 commit 608b7d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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',
},
);

0 comments on commit 608b7d3

Please sign in to comment.