-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathswc-native-async.js
More file actions
52 lines (47 loc) · 1.18 KB
/
Copy pathswc-native-async.js
File metadata and controls
52 lines (47 loc) · 1.18 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
// @ts-check
import * as swc from "@swc/core";
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: "esnext",
},
};
/** @type {swc.ParseOptions} */
const parseOptions = {
syntax: "typescript",
target: "esnext",
};
async function main() {
const p = [];
for (let i = 0; i < count; i++) {
let out;
if (parseTS) {
out = Promise.all([
swc.transform(input, options),
swc.parse(input, parseOptions).then((_ast) => {
assert(_ast.body);
}),
]).then(([out]) => out);
} else {
out = swc.transform(input, options);
}
p.push(
out.then((out) => {
assert((out.map?.length ?? 0) > 100);
assert(out.code.length > 100);
}),
);
}
await Promise.all(p);
}
main();