aboutsummaryrefslogtreecommitdiff
path: root/src/api/demo/lib/scan.ts
blob: c2fd7bb129d62d4a9fca40b56f023146cd8ec455 (plain) (blame)
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
import { init, parse } from "es-module-lexer";

import { Bun } from "./api";

export async function start() {
  await init;
  await Bun.init("/bun-wasm.wasm");
}

const swcOptions = {
  sourceMaps: false,
  inlineSourcesContent: false,
  jsc: {
    target: "es2022",
    parser: {
      jsx: true,
      syntax: "typescript",
      tsx: false,
      decorators: false,
      dynamicImport: false,
    },
  },
};

export async function transform(contents, file) {
  var result: any = {
    timings: {
      lexer: 0,
      bun: 0,
    },
  };
  result.timings.lexer = performance.now();
  result.lexer = await parse(contents, file);
  result.timings.lexer = performance.now() - result.timings.lexer;

  result.timings.bun = performance.now();
  result.bun = Bun.scan(contents, file);
  result.timings.bun = performance.now() - result.timings.bun;

  console.log("lexer:", result.timings.lexer, "ms");
  console.log("Bun:", result.timings.bun, "ms");

  return result;
}