-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
traverse: support for getting AstNode by AstNodeId #4746
Comments
I'm sorry to say that what you're asking for is currently impossible in
I can see a possible new API for Is there any other way to make this transform work within this restriction? |
There doesn't seem to be a good way to do this at the moment, it's almost like reimplementing |
I think maybe this would work:
At present, Do you think it can work to move all the "action" into |
Sounds like it would be work
I'm not sure I get your meaning; could you please explain further? |
When I said "move all the action" I meant: do all mutating of the AST in one place in Sorry I wasn't very clear! |
close: #3943 ## Further improvements There is a double visit here. We need to collect all react hooks calling in `Function` and `ArrowFunctionExpression`. If we want to remove this implementation, we may wait for #4188. https://github.com/oxc-project/oxc/blob/d797e595d286c613848b773c256bd43124ad1981/crates/oxc_transformer/src/react/refresh.rs#L744-L947 ## Tests All tests copy from https://github.com/facebook/react/blob/main/packages/react-refresh/src/__tests__/ReactFresh-test.js There are still 4 tests that have not been passed **1. refresh/can-handle-implicit-arrow-returns/input.jsx** Related to #4767. transform correct, just output doesn't match the expected output **2. refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx** **3. refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx** Blocked by #4746 **4. refresh/supports-typescript-namespace-syntax/input.tsx** oxc transforms ts to js first, so probably we can ignore this case. If we really want to pass this test, we also need to turn off `TypeScript` plugin. ## What's next? ### Options: 1. Support transform `refresh_reg` and `refresh_sig` options to `MemberExpression`. Currently `import.meta.xxxx` still is an `Identifier` 2. Support `emit_full_signatures` option ### Other NAPI, testing in `monitor-oxc`, etc..
close: #3943 ## Further improvements There is a double visit here. We need to collect all react hooks calling in `Function` and `ArrowFunctionExpression`. If we want to remove this implementation, we may wait for #4188. https://github.com/oxc-project/oxc/blob/d797e595d286c613848b773c256bd43124ad1981/crates/oxc_transformer/src/react/refresh.rs#L744-L947 ## Tests All tests copy from https://github.com/facebook/react/blob/main/packages/react-refresh/src/__tests__/ReactFresh-test.js There are still 4 tests that have not been passed **1. refresh/can-handle-implicit-arrow-returns/input.jsx** Related to #4767. transform correct, just output doesn't match the expected output **2. refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx** **3. refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx** Blocked by #4746 **4. refresh/supports-typescript-namespace-syntax/input.tsx** oxc transforms ts to js first, so probably we can ignore this case. If we really want to pass this test, we also need to turn off `TypeScript` plugin. ## What's next? ### Options: 1. Support transform `refresh_reg` and `refresh_sig` options to `MemberExpression`. Currently `import.meta.xxxx` still is an `Identifier` 2. Support `emit_full_signatures` option ### Other NAPI, testing in `monitor-oxc`, etc..
Unfortunately, it still hasn't been resolved.
I've tested this solution, but unfortunately, it doesn't work. We can't move the mutation from |
I've thought of two solutions inspired by you:
To be honest, both of the solutions are not good. |
Oh damn, I thought this was solved now.
Glad to hear I inspire bad solutions! 😄 Yes, I'm afraid I don't think either of those solutions is great. Concerning the But I'm not really on top of the React Refresh transform, so I don't have any bright ideas for better solutions at present. When I finally get to look at it properly and understand the logic, maybe I will do. Maybe... |
I agree with you on this point.
Yes, the implementation of the plugin is very complex, and only by understanding its logic can one find a feasible solution. |
related: #4188
I am working on #3943. We need to port a logic from Babel's version plugin, but currently, we can't get the reference node by reference's stored node id. We don't seem to have a workaround to do it right now.
There are two tests related to the above logic here.
https://github.com/facebook/react/blob/ba6a9e94edf0db3ad96432804f9931ce9dc89fec/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js#L253-L333
The text was updated successfully, but these errors were encountered: