typescript-to-lua
Advanced tools
Comparing version 0.10.0 to 0.11.0
import { LuaTranspiler } from "../Transpiler"; | ||
import * as ts from "typescript"; | ||
export declare class LuaTranspiler51 extends LuaTranspiler { | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node: ts.Expression): string; | ||
} |
@@ -5,8 +5,4 @@ "use strict"; | ||
class LuaTranspiler51 extends Transpiler_1.LuaTranspiler { | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node) { | ||
return `unpack(${this.transpileExpression(node)})`; | ||
} | ||
} | ||
exports.LuaTranspiler51 = LuaTranspiler51; | ||
//# sourceMappingURL=Transpiler.51.js.map |
@@ -13,2 +13,4 @@ import { LuaTranspiler51 } from "./Transpiler.51"; | ||
/** @override */ | ||
transpileSwitch(node: ts.SwitchStatement): string; | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node: ts.Expression): string; | ||
@@ -15,0 +17,0 @@ /** @override */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Errors_1 = require("../Errors"); | ||
const TSHelper_1 = require("../TSHelper"); | ||
const Transpiler_51_1 = require("./Transpiler.51"); | ||
@@ -52,2 +53,60 @@ const ts = require("typescript"); | ||
/** @override */ | ||
transpileSwitch(node) { | ||
const expression = this.transpileExpression(node.expression, true); | ||
const clauses = node.caseBlock.clauses; | ||
let result = this.indent + "-------Switch statement start-------\n"; | ||
const switchVarName = "____switch" + this.genVarCounter; | ||
this.genVarCounter++; | ||
result += this.indent + `local ${switchVarName} = ${expression}\n`; | ||
let hasDefaultClause = false; | ||
// If statement to go to right entry label | ||
clauses.forEach((clause, index) => { | ||
if (ts.isCaseClause(clause)) { | ||
result += this.indent + | ||
`if ${this.transpileExpression(clause.expression, true)} == ${switchVarName} then\n`; | ||
this.pushIndent(); | ||
result += this.indent + `goto ${switchVarName}_case_${index}\n`; | ||
this.popIndent(); | ||
result += this.indent + "end\n"; | ||
} | ||
else if (ts.isDefaultClause(clause)) { | ||
hasDefaultClause = true; | ||
} | ||
}); | ||
result += "\n"; | ||
// If no case condition is matched jump to end or default immediately | ||
if (hasDefaultClause) { | ||
result += this.indent + `goto ${switchVarName}_default\n`; | ||
} | ||
else { | ||
result += this.indent + `goto ${switchVarName}_end\n`; | ||
} | ||
result += "\n"; | ||
const transpileClauseBody = (clause) => { | ||
this.transpilingSwitch++; | ||
result += this.indent + "do\n"; | ||
this.pushIndent(); | ||
result += this.transpileBlock(ts.createBlock(clause.statements)); | ||
this.popIndent(); | ||
result += this.indent + "end\n"; | ||
this.transpilingSwitch--; | ||
}; | ||
clauses.forEach((clause, index) => { | ||
if (ts.isCaseClause(clause)) { | ||
result += this.indent + `::${switchVarName}_case_${index}::\n`; | ||
transpileClauseBody(clause); | ||
if (TSHelper_1.TSHelper.containsStatement(clause.statements, ts.SyntaxKind.BreakStatement)) { | ||
result += this.indent + `goto ${switchVarName}_end\n`; | ||
} | ||
} | ||
else if (ts.isDefaultClause(clause)) { | ||
result += this.indent + `::${switchVarName}_default::\n`; | ||
transpileClauseBody(clause); | ||
} | ||
}); | ||
result += this.indent + `::${switchVarName}_end::\n`; | ||
result += this.indent + "-------Switch statement end-------\n"; | ||
return result; | ||
} | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node) { | ||
@@ -54,0 +113,0 @@ return `table.unpack(${this.transpileExpression(node)})`; |
@@ -8,2 +8,4 @@ import { LuaTranspiler52 } from "./Transpiler.52"; | ||
transpileBitOperation(node: ts.BinaryExpression, lhs: string, rhs: string): string; | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node: ts.Expression): string; | ||
} |
@@ -35,4 +35,8 @@ "use strict"; | ||
} | ||
/** @override */ | ||
transpileDestructingAssignmentValue(node) { | ||
return `unpack(${this.transpileExpression(node)})`; | ||
} | ||
} | ||
exports.LuaTranspilerJIT = LuaTranspilerJIT; | ||
//# sourceMappingURL=Transpiler.JIT.js.map |
@@ -69,2 +69,6 @@ import * as ts from "typescript"; | ||
pathToLuaRequirePath(filePath: string): string; | ||
computeEnumMembers(node: ts.EnumDeclaration): Array<{ | ||
name: string; | ||
value: string | number; | ||
}>; | ||
transpileSourceFile(): string; | ||
@@ -94,2 +98,3 @@ transpileBlock(block: ts.Block): string; | ||
transpileBinaryExpression(node: ts.BinaryExpression, brackets?: boolean): string; | ||
transpileAssignment(node: ts.BinaryExpression, lhs: string, rhs: string): string; | ||
transpileUnaryBitOperation(node: ts.PrefixUnaryExpression, operand: string): string; | ||
@@ -99,3 +104,4 @@ transpileBitOperation(node: ts.BinaryExpression, lhs: string, rhs: string): string; | ||
transpileConditionalExpression(node: ts.ConditionalExpression, brackets?: boolean): string; | ||
transpileAssignmentExpression(lhs: ts.Expression, replacementExpression: ts.BinaryExpression, isStatement: boolean, returnValueBefore: boolean): string; | ||
transpileBinaryAssignmentExpression(assignee: ts.Expression, lhs: ts.Expression, operator: ts.BinaryOperator, rhs: ts.Expression, pos: number): string; | ||
transpileAssignmentExpression(lhs: ts.Expression, operator: ts.BinaryOperator, rhs: ts.Expression, isStatement: boolean, returnValueBefore: boolean): string; | ||
transpilePostfixUnaryExpression(node: ts.PostfixUnaryExpression): string; | ||
@@ -138,3 +144,3 @@ transpilePrefixUnaryExpression(node: ts.PrefixUnaryExpression): string; | ||
transpileObjectLiteral(node: ts.ObjectLiteralExpression): string; | ||
transpileFunctionExpression(node: ts.ArrowFunction): string; | ||
transpileFunctionExpression(node: ts.FunctionLikeDeclaration): string; | ||
transpileParameterDefaultValues(params: ts.ParameterDeclaration[]): string; | ||
@@ -141,0 +147,0 @@ checkForLuaLibType(type: ts.Type): void; |
@@ -22,2 +22,4 @@ import * as ts from "typescript"; | ||
static isInGlobalScope(node: ts.FunctionDeclaration): boolean; | ||
static isExpressionWithEvaluationEffect(node: ts.Expression): boolean; | ||
static isAccessExpressionWithEvaluationEffects(node: ts.Expression, checker: ts.TypeChecker): [boolean, ts.Expression, ts.Expression]; | ||
} |
@@ -187,4 +187,31 @@ "use strict"; | ||
} | ||
// Returns true for expressions that may have effects when evaluated | ||
static isExpressionWithEvaluationEffect(node) { | ||
return !(ts.isLiteralExpression(node) || ts.isIdentifier(node)); | ||
} | ||
// If expression is property/element access with possible effects from being evaluated, returns true along with the | ||
// separated object and index expressions. | ||
static isAccessExpressionWithEvaluationEffects(node, checker) { | ||
if (ts.isElementAccessExpression(node) | ||
&& (this.isExpressionWithEvaluationEffect(node.expression) | ||
|| this.isExpressionWithEvaluationEffect(node.argumentExpression))) { | ||
const type = checker.getTypeAtLocation(node.expression); | ||
if (this.isArrayType(type, checker)) { | ||
// Offset arrays by one | ||
const oneLit = ts.createNumericLiteral("1"); | ||
const exp = ts.createParen(node.argumentExpression); | ||
const addExp = ts.createBinary(exp, ts.SyntaxKind.PlusToken, oneLit); | ||
return [true, node.expression, addExp]; | ||
} | ||
else { | ||
return [true, node.expression, node.argumentExpression]; | ||
} | ||
} | ||
else if (ts.isPropertyAccessExpression(node) && this.isExpressionWithEvaluationEffect(node.expression)) { | ||
return [true, node.expression, ts.createStringLiteral(node.name.text)]; | ||
} | ||
return [false, null, null]; | ||
} | ||
} | ||
exports.TSHelper = TSHelper; | ||
//# sourceMappingURL=TSHelper.js.map |
{ | ||
"name": "typescript-to-lua", | ||
"license": "MIT", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"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 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
168999
2902