-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathesbuild-async.js
More file actions
38 lines (34 loc) · 909 Bytes
/
Copy pathesbuild-async.js
File metadata and controls
38 lines (34 loc) · 909 Bytes
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
// @ts-check
import * as esbuild from "esbuild";
import * as fs from "node:fs";
import { parseTypeScriptAST } from "./ts-parse.js";
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 {esbuild.TransformOptions} */
const options = {
format: "esm",
target: "esnext",
sourcemap: "external",
loader: "ts",
};
async function main() {
const p = [];
for (let i = 0; i < count; i++) {
const out = esbuild.transform(input, options);
p.push(
out.then((out) => {
assert(out.map.length > 100);
assert(out.code.length > 100);
}),
);
}
if (parseTS) {
await parseTypeScriptAST(input, count);
}
await Promise.all(p);
}
main();