fix(transformer/react): react refresh panics when encounter use hook (#5768)

close: #5766

I even forgot that React has a `use` hook in the latest version
This commit is contained in:
Dunqing 2024-09-13 16:17:33 +00:00
parent e8bf30a125
commit 3cc38dfc05
3 changed files with 4 additions and 2 deletions

View file

@ -930,7 +930,7 @@ fn is_componentish_name(name: &str) -> bool {
}
fn is_use_hook_name(name: &str) -> bool {
name.starts_with("use") && name.chars().nth(3).unwrap().is_ascii_uppercase()
name.starts_with("use") && name.as_bytes().get(3).map_or(true, u8::is_ascii_uppercase)
}
#[rustfmt::skip]

View file

@ -10,5 +10,6 @@ export default function App() {
const baz = FancyHook.useThing();
React.useState();
useThePlatform();
use();
return <h1>{bar}{baz}</h1>;
}

View file

@ -15,9 +15,10 @@ export default function App() {
const baz = FancyHook.useThing();
React.useState();
useThePlatform();
use();
return _jsxs("h1", { children: [bar, baz] });
}
_s2(App, "useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}", true, function() {
_s2(App, "useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}\\nuse{}", true, function() {
return [FancyHook.useThing];
});
_c = App;