Another test for macros

This commit is contained in:
Jarred Sumner
2022-11-25 07:04:08 -08:00
parent e851e5fddb
commit b5bd98c0ef

View File

@@ -995,6 +995,14 @@ export var ComponentThatHasSpreadCausesDeopt = jsx(Hello, {
});
it("macros can return a Response body", () => {
// "promiseReturningCtx" is this:
// export function promiseReturningCtx(expr, ctx) {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(ctx);
// }, 1);
// });
// }
var object = Response.json({ hello: "world" });
const input = `
@@ -1014,6 +1022,34 @@ export function foo() {
expect(bunTranspiler.transformSync(input, object).trim()).toBe(output);
});
it("macros get dead code eliminated", () => {
var object = Response.json({
big: {
object: {
beep: "boop",
huge: 123,
},
blobby: {
beep: "boop",
huge: 123,
},
},
dead: "hello world!",
});
const input = `
import {promiseReturningCtx} from 'inline';
export const {dead} = promiseReturningCtx();
`.trim();
const output = `
export const { dead } = { dead: "hello world!" };
`.trim();
expect(bunTranspiler.transformSync(input, object).trim()).toBe(output);
});
it("rewrite string to length", () => {
expectPrinted_(
`export const foo = "a".length + "b".length;`,