diff --git a/src/lualib/Await.ts b/src/lualib/Await.ts index f5c368619..7f6a345ee 100644 --- a/src/lualib/Await.ts +++ b/src/lualib/Await.ts @@ -16,6 +16,7 @@ import { __TS__Promise } from "./Promise"; +const coroutine = _G.coroutine ?? {}; const cocreate = coroutine.create; const coresume = coroutine.resume; const costatus = coroutine.status; diff --git a/test/unit/builtins/loading.spec.ts b/test/unit/builtins/loading.spec.ts index e4363eb8c..563870f6d 100644 --- a/test/unit/builtins/loading.spec.ts +++ b/test/unit/builtins/loading.spec.ts @@ -67,6 +67,17 @@ test("lualib should not include tstl header", () => { ); }); +test("using lualib does not crash when coroutine is not defined", () => { + util.testModule` + declare const _G: any; + declare function require(this: void, name: string): any + + _G.coroutine = undefined; + require("lualib_bundle"); + export const result = 1 + `.expectToEqual({ result: 1 }); +}); + describe("Unknown builtin property", () => { test("access", () => { util.testExpression`Math.unknownProperty`