-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathswc-wasm.js
40 lines (35 loc) · 901 Bytes
/
swc-wasm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// @ts-check
import * as swc from "@swc/wasm";
import * as fs from "node:fs";
function assert(v) {
if (!v) throw new Error();
}
const input = fs.readFileSync(process.argv[2], "utf-8");
const count = Number(process.argv[3]) || 100;
const parseTS = process.argv.includes("--ts-ast");
/** @type {swc.Options} */
const options = {
filename: "input.ts",
sourceMaps: true,
isModule: true,
jsc: {
target: "es2022",
},
};
/** @type {swc.ParseOptions} */
const parseOptions = {
syntax: "typescript",
target: "es2022",
};
for (let i = 0; i < count; i++) {
let out;
if (parseTS) {
const ast = swc.parseSync(input, parseOptions);
assert(ast.body);
out = swc.transformSync(input, options);
} else {
out = swc.transformSync(input, options);
}
assert((out.map?.length ?? 0) > 100);
assert(out.code.length > 100);
}