Skip to content

Commit 5d7278c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into array-table-features
2 parents f68c268 + fff847b commit 5d7278c

23 files changed

+533
-243
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: node_js
2+
3+
node_js:
4+
- 'stable'
5+
6+
install:
7+
- npm install
8+
9+
script:
10+
- tsc -p ./test
11+
- node ./test/runner.js

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# TypescriptToLua
22
Typescript to lua transpiler.
33

4+
[![Build Status](https://travis-ci.org/Perryvw/TypescriptToLua.svg?branch=master)](https://travis-ci.org/Perryvw/TypescriptToLua)
5+
46
## Usage Guide
57

68
#### Prerequisites

dist/TSHelper.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,30 @@ var TSHelper = /** @class */ (function () {
4545
return (type.flags & ts.TypeFlags.Object) != 0
4646
&& type.typeArguments != undefined;
4747
};
48-
TSHelper.isCompileMembersOnlyEnum = function (type) {
48+
TSHelper.isCompileMembersOnlyEnum = function (type, checker) {
4949
return type.symbol
5050
&& ((type.symbol.flags & ts.SymbolFlags.Enum) != 0)
51-
&& type.symbol.getDocumentationComment()[0] != undefined
52-
&& this.hasCustomDecorator(type, "!CompileMembersOnly");
51+
&& type.symbol.getDocumentationComment(checker)[0] != undefined
52+
&& this.hasCustomDecorator(type, checker, "!CompileMembersOnly");
5353
};
54-
TSHelper.isPureAbstractClass = function (type) {
54+
TSHelper.isPureAbstractClass = function (type, checker) {
5555
return type.symbol
5656
&& ((type.symbol.flags & ts.SymbolFlags.Class) != 0)
57-
&& this.hasCustomDecorator(type, "!PureAbstract");
57+
&& this.hasCustomDecorator(type, checker, "!PureAbstract");
5858
};
59-
TSHelper.isExtensionClass = function (type) {
59+
TSHelper.isExtensionClass = function (type, checker) {
6060
return type.symbol
6161
&& ((type.symbol.flags & ts.SymbolFlags.Class) != 0)
62-
&& this.hasCustomDecorator(type, "!Extension");
62+
&& this.hasCustomDecorator(type, checker, "!Extension");
6363
};
64-
TSHelper.isPhantom = function (type) {
64+
TSHelper.isPhantom = function (type, checker) {
6565
return type.symbol
6666
&& ((type.symbol.flags & ts.SymbolFlags.Namespace) != 0)
67-
&& this.hasCustomDecorator(type, "!Phantom");
67+
&& this.hasCustomDecorator(type, checker, "!Phantom");
6868
};
69-
TSHelper.hasCustomDecorator = function (type, decorator) {
69+
TSHelper.hasCustomDecorator = function (type, checker, decorator) {
7070
if (type.symbol) {
71-
var comment = type.symbol.getDocumentationComment();
71+
var comment = type.symbol.getDocumentationComment(checker);
7272
var decorators = comment.filter(function (_) { return _.kind == "text"; }).map(function (_) { return _.text.trim(); }).filter(function (_) { return _[0] == "!"; });
7373
return decorators.indexOf(decorator) > -1;
7474
}

dist/Transpiler.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ var LuaTranspiler = /** @class */ (function () {
137137
};
138138
LuaTranspiler.prototype.transpileNamespace = function (node) {
139139
// If phantom namespace just transpile the body as normal
140-
if (TSHelper_1.TSHelper.isPhantom(this.checker.getTypeAtLocation(node)))
140+
if (TSHelper_1.TSHelper.isPhantom(this.checker.getTypeAtLocation(node), this.checker))
141141
return this.transpileNode(node.body);
142142
var defName = this.definitionName(node.name.text);
143143
var result = this.indent + (defName + " = {}\n");
@@ -151,7 +151,7 @@ var LuaTranspiler = /** @class */ (function () {
151151
var val = 0;
152152
var result = "";
153153
var type = this.checker.getTypeAtLocation(node);
154-
var membersOnly = TSHelper_1.TSHelper.isCompileMembersOnlyEnum(type);
154+
var membersOnly = TSHelper_1.TSHelper.isCompileMembersOnlyEnum(type, this.checker);
155155
if (!membersOnly) {
156156
var defName = this.definitionName(node.name.escapedText);
157157
result += this.indent + (defName + "={}\n");
@@ -386,6 +386,12 @@ var LuaTranspiler = /** @class */ (function () {
386386
case ts.SyntaxKind.MinusEqualsToken:
387387
result = lhs + "=" + lhs + "-" + rhs;
388388
break;
389+
case ts.SyntaxKind.AsteriskEqualsToken:
390+
result = lhs + "=" + lhs + "*" + rhs;
391+
break;
392+
case ts.SyntaxKind.SlashEqualsToken:
393+
result = lhs + "=" + lhs + "/" + rhs;
394+
break;
389395
case ts.SyntaxKind.AmpersandAmpersandToken:
390396
result = lhs + " and " + rhs;
391397
break;
@@ -432,7 +438,7 @@ var LuaTranspiler = /** @class */ (function () {
432438
var condition = this.transpileExpression(node.condition);
433439
var val1 = this.transpileExpression(node.whenTrue);
434440
var val2 = this.transpileExpression(node.whenFalse);
435-
return "TS_ITE(" + condition + ",function() return " + val1 + " end, function() return " + val2 + " end)";
441+
return "TS_ITE(" + condition + ",function() return " + val1 + " end,function() return " + val2 + " end)";
436442
};
437443
// Replace some missmatching operators
438444
LuaTranspiler.prototype.transpileOperator = function (operator) {
@@ -450,9 +456,9 @@ var LuaTranspiler = /** @class */ (function () {
450456
var operand = this.transpileExpression(node.operand, true);
451457
switch (node.operator) {
452458
case ts.SyntaxKind.PlusPlusToken:
453-
return operand + " = " + operand + " + 1";
459+
return operand + "=" + operand + "+1";
454460
case ts.SyntaxKind.MinusMinusToken:
455-
return operand + " = " + operand + " - 1";
461+
return operand + "=" + operand + "-1";
456462
default:
457463
throw new TranspileError("Unsupported unary postfix: " + TSHelper_1.TSHelper.enumName(node.kind, ts.SyntaxKind), node);
458464
}
@@ -461,9 +467,9 @@ var LuaTranspiler = /** @class */ (function () {
461467
var operand = this.transpileExpression(node.operand, true);
462468
switch (node.operator) {
463469
case ts.SyntaxKind.PlusPlusToken:
464-
return operand + " = " + operand + " + 1";
470+
return operand + "=" + operand + "+1";
465471
case ts.SyntaxKind.MinusMinusToken:
466-
return operand + " = " + operand + " - 1";
472+
return operand + "=" + operand + "-1";
467473
case ts.SyntaxKind.ExclamationToken:
468474
return "not " + operand;
469475
case ts.SyntaxKind.MinusToken:
@@ -584,7 +590,7 @@ var LuaTranspiler = /** @class */ (function () {
584590
return this.transpileArrayProperty(node);
585591
}
586592
// Do not output path for member only enums
587-
if (TSHelper_1.TSHelper.isCompileMembersOnlyEnum(type)) {
593+
if (TSHelper_1.TSHelper.isCompileMembersOnlyEnum(type, this.checker)) {
588594
return property;
589595
}
590596
var path = this.transpileExpression(node.expression);
@@ -717,16 +723,16 @@ var LuaTranspiler = /** @class */ (function () {
717723
if (clause.token == ts.SyntaxKind.ExtendsKeyword) {
718724
var superType = _this.checker.getTypeAtLocation(clause.types[0]);
719725
// Ignore purely abstract types (decorated with /** @PureAbstract */)
720-
if (!TSHelper_1.TSHelper.isPureAbstractClass(superType)) {
726+
if (!TSHelper_1.TSHelper.isPureAbstractClass(superType, _this.checker)) {
721727
extendsType = clause.types[0];
722728
}
723-
noClassOr = TSHelper_1.TSHelper.hasCustomDecorator(superType, "!NoClassOr");
729+
noClassOr = TSHelper_1.TSHelper.hasCustomDecorator(superType, _this.checker, "!NoClassOr");
724730
}
725731
});
726732
var className = node.name.escapedText;
727733
var result = "";
728734
// Skip header if this is an extension class
729-
var isExtension = TSHelper_1.TSHelper.isExtensionClass(this.checker.getTypeAtLocation(node));
735+
var isExtension = TSHelper_1.TSHelper.isExtensionClass(this.checker.getTypeAtLocation(node), this.checker);
730736
if (!isExtension) {
731737
// Write class declaration
732738
var classOr = noClassOr ? "" : className + " or ";
@@ -785,6 +791,12 @@ var LuaTranspiler = /** @class */ (function () {
785791
node.members.filter(ts.isMethodDeclaration).forEach(function (method) {
786792
result += _this.transpileMethodDeclaration(method, className + ".");
787793
});
794+
// Check if the class should be returned
795+
var isExport = node.modifiers && node.modifiers.some(function (_) { return _.kind == ts.SyntaxKind.ExportKeyword; });
796+
var isDefault = node.modifiers && node.modifiers.some(function (_) { return _.kind == ts.SyntaxKind.DefaultKeyword; });
797+
if (isExport && isDefault) {
798+
result += this.indent + ("return " + className + "\n");
799+
}
788800
return result;
789801
};
790802
LuaTranspiler.prototype.transpileConstructor = function (node, className, instanceFields) {

dist/lualib/typescript.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ function TS_filter(list, func)
3232
end
3333

3434
function TS_slice(list, startI, endI)
35-
endI = endI or (#list-1)
35+
endI = endI or #list
36+
if startI < 0 then startI = #list + startI end
37+
if endI < 0 then endI = #list + endI end
3638
local out = {}
37-
for i = startI + 1, endI + 1 do
39+
for i = startI + 1, endI do
3840
table.insert(out, list[i])
3941
end
4042
return out

0 commit comments

Comments
 (0)