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
62 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
const utility_1 = require("../utility");
function compileConditionalExpression(state, node) {
let id;
const currentConditionalContext = state.currentConditionalContext;
const declaration = state.declarationContext.get(node);
const condition = _1.assertNonLuaTuple(utility_1.skipNodesDownwards(node.getCondition()));
const whenTrue = utility_1.skipNodesDownwards(node.getWhenTrue());
const whenFalse = utility_1.skipNodesDownwards(node.getWhenFalse());
let conditionStr;
let isPushed = false;
if (declaration) {
conditionStr = _1.compileExpression(state, condition);
if (declaration.needsLocalizing) {
state.pushPrecedingStatements(node, state.indent + "local " + declaration.set + ";\n");
}
id = declaration.set;
state.currentConditionalContext = id;
}
else {
if (currentConditionalContext === "") {
id = state.pushPrecedingStatementToNewId(node, "");
state.currentConditionalContext = id;
isPushed = true;
}
else {
id = currentConditionalContext;
}
conditionStr = _1.compileExpression(state, condition);
}
state.pushPrecedingStatements(condition, state.indent + `if ${conditionStr} then\n`);
state.pushIndent();
state.declarationContext.set(whenTrue, { isIdentifier: declaration ? declaration.isIdentifier : true, set: id });
state.pushIdStack();
const whenTrueStr = _1.compileExpression(state, whenTrue);
if (state.declarationContext.delete(whenTrue) && id !== whenTrueStr) {
state.pushPrecedingStatements(whenTrue, state.indent + utility_1.makeSetStatement(id, whenTrueStr) + ";\n");
}
state.popIdStack();
state.popIndent();
state.pushPrecedingStatements(whenFalse, state.indent + `else\n`);
state.pushIndent();
state.pushIdStack();
state.declarationContext.set(whenFalse, { isIdentifier: declaration ? declaration.isIdentifier : true, set: id });
const whenFalseStr = _1.compileExpression(state, whenFalse);
if (state.declarationContext.delete(whenFalse) && id !== whenFalseStr) {
state.pushPrecedingStatements(whenFalse, state.indent + utility_1.makeSetStatement(id, whenFalseStr) + ";\n");
}
state.popIdStack();
state.popIndent();
state.pushPrecedingStatements(whenFalse, state.indent + `end;\n`);
if (currentConditionalContext === "") {
state.currentConditionalContext = "";
}
state.declarationContext.delete(node);
state.getCurrentPrecedingStatementContext(node).isPushed = isPushed;
return id || "";
}
exports.compileConditionalExpression = compileConditionalExpression;
//# sourceMappingURL=conditional.js.map