MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / printIfStatement

Method printIfStatement

src/LuaPrinter.ts:461–486  ·  view source on GitHub ↗
(statement: lua.IfStatement, isElseIf = false)

Source from the content-addressed store, hash-verified

459 }
460
461 public printIfStatement(statement: lua.IfStatement, isElseIf = false): SourceNode {
462 const chunks: SourceChunk[] = [];
463
464 const prefix = isElseIf ? "elseif" : "if";
465 chunks.push(this.indent(prefix + " "), this.printExpression(statement.condition), " then\n");
466
467 this.pushIndent();
468 chunks.push(this.printBlock(statement.ifBlock));
469 this.popIndent();
470
471 if (statement.elseBlock) {
472 if (lua.isIfStatement(statement.elseBlock)) {
473 chunks.push(this.printIfStatement(statement.elseBlock, true));
474 } else {
475 chunks.push(this.indent("else\n"));
476 this.pushIndent();
477 chunks.push(this.printBlock(statement.elseBlock));
478 this.popIndent();
479 chunks.push(this.indent("end"));
480 }
481 } else {
482 chunks.push(this.indent("end"));
483 }
484
485 return this.concatNodes(...chunks);
486 }
487
488 public printWhileStatement(statement: lua.WhileStatement): SourceNode {
489 const chunks: SourceChunk[] = [];

Callers 1

Calls 6

indentMethod · 0.95
printExpressionMethod · 0.95
pushIndentMethod · 0.95
printBlockMethod · 0.95
popIndentMethod · 0.95
concatNodesMethod · 0.95

Tested by

no test coverage detected