aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bun.js/inline.macro.js16
-rw-r--r--test/bun.js/transpiler.test.js85
2 files changed, 81 insertions, 20 deletions
diff --git a/test/bun.js/inline.macro.js b/test/bun.js/inline.macro.js
index ff0292d0a..0fd7491b9 100644
--- a/test/bun.js/inline.macro.js
+++ b/test/bun.js/inline.macro.js
@@ -1,3 +1,19 @@
export function whatDidIPass(expr, ctx) {
return ctx;
}
+
+export function promiseReturningFunction(expr, ctx) {
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ resolve(1);
+ }, 1);
+ });
+}
+
+export function promiseReturningCtx(expr, ctx) {
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ resolve(ctx);
+ }, 1);
+ });
+}
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js
index c81b00ec5..83d30f3b1 100644
--- a/test/bun.js/transpiler.test.js
+++ b/test/bun.js/transpiler.test.js
@@ -109,84 +109,84 @@ describe("Bun.Transpiler", () => {
it("satisfies", () => {
ts.expectPrinted_(
"const t1 = { a: 1 } satisfies I1;",
- "const t1 = { a: 1 };\n"
+ "const t1 = { a: 1 };\n",
);
ts.expectPrinted_(
"const t2 = { a: 1, b: 1 } satisfies I1;",
- "const t2 = { a: 1, b: 1 };\n"
+ "const t2 = { a: 1, b: 1 };\n",
);
ts.expectPrinted_("const t3 = { } satisfies I1;", "const t3 = {};\n");
ts.expectPrinted_(
"const t4: T1 = { a: 'a' } satisfies T1;",
- 'const t4 = { a: "a" };\n'
+ 'const t4 = { a: "a" };\n',
);
ts.expectPrinted_(
"const t5 = (m => m.substring(0)) satisfies T2;",
- "const t5 = (m) => m.substring(0);\n"
+ "const t5 = (m) => m.substring(0);\n",
);
ts.expectPrinted_(
"const t6 = [1, 2] satisfies [number, number];",
- "const t6 = [1, 2];\n"
+ "const t6 = [1, 2];\n",
);
ts.expectPrinted_(
"let t7 = { a: 'test' } satisfies A;",
- 'let t7 = { a: "test" };\n'
+ 'let t7 = { a: "test" };\n',
);
ts.expectPrinted_(
"let t8 = { a: 'test', b: 'test' } satisfies A;",
- 'let t8 = { a: "test", b: "test" };\n'
+ 'let t8 = { a: "test", b: "test" };\n',
);
ts.expectPrinted_(
"export default {} satisfies Foo;",
- "export default {};\n"
+ "export default {};\n",
);
ts.expectPrinted_(
"export default { a: 1 } satisfies Foo;",
- "export default { a: 1 };\n"
+ "export default { a: 1 };\n",
);
ts.expectPrinted_(
"const p = { isEven: n => n % 2 === 0, isOdd: n => n % 2 === 1 } satisfies Predicates;",
- "const p = { isEven: (n) => n % 2 === 0, isOdd: (n) => n % 2 === 1 };\n"
+ "const p = { isEven: (n) => n % 2 === 0, isOdd: (n) => n % 2 === 1 };\n",
);
ts.expectPrinted_(
"let obj: { f(s: string): void } & Record<string, unknown> = { f(s) { }, g(s) { } } satisfies { g(s: string): void } & Record<string, unknown>;",
- "let obj = { f(s) {\n}, g(s) {\n} };\n"
+ "let obj = { f(s) {\n}, g(s) {\n} };\n",
);
ts.expectPrinted_(
"const car = { start() { }, move(d) { }, stop() { } } satisfies Movable & Record<string, unknown>;",
- "const car = { start() {\n}, move(d) {\n}, stop() {\n} };\n"
+ "const car = { start() {\n}, move(d) {\n}, stop() {\n} };\n",
);
ts.expectPrinted_(
"var v = undefined satisfies 1;",
- "var v = undefined;\n"
+ "var v = undefined;\n",
);
ts.expectPrinted_(
"const a = { x: 10 } satisfies Partial<Point2d>;",
- "const a = { x: 10 };\n"
+ "const a = { x: 10 };\n",
);
ts.expectPrinted_(
'const p = { a: 0, b: "hello", x: 8 } satisfies Partial<Record<Keys, unknown>>;',
- 'const p = { a: 0, b: "hello", x: 8 };\n'
+ 'const p = { a: 0, b: "hello", x: 8 };\n',
);
ts.expectPrinted_(
'const p = { a: 0, b: "hello", x: 8 } satisfies Record<Keys, unknown>;',
- 'const p = { a: 0, b: "hello", x: 8 };\n'
+ 'const p = { a: 0, b: "hello", x: 8 };\n',
);
ts.expectPrinted_(
'const x2 = { m: true, s: "false" } satisfies Facts;',
- 'const x2 = { m: true, s: "false" };\n'
+ 'const x2 = { m: true, s: "false" };\n',
);
ts.expectPrinted_(
"export const Palette = { white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, blue: { r: 0, g: 0, b: 255 }, } satisfies Record<string, Color>;",
- "export const Palette = { white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, blue: { r: 0, g: 0, b: 255 } };\n"
+ "export const Palette = { white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, blue: { r: 0, g: 0, b: 255 } };\n",
);
ts.expectPrinted_(
'const a: "baz" = "foo" satisfies "foo" | "bar";',
- 'const a = "foo";\n'
+ 'const a = "foo";\n',
);
ts.expectPrinted_(
'const b: { xyz: "baz" } = { xyz: "foo" } satisfies { xyz: "foo" | "bar" };',
- 'const b = { xyz: "foo" };\n'
+ 'const b = { xyz: "foo" };\n',
);
});
});
@@ -373,6 +373,8 @@ describe("Bun.Transpiler", () => {
macro: {
inline: {
whatDidIPass: `${import.meta.dir}/inline.macro.js`,
+ promiseReturningFunction: `${import.meta.dir}/inline.macro.js`,
+ promiseReturningCtx: `${import.meta.dir}/inline.macro.js`,
},
react: {
bacon: `${import.meta.dir}/macro-check.js`,
@@ -969,6 +971,49 @@ export var ComponentThatHasSpreadCausesDeopt = jsx(Hello, {
`);
});
+ it("macros can return a promise", () => {
+ var object = {
+ helloooooooo: {
+ message: [12345],
+ },
+ };
+
+ const output = bunTranspiler.transformSync(
+ `
+ import {promiseReturningFunction} from 'inline';
+
+ export function foo() {
+ return promiseReturningFunction();
+ }
+ `,
+ object,
+ );
+ expect(output).toBe(`export function foo() {
+ return 1;
+}
+`);
+ });
+
+ it("macros can return a Response body", () => {
+ var object = Response.json({ hello: "world" });
+
+ const input = `
+import {promiseReturningCtx} from 'inline';
+
+export function foo() {
+ return promiseReturningCtx();
+}
+`.trim();
+
+ const output = `
+export function foo() {
+ return { hello: "world" };
+}
+`.trim();
+
+ expect(bunTranspiler.transformSync(input, object).trim()).toBe(output);
+ });
+
it("rewrite string to length", () => {
expectPrinted_(
`export const foo = "a".length + "b".length;`,