@abaplint/transpiler
Version:
48 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AtTranspiler = void 0;
const abaplint = require("@abaplint/core");
const chunk_1 = require("../chunk");
const statements_1 = require("../statements");
const unique_identifier_1 = require("../unique_identifier");
class AtTranspiler {
transpile(node, traversal, previous, loopTarget, tabix, loopStatement) {
const ret = new chunk_1.Chunk();
const atStatement = node.findDirectStatement(abaplint.Statements.At);
const concat = atStatement?.concatTokens().toUpperCase();
const name = atStatement
?.findDirectExpression(abaplint.Expressions.FieldSub)
?.concatTokens()
?.toLowerCase();
let suffix = `.get().${name}`;
if (name === "table_line") {
suffix = "";
}
if (concat?.startsWith("AT NEW ")) {
ret.appendString(`if (${previous} === undefined || abap.compare.eq(${previous}${suffix}, ${loopTarget}${suffix}) === false) {\n`);
const body = node.findDirectStructure(abaplint.Structures.Body);
if (body) {
ret.appendChunk(traversal.traverse(body));
}
ret.appendString("}\n");
}
else if (concat?.startsWith("AT END OF ")) {
const next = unique_identifier_1.UniqueIdentifier.get();
ret.appendString(`let ${next} = undefined;\n`);
const loop = new statements_1.LoopTranspiler({ injectFrom: tabix, skipInto: true });
ret.appendChunk(loop.transpile(loopStatement, traversal));
ret.appendString(`${next} = ${loop.getTarget()};\n`);
ret.appendString(`break;\n`);
ret.appendString(`}\n`);
ret.appendString(`if (${next} === undefined || abap.compare.eq(${next}${suffix}, ${loopTarget}${suffix}) === false) {\n`);
const body = node.findDirectStructure(abaplint.Structures.Body);
if (body) {
ret.appendChunk(traversal.traverse(body));
}
ret.appendString("}\n");
}
return ret;
}
}
exports.AtTranspiler = AtTranspiler;
//# sourceMappingURL=at.js.map