diff options
author | 2022-01-21 04:58:28 -0800 | |
---|---|---|
committer | 2022-01-21 04:58:28 -0800 | |
commit | 4a7b5892af2b16a9ddff960a30a0dbb43c331370 (patch) | |
tree | e270b9bc678a2cffa142379a07ca09568972fbd1 /bench/snippets/transpiler.mjs | |
parent | 9a5aa95893d047db0ab6d83303e30aaf3c9908cc (diff) | |
download | bun-4a7b5892af2b16a9ddff960a30a0dbb43c331370.tar.gz bun-4a7b5892af2b16a9ddff960a30a0dbb43c331370.tar.zst bun-4a7b5892af2b16a9ddff960a30a0dbb43c331370.zip |
Add a little benchmark for transpiling from inside JS
Diffstat (limited to 'bench/snippets/transpiler.mjs')
-rw-r--r-- | bench/snippets/transpiler.mjs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bench/snippets/transpiler.mjs b/bench/snippets/transpiler.mjs new file mode 100644 index 000000000..b4c1d390d --- /dev/null +++ b/bench/snippets/transpiler.mjs @@ -0,0 +1,38 @@ +import { readFileSync } from "fs"; + +var transformSync; +var opts; +if (process.isBun) { + const transpiler = new Bun.Transpiler({ loader: "jsx" }); + transformSync = transpiler.transformSync.bind(transpiler); + opts = "jsx"; +} else if (process.env["USE_ESBUILD"]) { + try { + const esbuild = await import("esbuild"); + transformSync = esbuild.transformSync; + opts = { loader: "jsx" }; + } catch (exception) { + throw exception; + } +} else if (process.env["USE_SWC"]) { + try { + const swc = await import("@swc/core"); + transformSync = swc.transformSync; + opts = { + sourceMaps: false, + inlineSourcesContent: false, + jsc: { + target: "es2022", + parser: { + jsx: true, + }, + }, + }; + } catch (exception) { + throw exception; + } +} + +const code = readFileSync("src/test/fixtures/simple.jsx", "utf8"); + +transformSync(code, opts); |