aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench/snippets/transpiler.mjs38
-rw-r--r--integration/bunjs-only-snippets/transpiler.test.js6
2 files changed, 43 insertions, 1 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);
diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js
index 0a33954c5..8480dd091 100644
--- a/integration/bunjs-only-snippets/transpiler.test.js
+++ b/integration/bunjs-only-snippets/transpiler.test.js
@@ -52,7 +52,11 @@ describe("Bun.Transpiler", () => {
describe("transform", () => {
it("removes types", () => {
- const out = transpiler.transform(code);
+ expect(code.includes("ActionFunction")).toBe(true);
+ expect(code.includes("LoaderFunction")).toBe(true);
+
+ const out = transpiler.transformSync(code);
+
expect(out.includes("ActionFunction")).toBe(false);
expect(out.includes("LoaderFunction")).toBe(false);