Skip to content

Commit f610b5f

Browse files
authored
Fix crash when using lualib_bundle in an environment without coroutines (#1547)
* Don't crash if coroutine not supported * Add test for environment without coroutine * Fix prettier
1 parent 7db98b3 commit f610b5f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/lualib/Await.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { __TS__Promise } from "./Promise";
1818

19+
const coroutine = _G.coroutine ?? {};
1920
const cocreate = coroutine.create;
2021
const coresume = coroutine.resume;
2122
const costatus = coroutine.status;

test/unit/builtins/loading.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ test("lualib should not include tstl header", () => {
6767
);
6868
});
6969

70+
test("using lualib does not crash when coroutine is not defined", () => {
71+
util.testModule`
72+
declare const _G: any;
73+
declare function require(this: void, name: string): any
74+
75+
_G.coroutine = undefined;
76+
require("lualib_bundle");
77+
export const result = 1
78+
`.expectToEqual({ result: 1 });
79+
});
80+
7081
describe("Unknown builtin property", () => {
7182
test("access", () => {
7283
util.testExpression`Math.unknownProperty`

0 commit comments

Comments
 (0)