Skip to content
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

Closed
klesun opened this issue Mar 17, 2021 · 5 comments
Closed

SWCSWCSWCSWCSWC #16

klesun opened this issue Mar 17, 2021 · 5 comments
Assignees

Comments

@klesun
Copy link
Owner

klesun commented Mar 17, 2021

https://github.com/swc-project/swc

image

@klesun
Copy link
Owner Author

klesun commented Mar 17, 2021

wasm discussion: swc-project/swc#106 (comment)

Hey people, SWC Parser can be built for Wasm!

@klesun klesun self-assigned this Mar 17, 2021
@klesun klesun added the SUPER-HIGHEST PRIORITY! DROP ALL OTHER PROJECTS, START WORKING ON THIS! label Mar 17, 2021
@klesun
Copy link
Owner Author

klesun commented Aug 15, 2024

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.

@klesun
Copy link
Owner Author

klesun commented Aug 15, 2024

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);

@klesun klesun removed the SUPER-HIGHEST PRIORITY! DROP ALL OTHER PROJECTS, START WORKING ON THIS! label Aug 16, 2024
@klesun
Copy link
Owner Author

klesun commented Aug 16, 2024

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()...

@klesun
Copy link
Owner Author

klesun commented Aug 16, 2024

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 useSwc parameter in the lib.

@klesun klesun closed this as completed Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant