define(["require", "exports", "./flow_node_handler", ".."], function (require, exports, flow_node_handler_1, __1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class ScriptTaskHandler extends flow_node_handler_1.FlowNodeHandler {
        async executeIntern(scriptTask, processToken, context) {
            const tokenData = processToken.data || {};
            let result;
            const script = scriptTask.script;
            if (script) {
                const scriptFunction = new Function('token', 'context', script);
                result = await scriptFunction.call(this, tokenData, context);
                let finalResult = result;
                const toPojoOptions = { skipCalculation: true };
                if (result && typeof result.toPojos === 'function') {
                    finalResult = await result.toPojos(context, toPojoOptions);
                }
                else if (result && typeof result.toPojo === 'function') {
                    finalResult = await result.toPojo(context, toPojoOptions);
                }
                tokenData.current = finalResult;
                processToken.data = tokenData;
                return new __1.NextFlowNodeInfo(await this.getNextFlowNodeFor(scriptTask, context), processToken);
            }
        }
    }
    exports.ScriptTaskHandler = ScriptTaskHandler;
});

//# sourceMappingURL=script_task_handler.js.map
