Skip to content

Commit 8ce2350

Browse files
committed
Add global assign test
1 parent 6b9e7a8 commit 8ce2350

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

test/transpile/lualib.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import * as ts from "typescript";
22
import { LuaLibFeature } from "../../src";
33
import { readLuaLibFeature } from "../../src/LuaLib";
4+
import * as util from "../util";
45

56
test.each(Object.entries(LuaLibFeature))("Lualib does not use ____exports (%p)", (_, feature) => {
67
const lualibCode = readLuaLibFeature(feature, ts.sys);
78

89
const exportsOccurrences = lualibCode.match(/____exports/g);
910
expect(exportsOccurrences).toBeNull();
1011
});
12+
13+
test("Lualib bundle does not assign globals", () => {
14+
// language=TypeScript
15+
util.testModule`
16+
declare const _G: LuaTable;
17+
declare const require: (this: void, module: string) => any;
18+
const globalKeys = new LuaTable();
19+
for (const [key] of _G) {
20+
globalKeys[key] = true;
21+
}
22+
require("lualib_bundle");
23+
for (const [key] of _G) {
24+
if (!globalKeys[key]) {
25+
error("Global was assigned: " + key);
26+
}
27+
}
28+
`
29+
.withLanguageExtensions()
30+
.expectNoExecutionError();
31+
});

0 commit comments

Comments
 (0)