-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Babel compatible AST #1392
Comments
It's not hard, but not trivial at all. |
There are also some cases were babel made some incorrect namings in their AST #548 Also, generally SWC moves faster than Babel and so sometimes SWC is ahead with their support for TS language features. So SWC could implement something then Babel could come along and implement it with a different AST shape. |
Just curious, won't this eventually need to be done to support #1321 ? |
@dwoznicki Yes, this is required for #1321. |
Thank you for such a nice project :). I'm working on putout code transformer, it has support of the most popular JavaScript parsers that producing estree and babel AST (with help of estree-to-babel adapter). This made to have ability to switch into fastest one, right now As I see About |
@coderaiser I know it worths it, but I just don't have time. |
@kdy1, Also would be amazing to have ability to get |
Heya, I noticed |
Yes, some more works are required |
I started working on |
I'm also going to write babel-plugin runner so I'm not sure if |
I want to use Also would be nice to have |
Maybe acorn's AST is more standard. |
I tried this, but actually, it was slower. But returning the parsed ast back to javascript world was too slow. This is the number I get. This is rust-side benchmark, which uses same file but from rust side. It's about 37365 ops / sec. I'll investigate a way to make crossing boundaries faster. |
In my mind, |
@SoloJiang For 2, I'm working hard on it. For 3, https://swc.rs/docs/online-repl although it's does not show ast. For 4, can you elaborate? What does code like |
For 4: like this https://babeljs.io/docs/en/babel-generator. Developer can use it verify their plugin quickly. |
For 1: my meaning is not runtime speed. Okay, my presentation problem. I mean may it create AST nodes very quickly.... |
I don't think it's necessary to be compatible with Babel's AST standard, but I'm still worried about the data transfer between rust and js, which is a performance bottleneck. I have seen that parcel operates AST directly on the rust side (using wasm), which seems to be the best solution at present, but swc does not provide a plugin system for rust. |
I'll fix |
@yisar you are right, but js plugin system for the front end developer is more friendly? rust plugin system and js plugin system, we all need =。= ... The decision to use the plugin system should be the developer's. |
@yisar I came up with an idea. I didn't make rust plugin system because
But passing down ast as json to plugin would be performant enough and I can create a wrapper for swc plugins using proc macros. @SoloJiang Do you mean users of swc should decide the language used for plugins? |
For this, I can create t.importDeclaration([t.importDefaultSpecifier(t.identifier(localName)], t.stringLiteral(value)); |
@kdy1 Yeah, I mean this. For performance requirements or for parsing too many files, I might choose Rust. Select JS for other scenarios |
For 3: I mean AST playground, hhhhh |
@kdy1 Unfortunately, I have tested the performance of swc_wasm, but it is still very slow. I feel that it is unreliable to operate AST in js side, because there is no good way to optimize it by serializing AST as JSON and passing it back and forth. Now I can only use swc to operate AST in rust side, and then pass a simple structure to js side. |
@yisar Yes, I also think so. Porting a babel plugin is very easy task to me, but API for plugins is the hard part. |
Just tying this issue to #1366 as any adapter will need valid span/range/start/end values (which are lacking at the moment) |
Hi there, just heard of SWC today and I'm not sure if this is the right place to ask but - I'm curious how one would go about migrating their babel macros to work with SWC ?? I see some documentation on plugins but doesn't quite look like the same thing. |
I'm going to provide a rust plugin api and deprecate node apis. Babel plugins are not supported. |
Just to confirm, does this mean that we should avoid writing plugins similar to the example here: https://swc.rs/docs/usage-plugin? Will this kind of js plugin be deprecated in the future in favour of rust-only plugins? |
@jdb8 Correct. It's simply misdesigned. |
@kdy1 good to know, thanks - I wonder if it would be worth updating that page with a deprecation warning? I was briefly considering porting some plugins from Babel to swc, but I'll definitely now wait until the Rust api is finalised. |
I added it. Thanks! |
@kdy1 would this rust plugin api allow us to build macros similar to babel macros? |
Yes it will. |
I think #2175 is relevant to this discussion. I've done some experiments into ways to speed up |
Out of curiosity, with the Node API deprioritized, is Babel AST compatibility still of interest to this project? |
@Gregoor If there's a need that is helpful to the project, yes. |
This can be a solution: swc-to-babel. But I need a comments as well. I'm working on 🐊 Everything else can be converted, but that's just missing information... Here is {
"type": "File",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"errors": [],
"program": {
"type": "Program",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 9,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 18,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "world"
},
"name": "world"
},
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 26,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 3,
"column": 1
}
},
"body": [],
"directives": []
},
"leadingComments": [
{
"type": "CommentLine",
"value": " hello",
"start": 0,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " hello",
"start": 0,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
}
]
} And {
"type": "Module",
"span": {
"start": 0,
"end": 12,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 0,
"end": 12,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 6,
"end": 11,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 6,
"end": 7,
"ctxt": 0
},
"value": "a",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "NumericLiteral",
"span": {
"start": 10,
"end": 11,
"ctxt": 0
},
"value": 5
},
"definite": false
}
]
}
],
"interpreter": null
} |
Heya,
thanks for this amazingly fast parser! I've been playing with replacing it with Babel's parser, but I also used a number of babel libraries which expect a Babel AST. Namely
span
to be in-lined (collapsingLogicalExpression
intoBinaryExpression
does not seem to be causing problems). Now I was wondering whether the divergence from Babel's AST is wanted? I can imagine integration into all kinds of related libs to be simpler when conforming to their AST more. Or is there a perf cost associated with these differences?Would be curious to learn more and I did not find a past issues that made me understand.
Cheers!
Edit: Oh I also just saw that
BlockStatement
is also shaped differentlyThe text was updated successfully, but these errors were encountered: