-
Notifications
You must be signed in to change notification settings - Fork 8
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
SWCSWCSWCSWCSWC #16
Comments
wasm discussion: swc-project/swc#106 (comment)
|
it's basically as simple as import initSwc, { transformSync } from "https://cdn.jsdelivr.net/npm/@swc/wasm-web@1.7.10/wasm_bg.wasm";
await initSwc();
const result = transformSync(`const zhopa: number = 123`, {
jsc: {
parser: {
syntax: "typescript",
tsx: true,
},
},
});
console.log("ololo result", result); One downside though, swc is 3.5 MiB in compressed form, whereas typescript is 1 MiB in compressed form. So it's a tradeiff between CPU over amount of bytes to fetch before compilation starts. In big projects with loads of typescript files using swc would be worth it. For users that have fast internet, at least 100 Mbit/s it is also worth it. For mobile devices with shitty connection and in a web page without a lot of imports it is not worth it. |
764 kib! import initSwc, { transformSync } from "https://cdn.jsdelivr.net/npm/@swc/wasm-typescript-esm@1.7.10/+esm";
await initSwc();
const result = transformSync(`const zhopa: number = 123`, {
jsc: {
parser: {
syntax: "typescript",
tsx: true,
},
},
});
console.log("ololo result", result); |
Oh, and then there comes the realization that this lib also requires AST traversal for import statements/expression conversion... Should check if @swc/wasm-typescript-esm supports parseSync()... |
Ok, we're back to square one: to switch to SWC we would have to use the 3.5 MiB module for parsing AST as @swc/wasm-typescript-esm appears to only provide the transformSync() function, but not parseSync(). If we are really desperate, then, instead of parsing AST we could use dirty regex replaces... but we are not desperate I think. I guess we can stick to typescript for now and assume that compilation CPU load bottleneck is not greater concern than http latency of fetching each .ts file. If at some point a really big project (probably SPA) with a lot of .ts files and a good internet connection will be suffering from long compilation time, we can consider the 3.5 MiB SWC. For now none of my projects are like that and I'm not aware of the situation of other people using this library. If someone is reading this, and you are using this lib and your project is big enough that the 10-50 ms compilation time per file significantly worsens the experience of your application, you can ping me, that would be good enough motivation for me to implement the |
https://github.com/swc-project/swc
The text was updated successfully, but these errors were encountered: