roblox-ts
Version:
<div align="center"><img width=25% src="https://i.imgur.com/yCjHmng.png"></div> <h1 align="center"><a href="https://roblox-ts.github.io/">roblox-ts</a></h1> <div align="center">A TypeScript-to-Lua Compiler for Roblox</div> <br> <div align="center"> <a hr
125 lines • 4.98 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts = __importStar(require("ts-morph"));
const _1 = require(".");
const CompilerError_1 = require("../errors/CompilerError");
const typeUtilities_1 = require("../typeUtilities");
function compileStatement(state, node) {
if (typeUtilities_1.isTypeStatement(node)) {
return "";
}
else if (ts.TypeGuards.isBlock(node)) {
return _1.compileBlock(state, node);
}
else if (ts.TypeGuards.isImportDeclaration(node)) {
return _1.compileImportDeclaration(state, node);
}
else if (ts.TypeGuards.isImportEqualsDeclaration(node)) {
return _1.compileImportEqualsDeclaration(state, node);
}
else if (ts.TypeGuards.isExportDeclaration(node)) {
return _1.compileExportDeclaration(state, node);
}
else if (ts.TypeGuards.isFunctionDeclaration(node)) {
return _1.compileFunctionDeclaration(state, node);
}
else if (ts.TypeGuards.isClassDeclaration(node)) {
return _1.compileClassDeclaration(state, node);
}
else if (ts.TypeGuards.isNamespaceDeclaration(node)) {
return _1.compileNamespaceDeclaration(state, node);
}
else if (ts.TypeGuards.isDoStatement(node)) {
return _1.compileDoStatement(state, node);
}
else if (ts.TypeGuards.isIfStatement(node)) {
return _1.compileIfStatement(state, node);
}
else if (ts.TypeGuards.isBreakStatement(node)) {
return _1.compileBreakStatement(state, node);
}
else if (ts.TypeGuards.isExpressionStatement(node)) {
return _1.compileExpressionStatement(state, node);
}
else if (ts.TypeGuards.isContinueStatement(node)) {
return _1.compileContinueStatement(state, node);
}
else if (ts.TypeGuards.isForInStatement(node)) {
throw new CompilerError_1.CompilerError("For..in loops are disallowed!", node, CompilerError_1.CompilerErrorType.ForInLoop);
}
else if (ts.TypeGuards.isForOfStatement(node)) {
return _1.compileForOfStatement(state, node);
}
else if (ts.TypeGuards.isForStatement(node)) {
return _1.compileForStatement(state, node);
}
else if (ts.TypeGuards.isReturnStatement(node)) {
return _1.compileReturnStatement(state, node);
}
else if (ts.TypeGuards.isThrowStatement(node)) {
return _1.compileThrowStatement(state, node);
}
else if (ts.TypeGuards.isVariableStatement(node)) {
return _1.compileVariableStatement(state, node);
}
else if (ts.TypeGuards.isWhileStatement(node)) {
return _1.compileWhileStatement(state, node);
}
else if (ts.TypeGuards.isEnumDeclaration(node)) {
return _1.compileEnumDeclaration(state, node);
}
else if (ts.TypeGuards.isExportAssignment(node)) {
return _1.compileExportAssignment(state, node);
}
else if (ts.TypeGuards.isSwitchStatement(node)) {
return _1.compileSwitchStatement(state, node);
}
else if (ts.TypeGuards.isTryStatement(node)) {
return _1.compileTryStatement(state, node);
}
else if (ts.TypeGuards.isLabeledStatement(node)) {
throw new CompilerError_1.CompilerError("Labeled statements are not supported!", node, CompilerError_1.CompilerErrorType.NoLabeledStatement);
}
/* istanbul ignore next */
if (ts.TypeGuards.isEmptyStatement(node) ||
ts.TypeGuards.isTypeAliasDeclaration(node) ||
ts.TypeGuards.isInterfaceDeclaration(node)) {
return "";
}
/* istanbul ignore next */
throw new CompilerError_1.CompilerError(`Unexpected statement ( ${node.getKindName()} ) in compiledStatement`, node, CompilerError_1.CompilerErrorType.BadStatement, true);
}
exports.compileStatement = compileStatement;
function compileStatementedNode(state, node) {
state.pushIdStack();
state.exportStack.push(new Set());
let result = "";
const shouldMakeHoistStack = !ts.TypeGuards.isCaseClause(node);
if (shouldMakeHoistStack) {
state.hoistStack.push(new Set());
}
for (const child of node.getStatements()) {
result += compileStatement(state, child);
if (ts.TypeGuards.isReturnStatement(child) || ts.TypeGuards.isBreakStatement(child)) {
break;
}
}
if (shouldMakeHoistStack) {
result = state.popHoistStack(result);
}
const scopeExports = state.exportStack.pop();
if (scopeExports && scopeExports.size > 0) {
scopeExports.forEach(scopeExport => (result += state.indent + scopeExport));
}
state.popIdStack();
return result;
}
exports.compileStatementedNode = compileStatementedNode;
//# sourceMappingURL=statement.js.map