Socket
Socket
Sign inDemoInstall

typescript-to-lua

Package Overview
Dependencies
Maintainers
2
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-to-lua - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

111

dist/Transpiler.js

@@ -85,3 +85,3 @@ "use strict";

}
if (this.namespace.length !== 0) {
if (this.namespace.length !== 0 && !ts.isModuleDeclaration(node)) {
result += this.indent + (this.definitionName(name) + " = " + name + "\n");

@@ -154,3 +154,7 @@ }

return this.transpileBreak();
case ts.SyntaxKind.ContinueKeyword:
case ts.SyntaxKind.TryStatement:
return this.transpileTry(node);
case ts.SyntaxKind.ThrowStatement:
return this.transpileThrow(node);
case ts.SyntaxKind.ContinueStatement:
// Disallow continue

@@ -393,2 +397,31 @@ throw new TranspileError("Continue is not supported in Lua", node);

};
LuaTranspiler.prototype.transpileTry = function (node) {
var tryFunc = "function()\n";
this.pushIndent();
tryFunc += this.transpileBlock(node.tryBlock);
this.popIndent();
tryFunc += "end";
var catchFunc = "function(e)\nend";
if (node.catchClause) {
var variableName = node.catchClause.variableDeclaration.name.escapedText;
catchFunc = this.indent + ("function(" + variableName + ")\n");
this.pushIndent();
catchFunc += this.transpileBlock(node.catchClause.block);
this.popIndent();
catchFunc += "end";
}
var result = this.indent + ("xpcall(" + tryFunc + ",\n" + catchFunc + ")\n");
if (node.finallyBlock) {
result += this.transpileBlock(node.finallyBlock);
}
return result;
};
LuaTranspiler.prototype.transpileThrow = function (node) {
if (ts.isStringLiteral(node.expression)) {
return "error(\"" + node.expression.text + "\")";
}
else {
throw new TranspileError("Unsupported throw expression, only string literals are supported", node.expression);
}
};
LuaTranspiler.prototype.transpileReturn = function (node) {

@@ -508,14 +541,29 @@ if (node.expression) {

switch (node.operatorToken.kind) {
case ts.SyntaxKind.AmpersandToken:
result = lhs + "&" + rhs;
break;
case ts.SyntaxKind.AmpersandEqualsToken:
result = lhs + "=" + lhs + "&" + rhs;
break;
case ts.SyntaxKind.BarToken:
result = lhs + "|" + rhs;
break;
case ts.SyntaxKind.BarEqualsToken:
result = lhs + "=" + lhs + "|" + rhs;
break;
case ts.SyntaxKind.LessThanLessThanToken:
result = lhs + "<<" + rhs;
break;
case ts.SyntaxKind.LessThanLessThanEqualsToken:
result = lhs + "=" + lhs + "<<" + rhs;
break;
case ts.SyntaxKind.GreaterThanGreaterThanToken:
result = lhs + ">>" + rhs;
break;
case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
result = lhs + "=" + lhs + ">>" + rhs;
break;
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
result = lhs + ">>>" + rhs;
break;
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:

@@ -551,8 +599,45 @@ result = lhs + "=" + lhs + ">>>" + rhs;

var typeRight = this.checker.getTypeAtLocation(node.right);
if (typeLeft.flags & ts.TypeFlags.String || ts.isStringLiteral(node.left))
return lhs + ".." + rhs;
if (typeRight.flags & ts.TypeFlags.String || ts.isStringLiteral(node.right))
return lhs + ".." + rhs;
if ((typeLeft.flags & ts.TypeFlags.String) || ts.isStringLiteral(node.left)
|| (typeRight.flags & ts.TypeFlags.String) || ts.isStringLiteral(node.right)) {
return lhs + " .. " + rhs;
}
result = lhs + "+" + rhs;
break;
case ts.SyntaxKind.MinusToken:
result = lhs + "-" + rhs;
break;
case ts.SyntaxKind.AsteriskToken:
result = lhs + "*" + rhs;
break;
case ts.SyntaxKind.SlashToken:
result = lhs + "/" + rhs;
break;
case ts.SyntaxKind.PercentToken:
result = lhs + "%" + rhs;
break;
case ts.SyntaxKind.GreaterThanToken:
result = lhs + ">" + rhs;
break;
case ts.SyntaxKind.GreaterThanEqualsToken:
result = lhs + ">=" + rhs;
break;
case ts.SyntaxKind.LessThanToken:
result = lhs + "<" + rhs;
break;
case ts.SyntaxKind.LessThanEqualsToken:
result = lhs + "<=" + rhs;
break;
case ts.SyntaxKind.EqualsToken:
result = lhs + "=" + rhs;
break;
case ts.SyntaxKind.EqualsEqualsToken:
case ts.SyntaxKind.EqualsEqualsEqualsToken:
result = lhs + "==" + rhs;
break;
case ts.SyntaxKind.ExclamationEqualsToken:
case ts.SyntaxKind.ExclamationEqualsEqualsToken:
result = lhs + "~=" + rhs;
break;
default:
result = lhs + this.transpileOperator(node.operatorToken) + rhs;
throw new TranspileError("Unsupported binary operator kind: " + ts.tokenToString(node.operatorToken.kind), node);
}

@@ -588,14 +673,2 @@ }

};
// Replace some missmatching operators
LuaTranspiler.prototype.transpileOperator = function (operator) {
switch (operator.kind) {
case ts.SyntaxKind.EqualsEqualsEqualsToken:
return "==";
case ts.SyntaxKind.ExclamationEqualsToken:
case ts.SyntaxKind.ExclamationEqualsEqualsToken:
return "~=";
default:
return ts.tokenToString(operator.kind);
}
};
LuaTranspiler.prototype.transpilePostfixUnaryExpression = function (node) {

@@ -602,0 +675,0 @@ var operand = this.transpileExpression(node.operand, true);

3

dist/TSHelper.js

@@ -19,5 +19,2 @@ "use strict";

};
TSHelper.getFirstChildOfType = function (node, typeFilter) {
return this.getChildrenOfType(node, typeFilter)[0];
};
// Reverse lookup of enum key by value

@@ -24,0 +21,0 @@ TSHelper.enumName = function (needle, haystack) {

{
"name": "typescript-to-lua",
"license": "MIT",
"version": "0.0.13",
"version": "0.0.14",
"repository": "https://github.com/Perryvw/TypescriptToLua",

@@ -6,0 +6,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc