typescript-to-lua
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -27,3 +27,3 @@ "use strict"; | ||
addHeader: { | ||
alias: "ah", | ||
alias: ["ah", "header"], | ||
"default": true, | ||
@@ -145,3 +145,3 @@ describe: "Specify if a header will be added to compiled files.", | ||
if (!commandLine.options.project) { | ||
return; | ||
throw new CLIError("error no base path provided, could not find config."); | ||
} | ||
@@ -172,2 +172,3 @@ var configPath; | ||
} | ||
exports.findConfigFile = findConfigFile; | ||
//# sourceMappingURL=CommandLineParser.js.map |
@@ -41,5 +41,16 @@ #!/usr/bin/env node | ||
} | ||
// change extension | ||
var fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua"; | ||
outPath = path.join(path.dirname(outPath), fileNameLua); | ||
// change extension or rename to outFile | ||
if (options.outFile) { | ||
if (path.isAbsolute(options.outFile)) { | ||
outPath = options.outFile; | ||
} | ||
else { | ||
// append to workingDir or outDir | ||
outPath = path.resolve(options.outDir, options.outFile); | ||
} | ||
} | ||
else { | ||
var fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua"; | ||
outPath = path.join(path.dirname(outPath), fileNameLua); | ||
} | ||
// Write output | ||
@@ -46,0 +57,0 @@ ts.sys.writeFile(outPath, lua); |
@@ -14,3 +14,2 @@ "use strict"; | ||
var ts = require("typescript"); | ||
var ForHelper_1 = require("./ForHelper"); | ||
var TSHelper_1 = require("./TSHelper"); | ||
@@ -326,16 +325,16 @@ var path = require("path"); | ||
LuaTranspiler.prototype.transpileFor = function (node) { | ||
// Get iterator variable | ||
var variable = node.initializer.declarations[0]; | ||
var identifier = variable.name; | ||
// Populate three components of lua numeric for loop: | ||
var start = this.transpileExpression(variable.initializer); | ||
var end = ForHelper_1.ForHelper.GetForEnd(node.condition, this); | ||
var step = ForHelper_1.ForHelper.GetForStep(node.incrementor, this); | ||
// Add header | ||
var result = this.indent + ("for " + identifier.escapedText + "=" + start + "," + end + "," + step + " do\n"); | ||
var result = ""; | ||
for (var _i = 0, _a = node.initializer.declarations; _i < _a.length; _i++) { | ||
var variableDeclaration = _a[_i]; | ||
result += this.transpileVariableDeclaration(variableDeclaration); | ||
} | ||
result += this.indent + ("while(" + this.transpileExpression(node.condition) + ") do\n"); | ||
// Add body | ||
this.pushIndent(); | ||
result += this.transpileStatement(node.statement); | ||
result += this.indent + this.transpileExpression(node.incrementor) + "\n"; | ||
this.popIndent(); | ||
return result + this.indent + "end\n"; | ||
result += this.indent + "end\n"; | ||
return result; | ||
}; | ||
@@ -349,3 +348,3 @@ LuaTranspiler.prototype.transpileForOf = function (node) { | ||
// Use ipairs for array types, pairs otherwise | ||
var isArray = TSHelper_1.TSHelper.isArrayType(this.checker.getTypeAtLocation(node.expression)); | ||
var isArray = TSHelper_1.TSHelper.isArrayType(this.checker.getTypeAtLocation(node.expression), this.checker); | ||
var pairs = isArray ? "ipairs" : "pairs"; | ||
@@ -366,3 +365,3 @@ // Make header | ||
var expression = this.transpileExpression(node.expression); | ||
if (TSHelper_1.TSHelper.isArrayType(this.checker.getTypeAtLocation(node.expression))) { | ||
if (TSHelper_1.TSHelper.isArrayType(this.checker.getTypeAtLocation(node.expression), this.checker)) { | ||
throw new TranspileError("Iterating over arrays with 'for in' is not allowed.", node); | ||
@@ -782,3 +781,3 @@ } | ||
} | ||
if (TSHelper_1.TSHelper.isArrayType(expType)) { | ||
if (TSHelper_1.TSHelper.isArrayType(expType, this.checker)) { | ||
return this.transpileArrayCallExpression(node); | ||
@@ -918,3 +917,3 @@ } | ||
case ts.TypeFlags.Object: | ||
if (TSHelper_1.TSHelper.isArrayType(type)) { | ||
if (TSHelper_1.TSHelper.isArrayType(type, this.checker)) { | ||
return this.transpileArrayProperty(node); | ||
@@ -987,3 +986,3 @@ } | ||
var type = this.checker.getTypeAtLocation(node.expression); | ||
if (TSHelper_1.TSHelper.isArrayType(type) || TSHelper_1.TSHelper.isTupleType(type)) { | ||
if (TSHelper_1.TSHelper.isArrayType(type, this.checker) || TSHelper_1.TSHelper.isTupleType(type, this.checker)) { | ||
return element + "[" + index + "+1]"; | ||
@@ -1031,6 +1030,6 @@ } | ||
&& TSHelper_1.TSHelper.isTupleReturnFunction(this.checker.getTypeAtLocation(node.initializer.expression), this.checker)) { | ||
return "local " + vars + "=" + value; | ||
return "local " + vars + "=" + value + "\n"; | ||
} | ||
else { | ||
return "local " + vars + "=unpack(" + value + ")"; | ||
return "local " + vars + "=unpack(" + value + ")\n"; | ||
} | ||
@@ -1037,0 +1036,0 @@ } |
@@ -58,10 +58,9 @@ "use strict"; | ||
}; | ||
TSHelper.isArrayType = function (type) { | ||
return (type.flags & ts.TypeFlags.Object) !== 0 | ||
&& type.symbol | ||
&& type.symbol.escapedName === "Array"; | ||
TSHelper.isArrayType = function (type, checker) { | ||
var typeNode = checker.typeToTypeNode(type); | ||
return typeNode && typeNode.kind === ts.SyntaxKind.ArrayType; | ||
}; | ||
TSHelper.isTupleType = function (type) { | ||
return (type.flags & ts.TypeFlags.Object) !== 0 | ||
&& type.typeArguments !== undefined; | ||
TSHelper.isTupleType = function (type, checker) { | ||
var typeNode = checker.typeToTypeNode(type); | ||
return typeNode && typeNode.kind === ts.SyntaxKind.TupleType; | ||
}; | ||
@@ -68,0 +67,0 @@ TSHelper.isCompileMembersOnlyEnum = function (type, checker) { |
{ | ||
"name": "typescript-to-lua", | ||
"license": "MIT", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": "https://github.com/Perryvw/TypescriptToLua", | ||
@@ -6,0 +6,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83075
8
1623