Skip to content

Commit cb13fbc

Browse files
committed
Revert "Merge branch 'master' into transformer-namespace"
This reverts commit 773afae, reversing changes made to 743912a.
1 parent 773afae commit cb13fbc

6 files changed

Lines changed: 30 additions & 56 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ Large projects written in lua can become hard to maintain and make it easy to ma
88
[![Coverage](https://codecov.io/gh/perryvw/typescripttolua/branch/master/graph/badge.svg)](https://codecov.io/gh/perryvw/typescripttolua)
99
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/TypescriptToLua/Lobby)
1010

11-
You can also find us on Discord: [![Discord](https://img.shields.io/discord/515854149821267971.svg)](https://discord.gg/BWAq58Y)
12-
1311
## Documentation
1412
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/Perryvw/TypescriptToLua/wiki).
1513

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "typescript-to-lua",
33
"license": "MIT",
4-
"version": "0.11.1",
4+
"version": "0.11.0",
55
"repository": "https://github.com/Perryvw/TypescriptToLua",
66
"keywords": [
77
"typescript",

src/Transpiler.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export abstract class LuaTranspiler {
213213
}
214214

215215
// Inline lualib features
216-
if (this.options.luaLibImport === LuaLibImportKind.Inline && this.luaLibFeatureSet.size > 0) {
216+
if (this.options.luaLibImport === LuaLibImportKind.Inline) {
217217
result += "\n" + "-- Lua Library Imports\n";
218218
for (const feature of this.luaLibFeatureSet) {
219219
const featureFile = path.resolve(__dirname, `../dist/lualib/${feature}.lua`);
@@ -1789,30 +1789,29 @@ export abstract class LuaTranspiler {
17891789

17901790
public transpileConstructor(node: ts.ConstructorDeclaration,
17911791
className: string): string {
1792-
// Check for field declarations in constructor
1793-
const constructorFieldsDeclarations = node.parameters.filter(p => p.modifiers !== undefined);
1792+
const extraInstanceFields = [];
17941793

1795-
const [paramNames, spreadIdentifier] = this.transpileParameters(node.parameters);
1796-
1797-
let result = this.indent + `function ${className}.constructor(${["self"].concat(paramNames).join(",")})\n`;
1794+
const parameters = ["self"];
1795+
node.parameters.forEach(param => {
1796+
// If param has decorators, add extra instance field
1797+
if (param.modifiers !== undefined) {
1798+
extraInstanceFields.push(this.transpileIdentifier(param.name as ts.Identifier));
1799+
}
1800+
// Add to parameter list
1801+
parameters.push(this.transpileIdentifier(param.name as ts.Identifier));
1802+
});
17981803

1799-
// Transpile constructor body
1800-
this.pushIndent();
1801-
this.classStack.push(className);
1804+
let result = this.indent + `function ${className}.constructor(${parameters.join(",")})\n`;
18021805

18031806
// Add in instance field declarations
1804-
for (const declaration of constructorFieldsDeclarations) {
1805-
const declarationName = this.transpileIdentifier(declaration.name as ts.Identifier);
1806-
if (declaration.initializer) {
1807-
const value = this.transpileExpression(declaration.initializer);
1808-
result += this.indent + `self.${declarationName} = ${declarationName} or ${value}\n`;
1809-
} else {
1810-
result += this.indent + `self.${declarationName} = ${declarationName}\n`;
1811-
}
1807+
for (const f of extraInstanceFields) {
1808+
result += this.indent + ` self.${f} = ${f}\n`;
18121809
}
18131810

1814-
result += this.transpileFunctionBody(node.parameters, node.body, spreadIdentifier);
1815-
1811+
// Transpile constructor body
1812+
this.pushIndent();
1813+
this.classStack.push(className);
1814+
result += this.transpileBlock(node.body);
18161815
this.classStack.pop();
18171816
this.popIndent();
18181817

test/unit/class.spec.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ClassTests {
4444

4545
@Test("ClassConstructorAssignment")
4646
public classConstructorAssignment(): void {
47-
// Transpile
47+
// Transpile
4848
const lua = util.transpileString(
4949
`class a { constructor(public field: number) {} }
5050
return new a(4).field;`
@@ -57,26 +57,6 @@ export class ClassTests {
5757
Expect(result).toBe(4);
5858
}
5959

60-
@Test("ClassConstructorDefaultParameter")
61-
public classConstructorDefaultParameter(): void {
62-
const result = util.transpileAndExecute(
63-
`class a { public field: number; constructor(f: number = 3) { this.field = f; } }
64-
return new a().field;`
65-
);
66-
67-
Expect(result).toBe(3);
68-
}
69-
70-
@Test("ClassConstructorAssignmentDefault")
71-
public classConstructorAssignmentParameterDefault(): void {
72-
const result = util.transpileAndExecute(
73-
`class a { constructor(public field: number = 3) { } }
74-
return new a().field;`
75-
);
76-
77-
Expect(result).toBe(3);
78-
}
79-
8060
@Test("ClassNewNoBrackets")
8161
public classNewNoBrackets(): void {
8262
// Transpile

test/unit/modules.spec.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export class LuaModuleTests {
2323
Expect(lua.startsWith(`require("lualib_bundle")`));
2424
}
2525

26+
@Test("lualibRequireNoUses")
27+
public lualibRequireNoUses(): void {
28+
// Transpile
29+
const lua = util.transpileString(``, { luaLibImport: LuaLibImportKind.Require, luaTarget: LuaTarget.LuaJIT });
30+
31+
// Assert
32+
Expect(lua).toBe(``);
33+
}
34+
2635
@Test("lualibRequireAlways")
2736
public lualibRequireAlways(): void {
2837
// Transpile
@@ -40,16 +49,4 @@ export class LuaModuleTests {
4049

4150
Expect(result).toBe(3);
4251
}
43-
44-
@TestCase(LuaLibImportKind.Inline)
45-
@TestCase(LuaLibImportKind.None)
46-
@TestCase(LuaLibImportKind.Require)
47-
@Test("LuaLib no uses? No code")
48-
public lualibNoUsesNoCode(impKind: LuaLibImportKind): void {
49-
// Transpile
50-
const lua = util.transpileString(``, { luaLibImport: impKind });
51-
52-
// Assert
53-
Expect(lua).toBe(``);
54-
}
5552
}

0 commit comments

Comments
 (0)