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
65 lines • 2.36 kB
JavaScript
;
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(".");
function hasContinueDescendant(node) {
for (const child of node.getChildren()) {
if (ts.TypeGuards.isContinueStatement(child)) {
return true;
}
if (!(ts.TypeGuards.isForInStatement(child) ||
ts.TypeGuards.isForOfStatement(child) ||
ts.TypeGuards.isForStatement(child) ||
ts.TypeGuards.isWhileStatement(child) ||
ts.TypeGuards.isDoStatement(child))) {
if (hasContinueDescendant(child)) {
return true;
}
}
}
return false;
}
function compileLoopBody(state, node) {
const hasContinue = hasContinueDescendant(node);
let endsWithBreakOrReturn = false;
if (ts.TypeGuards.isBlock(node)) {
const statements = node.getStatements();
const lastStatement = statements[statements.length - 1];
if (lastStatement) {
if (ts.TypeGuards.isBreakStatement(lastStatement) || ts.TypeGuards.isReturnStatement(lastStatement)) {
endsWithBreakOrReturn = true;
}
}
}
let result = "";
if (hasContinue) {
state.continueId++;
result += state.indent + `local _continue_${state.continueId} = false;\n`;
result += state.indent + `repeat\n`;
state.pushIndent();
}
result += _1.compileStatement(state, node);
if (hasContinue) {
if (!endsWithBreakOrReturn) {
result += state.indent + `_continue_${state.continueId} = true;\n`;
}
state.popIndent();
result += state.indent + `until true;\n`;
result += state.indent + `if not _continue_${state.continueId} then\n`;
state.pushIndent();
result += state.indent + `break;\n`;
state.popIndent();
result += state.indent + `end;\n`;
state.continueId--;
}
return result;
}
exports.compileLoopBody = compileLoopBody;
//# sourceMappingURL=loop.js.map