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
42 lines • 1.81 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(".");
const CompilerError_1 = require("../errors/CompilerError");
const utility_1 = require("../utility");
function compileYieldExpression(state, node) {
const exp = utility_1.skipNodesDownwards(node.getExpression());
if (node.isGenerator()) {
if (!ts.TypeGuards.isExpressionStatement(utility_1.skipNodesUpwards(node.getParent()))) {
throw new CompilerError_1.CompilerError("Yield expressions must be expression statements!", node, CompilerError_1.CompilerErrorType.YieldNotInExpressionStatement);
}
state.pushIdStack();
const id = state.getNewId();
let result = `for ${id} in ${_1.compileExpression(state, exp)}.next do\n`;
state.pushIndent();
result += state.indent + `if ${id}.done then break end;\n`;
result += state.indent + `coroutine.yield(${id});\n`;
state.popIndent();
result += state.indent + `end`;
state.popIdStack();
return result;
}
else {
let result = `coroutine.yield({\n`;
state.pushIndent();
result += state.indent + `value = ${exp ? _1.compileExpression(state, exp) : "nil"};\n`;
result += state.indent + `done = false;\n`;
state.popIndent();
result += state.indent + `})`;
return result;
}
}
exports.compileYieldExpression = compileYieldExpression;
//# sourceMappingURL=yield.js.map