@abaplint/transpiler
Version:
36 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InlineDeclarations = void 0;
const abaplint = require("@abaplint/core");
const transpile_types_1 = require("./transpile_types");
const statements_1 = require("./statements");
class InlineDeclarations {
static buildDeclarations(node, traversal) {
const inlineDataExpressions = node.findAllExpressionsRecursive(abaplint.Expressions.InlineData);
let result = "";
for (const expression of inlineDataExpressions) {
const name = expression.findFirstExpression(abaplint.Expressions.TargetField)?.concatTokens();
if (name === undefined) {
throw new Error("InlineDeclarations: no target data field found");
}
const scope = traversal.findCurrentScopeByToken(expression.getFirstToken());
const variable = scope?.findVariable(name);
if (variable === undefined) {
throw new Error("InlineDeclarations: no variable found");
}
result += transpile_types_1.TranspileTypes.declare(variable) + "\n";
}
// todo: declare DATA and FSes according to when they appear in the code
const inlineFieldSymbols = node.findAllExpressionsRecursive(abaplint.Expressions.InlineFS);
for (const expression of inlineFieldSymbols) {
const target = expression.findFirstExpression(abaplint.Expressions.TargetFieldSymbol);
if (target === undefined) {
throw new Error("InlineDeclarations: no target fs field found");
}
result += new statements_1.FieldSymbolTranspiler().transpile(target, traversal).getCode();
}
return result;
}
}
exports.InlineDeclarations = InlineDeclarations;
//# sourceMappingURL=inline.js.map