Skip to content

Commit 892b2cf

Browse files
committed
fix: small issues discovered in testing
1 parent 41a219a commit 892b2cf

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/transpilation/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function getBundleResult(program: ts.Program, files: ProcessedFile[]): [t
107107

108108
// return require("<entry module path>")
109109
const args = options.luaTarget === LuaTarget.Lua50 ? "unpack(arg == nil and {} or arg)" : "...";
110-
const entryPoint = `return require(${createModulePath(entryModuleFilePath ?? entryModule, program)}, ${args}})\n`;
110+
const entryPoint = `return require(${createModulePath(entryModuleFilePath ?? entryModule, program)}, ${args})\n`;
111111

112112
const footers: string[] = [];
113113
if (options.sourceMapTraceback) {

test/json.50.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ local function encode_table(val, stack)
7777
-- Treat as array -- check keys are valid and it is not sparse
7878
local n = 0
7979
for k in pairs(val) do
80-
if type(k) ~= "number" then
81-
error("invalid table: mixed or invalid key types")
80+
if k ~= "n" then
81+
if type(k) ~= "number" then
82+
error("invalid table: mixed or invalid key types")
83+
end
84+
n = n + 1
8285
end
83-
n = n + 1
8486
end
8587
if n ~= table.getn(val) then
8688
error("invalid table: sparse array")
@@ -107,7 +109,7 @@ end
107109

108110

109111
local function encode_string(val)
110-
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
112+
return '"' .. string.gsub(val, '[%z\1-\31\\"]', escape_char) .. '"'
111113
end
112114

113115

test/transpile/lualib.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as ts from "typescript";
2-
import { LuaLibFeature } from "../../src";
2+
import { LuaLibFeature, LuaTarget } from "../../src";
33
import { readLuaLibFeature } from "../../src/LuaLib";
44
import * as util from "../util";
55

66
test.each(Object.entries(LuaLibFeature))("Lualib does not use ____exports (%p)", (_, feature) => {
7-
const lualibCode = readLuaLibFeature(feature, ts.sys);
7+
const lualibCode = readLuaLibFeature(feature, LuaTarget.Lua54, ts.sys);
88

99
const exportsOccurrences = lualibCode.match(/____exports/g);
1010
expect(exportsOccurrences).toBeNull();

test/util.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import * as ts from "typescript";
99
import * as vm from "vm";
1010
import * as tstl from "../src";
1111
import { createEmitOutputCollector } from "../src/transpilation/output-collector";
12-
import { EmitHost, getEmitOutDir, transpileProject } from "../src";
12+
import { EmitHost, getEmitOutDir, LuaTarget, transpileProject } from "../src";
1313
import { formatPathToLuaPath, normalizeSlashes } from "../src/utils";
1414

15-
const luaLib = fs.readFileSync(path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"), "utf8");
15+
function readLuaLib(target: tstl.LuaTarget) {
16+
const luaLibDir = `../dist/${target === LuaTarget.Lua50 ? "lualib-lua50" : "lualib"}`;
17+
return fs.readFileSync(path.resolve(__dirname, `${luaLibDir}/lualib_bundle.lua`), "utf8");
18+
}
1619

1720
function jsonLib(target: tstl.LuaTarget): string {
1821
const fileName = target === tstl.LuaTarget.Lua50 ? "json.50.lua" : "json.lua";
@@ -425,7 +428,7 @@ export abstract class TestBuilder {
425428
this.options.luaLibImport === tstl.LuaLibImportKind.Require ||
426429
mainFile.includes('require("lualib_bundle")')
427430
) {
428-
this.injectLuaFile(L, lua, lauxlib, "lualib_bundle", luaLib);
431+
this.injectLuaFile(L, lua, lauxlib, "lualib_bundle", readLuaLib(luaTarget));
429432
}
430433

431434
// Load all transpiled files into Lua's package cache

0 commit comments

Comments
 (0)