-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(node-swc): Babel ast translator #1465
Conversation
Wow, thank you for such enormous work! |
Will you implement the conversion from swc ast to babel ast? |
Sorry, yes, I am working on the conversions. It's slow going for.. well, a variety of reasons. Perhaps it would be helpful if you gave me a generic example of how you expect the |
@dwoznicki Good to hear. I'll add some examples for it tomorrow. (It's time to go sleep in my country) |
I did some work. Please feel free to ping me if you need ant help. I added some methods to convert 'common' types, and converting other ast nodes would be simillar. |
Cool, thanks. I'll let you know if I have any trouble. |
@kdy1 Hey, a couple questions for you.
|
|
@kdy1 Cool, thanks. Okay, another question. I've found several places where the swc node does not convert cleanly into a babel node, and I need to throw/return an error if the tree is invalid. How should I handle this? Should I modify the |
@dwoznicki I think so. Panic would also work, but it doesn't look good. |
@kdy1 Hey, quick question. The swc |
@dwoznicki Currently there's no way to do it. Taking lower |
Great, yeah, that appears to work. Thanks. |
I'll extract ast definitions from the pr so that I can use them to implement the babel plugin runner. |
Oh, I've fixed a couple things since. Let me make a push right quick. I suspect there will be more problems with my definitions that'll need fixing. |
@dwoznicki Oh, thanks! |
It's up. Are you implementing a babel plugin runner in Rust? |
@devongovett I'd like to, but I need to do some experiments to see if it's possible. |
And thanks! |
@kdy1 If you manage to get it working, can you let me know if you solve this issue? napi-rs/napi-rs#436 I got stuck here while trying to implement Webpack plugins. |
Ok, I'll try workarouding it and I'll cc you when I make a success. |
First pass at conversion is done. It's pretty rough, and completely untested. I'll fix it up as I write tests. |
Sounds great! |
I'll take a look tonight |
@kdy1 Hey, I want to get your thoughts on a couple things.
|
For 1, I think the safety line would be babel-plugin compatibility. I expect the plugin system to work even though some ast differs (e.g. For 2, I don't think so. Almost, if not all, babel plugins would not depend on some undocumented fields. And same as 1, we can fit it in the future if it causes a problem. |
Cool thanks. Okay, another more specific question. Babel wraps the top level |
Yes, but not vice versa. The |
Fixed a bug where spread attr had incorrect start pos in swc AST
Fixed a bug related to operator conversion
Fixed a bug with default value for prefix field
Commented out TS test for now
@kdy1 Hey, I think this PR is getting close. There are almost certainly more inconsistencies I've missed, but I'm running out of ideas for tests to write. With one big exception... TypeScript. I've never written TypeScript, so I only understand it conceptually. Writing TS tests is going to take me a while without help. So the question is, do you want to wait for TS compatibility testing before merging? |
@dwoznicki Wow. Nice work! Thank you so much! I don't think typescript conversion is important at the moment. It's because using type information is very complex, and to use type information, what you need the ast of tsc, not babel. So no one would try to use type ast nodes of babel. |
Great! Well, I think this PR is actually ready in the case. I suspect there will be a number of bugs at first, so feel free to @ me for issues. |
Great Thanks! |
This pull request is a WIP.
Let me know if there's anything missing from the todo list.