typescript-to-lua
Advanced tools
Comparing version 0.13.0 to 0.13.1
@@ -16,2 +16,3 @@ import * as ts from "typescript"; | ||
static InvalidPropertyCall: (node: ts.Node) => TranspileError; | ||
static InvalidElementCall: (node: ts.Node) => TranspileError; | ||
static InvalidThrowExpression: (node: ts.Node) => TranspileError; | ||
@@ -18,0 +19,0 @@ static KeywordIdentifier: (node: ts.Identifier) => TranspileError; |
@@ -24,2 +24,3 @@ "use strict"; | ||
TSTLErrors.InvalidPropertyCall = (node) => new TranspileError(`Tried to transpile a non-property call as property call.`, node); | ||
TSTLErrors.InvalidElementCall = (node) => new TranspileError(`Tried to transpile a non-element call as an element call.`, node); | ||
TSTLErrors.InvalidThrowExpression = (node) => new TranspileError(`Invalid throw expression, only strings can be thrown.`, node); | ||
@@ -26,0 +27,0 @@ TSTLErrors.KeywordIdentifier = (node) => new TranspileError(`Cannot use Lua keyword ${node.escapedText} as identifier.`, node); |
@@ -9,2 +9,4 @@ import { LuaTranspiler51 } from "./Transpiler.51"; | ||
/** @override */ | ||
transpileBreak(node: ts.BreakStatement): string; | ||
/** @override */ | ||
transpileUnaryBitOperation(node: ts.PrefixUnaryExpression, operand: string): string; | ||
@@ -11,0 +13,0 @@ /** @override */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Errors_1 = require("../Errors"); | ||
const TSHelper_1 = require("../TSHelper"); | ||
const Transpiler_1 = require("../Transpiler"); | ||
const Transpiler_51_1 = require("./Transpiler.51"); | ||
@@ -10,10 +10,5 @@ const ts = require("typescript"); | ||
transpileLoopBody(node) { | ||
this.loopStack.push(this.genVarCounter); | ||
this.genVarCounter++; | ||
let result = this.indent + "do\n"; | ||
this.pushIndent(); | ||
result += this.transpileStatement(node.statement); | ||
this.popIndent(); | ||
result += this.indent + "end\n"; | ||
result += this.indent + `::__continue${this.loopStack.pop()}::\n`; | ||
this.pushSpecialScope(Transpiler_1.ScopeType.Loop); | ||
let result = super.transpileLoopBody(node); | ||
result += this.indent + `::__continue${this.popSpecialScope().id}::\n`; | ||
return result; | ||
@@ -23,5 +18,15 @@ } | ||
transpileContinue(node) { | ||
return this.indent + `goto __continue${this.loopStack[this.loopStack.length - 1]}\n`; | ||
return this.indent + `goto __continue${this.peekSpecialScope().id}\n`; | ||
} | ||
/** @override */ | ||
transpileBreak(node) { | ||
const topScope = this.peekSpecialScope(); | ||
if (topScope.type === Transpiler_1.ScopeType.Switch) { | ||
return this.indent + `goto ____switch${topScope.id}_end\n`; | ||
} | ||
else { | ||
return super.transpileBreak(node); | ||
} | ||
} | ||
/** @override */ | ||
transpileUnaryBitOperation(node, operand) { | ||
@@ -60,3 +65,3 @@ switch (node.operator) { | ||
const switchVarName = "____switch" + this.genVarCounter; | ||
this.genVarCounter++; | ||
this.pushSpecialScope(Transpiler_1.ScopeType.Switch); | ||
result += this.indent + `local ${switchVarName} = ${expression}\n`; | ||
@@ -88,3 +93,2 @@ let hasDefaultClause = false; | ||
const transpileClauseBody = (clause) => { | ||
this.transpilingSwitch++; | ||
result += this.indent + "do\n"; | ||
@@ -95,3 +99,2 @@ this.pushIndent(); | ||
result += this.indent + "end\n"; | ||
this.transpilingSwitch--; | ||
}; | ||
@@ -102,5 +105,2 @@ clauses.forEach((clause, index) => { | ||
transpileClauseBody(clause); | ||
if (TSHelper_1.TSHelper.containsStatement(clause.statements, ts.SyntaxKind.BreakStatement)) { | ||
result += this.indent + `goto ${switchVarName}_end\n`; | ||
} | ||
} | ||
@@ -114,2 +114,3 @@ else if (ts.isDefaultClause(clause)) { | ||
result += this.indent + "-------Switch statement end-------\n"; | ||
this.popSpecialScope(); | ||
return result; | ||
@@ -116,0 +117,0 @@ } |
@@ -45,2 +45,11 @@ import * as ts from "typescript"; | ||
} | ||
export declare enum ScopeType { | ||
Function = 0, | ||
Switch = 1, | ||
Loop = 2 | ||
} | ||
interface SpecialScope { | ||
type: ScopeType; | ||
id: number; | ||
} | ||
export declare abstract class LuaTranspiler { | ||
@@ -52,3 +61,2 @@ luaKeywords: Set<string>; | ||
genVarCounter: number; | ||
transpilingSwitch: number; | ||
namespace: string[]; | ||
@@ -59,3 +67,3 @@ importCount: number; | ||
sourceFile: ts.SourceFile; | ||
loopStack: number[]; | ||
scopeStack: SpecialScope[]; | ||
classStack: string[]; | ||
@@ -71,2 +79,5 @@ exportStack: ExportInfo[][]; | ||
pushExport(nameIn: string, nodeIn: ts.Node, dummyIn?: boolean): void; | ||
peekSpecialScope(): SpecialScope; | ||
pushSpecialScope(scopeType: ScopeType): void; | ||
popSpecialScope(): SpecialScope; | ||
makeExport(name: string, node: ts.Node, dummy?: boolean): string; | ||
@@ -89,3 +100,3 @@ makeExports(): string; | ||
transpileEnum(node: ts.EnumDeclaration): string; | ||
transpileBreak(): string; | ||
transpileBreak(node: ts.BreakStatement): string; | ||
transpileContinue(node: ts.ContinueStatement): string; | ||
@@ -119,2 +130,3 @@ transpileIf(node: ts.IfStatement): string; | ||
transpilePropertyCall(node: ts.CallExpression): string; | ||
transpileElementCall(node: ts.CallExpression): string; | ||
transpileStringCallExpression(node: ts.CallExpression): string; | ||
@@ -139,2 +151,3 @@ getValidStringProperties(): { | ||
transpileArrayBindingElement(name: ts.ArrayBindingElement): string; | ||
transpileAssertionExpression(node: ts.AssertionExpression): string; | ||
transpileTypeOfExpression(node: ts.TypeOfExpression): string; | ||
@@ -141,0 +154,0 @@ transpileVariableStatement(node: ts.VariableStatement): string; |
@@ -12,3 +12,2 @@ import * as ts from "typescript"; | ||
static enumNames<T>(mask: number, haystack: any): string[]; | ||
static containsStatement(statements: ts.NodeArray<ts.Statement>, kind: ts.SyntaxKind): boolean; | ||
static getExtendedType(node: ts.ClassLikeDeclarationBase, checker: ts.TypeChecker): ts.Type | undefined; | ||
@@ -15,0 +14,0 @@ static isFileModule(sourceFile: ts.SourceFile): boolean; |
@@ -53,5 +53,2 @@ "use strict"; | ||
} | ||
static containsStatement(statements, kind) { | ||
return statements.some(statement => statement.kind === kind); | ||
} | ||
static getExtendedType(node, checker) { | ||
@@ -277,3 +274,3 @@ if (node && node.heritageClauses) { | ||
static isExpressionWithEvaluationEffect(node) { | ||
return !(ts.isLiteralExpression(node) || ts.isIdentifier(node)); | ||
return !(ts.isLiteralExpression(node) || ts.isIdentifier(node) || node.kind === ts.SyntaxKind.ThisKeyword); | ||
} | ||
@@ -280,0 +277,0 @@ // If expression is property/element access with possible effects from being evaluated, returns true along with the |
{ | ||
"name": "typescript-to-lua", | ||
"license": "MIT", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"repository": "https://github.com/Perryvw/TypescriptToLua", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
194472
3360