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
28 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
const utility_1 = require("../utility");
function compileWhileStatement(state, node) {
const exp = utility_1.skipNodesDownwards(node.getExpression());
state.pushIdStack();
state.enterPrecedingStatementContext();
const expStr = _1.compileExpression(state, exp);
let result = "";
const context = state.exitPrecedingStatementContext();
const contextHasStatements = context.length > 0;
// Did you know `while true do` loops are optimized by the Lua interpreter?
// It skips checking whether true is true (it's true!)
result += state.indent + `while ${contextHasStatements ? "true" : expStr} do\n`;
state.pushIndent();
if (contextHasStatements) {
result += utility_1.joinIndentedLines(context, 1);
result += state.indent + `if not (${expStr}) then break; end;\n`;
}
result += _1.compileLoopBody(state, node.getStatement());
state.popIndent();
result += state.indent + `end;\n`;
state.popIdStack();
return result;
}
exports.compileWhileStatement = compileWhileStatement;
//# sourceMappingURL=while.js.map