Skip to content

Commit d12017d

Browse files
committed
Fixed Laulib Inline/Export order & Fixed lualib build not cleanung up
1 parent 837deef commit d12017d

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

build_lualib.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import concat = require("concat");
22
import * as glob from "glob";
33
import {compile} from "./src/Compiler";
4+
import * as fs from "fs";
5+
6+
const bundlePath = "./dist/lualib/lualib_bundle.lua";
47

58
compile([
69
"--luaLibImport",
@@ -15,4 +18,6 @@ compile([
1518
...glob.sync("./src/lualib/*.ts"),
1619
]);
1720

18-
concat(glob.sync("./dist/lualib/*.lua"), "./dist/lualib/lualib_bundle.lua");
21+
fs.unlinkSync(bundlePath);
22+
23+
concat(glob.sync("./dist/lualib/*.lua"), bundlePath);

src/CommandLineParser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ export class CLIError extends Error {
1818
}
1919

2020
const optionDeclarations: { [key: string]: yargs.Options } = {
21-
noHeader: {
22-
default: false,
23-
describe: "Specify if a header will be added to compiled files.",
24-
type: "boolean",
25-
},
2621
luaLibImport: {
2722
choices: ["inline", "require", "none"],
2823
default: "inline",
@@ -36,6 +31,11 @@ const optionDeclarations: { [key: string]: yargs.Options } = {
3631
describe: "Specify Lua target version.",
3732
type: "string",
3833
},
34+
noHeader: {
35+
default: false,
36+
describe: "Specify if a header will be added to compiled files.",
37+
type: "boolean",
38+
},
3939
};
4040

4141
/**

src/Compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function compileFilesWithOptions(fileNames: string[], options: CompilerOp
5151
try {
5252
const rootDir = options.rootDir;
5353

54-
console.log(`Transpiling ${sourceFile.fileName}...`);
54+
// console.log(`Transpiling ${sourceFile.fileName}...`);
5555

5656
// Transpile AST
5757
const lua = createTranspiler(checker, options, sourceFile).transpileSourceFile();

src/Transpiler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,20 @@ export abstract class LuaTranspiler {
187187
result += "local exports = exports or {}\n";
188188
}
189189

190+
// Transpile content statements
191+
this.exportStack.push([]);
192+
this.sourceFile.statements.forEach(s => result += this.transpileNode(s));
193+
190194
// Inline lualib features
191195
if (this.options.luaLibImport === LuaLibImportKind.Inline) {
196+
result += "\n" + "-- Lua Library Imports\n";
192197
for (const feature of this.luaLibFeatureSet) {
193198
const featureFile = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
194-
result += fs.readFileSync(featureFile) + "\n";
199+
result += fs.readFileSync(featureFile).toString() + "\n";
195200
}
196201
}
197202

198-
// Transpile content statements
199-
this.exportStack.push([]);
200-
this.sourceFile.statements.forEach(s => result += this.transpileNode(s));
203+
// Exports
201204
result += this.makeExports();
202205

203206
if (this.isModule) {

test/src/util.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import * as ts from "typescript";
21
import * as path from "path";
2+
import * as ts from "typescript";
33

44
import { Expect } from "alsatian";
55

6-
import { LuaTarget, LuaTranspiler, TranspileError } from "../../src/Transpiler";
76
import { CompilerOptions } from "../../src/CommandLineParser";
87
import { createTranspiler } from "../../src/Compiler";
8+
import { LuaTarget, LuaTranspiler, TranspileError } from "../../src/Transpiler";
99

1010
import {lauxlib, lua, lualib, to_jsstring, to_luastring } from "fengari";
1111

1212
const fs = require("fs");
1313

14-
const libSource = fs.readFileSync(path.join(path.dirname(require.resolve('typescript')), 'lib.es6.d.ts')).toString();
14+
const libSource = fs.readFileSync(path.join(path.dirname(require.resolve("typescript")), "lib.es6.d.ts")).toString();
1515

16-
export function transpileString(str: string, options: CompilerOptions = { luaLibImport: "require", luaTarget: LuaTarget.Lua53 }): string {
16+
export function transpileString(str: string, options: CompilerOptions = { luaLibImport: "none", luaTarget: LuaTarget.Lua53 }): string {
1717
const compilerHost = {
1818
directoryExists: () => true,
1919
fileExists: (fileName): boolean => true,
@@ -118,4 +118,4 @@ const tslualib = fs.readFileSync("dist/lualib/lualib_bundle.lua") + "\n";
118118

119119
const jsonlib = fs.readFileSync("test/src/json.lua") + "\n";
120120

121-
export const minimalTestLib = tslualib + jsonlib;
121+
export const minimalTestLib = tslualib + jsonlib;

0 commit comments

Comments
 (0)