diff --git a/src/ast/Macro.zig b/src/ast/Macro.zig index 1a7f06c363..546af4b768 100644 --- a/src/ast/Macro.zig +++ b/src/ast/Macro.zig @@ -118,6 +118,7 @@ pub const MacroContext = struct { } macro.vm.enableMacroMode(); defer macro.vm.disableMacroMode(); + macro.vm.eventLoop().ensureWaker(); const Wrapper = struct { args: std.meta.ArgsTuple(@TypeOf(Macro.Runner.run)), @@ -193,6 +194,7 @@ pub fn init( }; vm.enableMacroMode(); + vm.eventLoop().ensureWaker(); const loaded_result = try vm.loadMacroEntryPoint(input_specifier, function_name, specifier, hash); diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index e84d5b2934..d928e59b2f 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -314,7 +314,7 @@ pub fn tickConcurrentWithCount(this: *EventLoop) usize { return this.tasks.count - start_count; } -pub inline fn usocketsLoop(this: *const EventLoop) *uws.Loop { +pub fn usocketsLoop(this: *const EventLoop) *uws.Loop { if (comptime Environment.isWindows) { return this.uws_loop.?; } @@ -553,6 +553,11 @@ pub fn ensureWaker(this: *EventLoop) void { // _ = actual.addPostHandler(*JSC.EventLoop, this, JSC.EventLoop.afterUSocketsTick); // _ = actual.addPreHandler(*JSC.VM, this.virtual_machine.jsc, JSC.VM.drainMicrotasks); } + if (comptime Environment.isWindows) { + if (this.uws_loop == null) { + this.uws_loop = bun.uws.Loop.get(); + } + } bun.uws.Loop.get().internal_loop_data.setParentEventLoop(bun.JSC.EventLoopHandle.init(this)); } diff --git a/test/bundler/transpiler/macro-test.test.ts b/test/bundler/transpiler/macro-test.test.ts index 5eaa5d747c..bc5ea871f3 100644 --- a/test/bundler/transpiler/macro-test.test.ts +++ b/test/bundler/transpiler/macro-test.test.ts @@ -8,6 +8,7 @@ import defaultMacro, { identity, identity as identity1, identity as identity2, + ireturnapromise, } from "./macro.ts" assert { type: "macro" }; import * as macros from "./macro.ts" assert { type: "macro" }; @@ -124,3 +125,7 @@ test("namespace import", () => { // test("template string latin1", () => { // expect(identity(`©${""}`)).toBe("©"); // }); + +test("ireturnapromise", async () => { + expect(await ireturnapromise()).toEqual("aaa"); +}); diff --git a/test/bundler/transpiler/macro.ts b/test/bundler/transpiler/macro.ts index 430fab84ee..9da8d72c5a 100644 --- a/test/bundler/transpiler/macro.ts +++ b/test/bundler/transpiler/macro.ts @@ -17,3 +17,9 @@ export function addStringsUTF16(arg: string) { export default function() { return "defaultdefaultdefault"; } + +export async function ireturnapromise() { + const { promise, resolve } = Promise.withResolvers(); + setTimeout(() => resolve("aaa"), 100); + return promise; +}