UNPKG

twing

Version:

First-class Twig engine for Node.js

46 lines (45 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeHashNodeSynchronously = exports.executeHashNode = void 0; const get_key_value_pairs_1 = require("../../helpers/get-key-value-pairs"); const context_1 = require("../../context"); const executeHashNode = async (node, executionContext) => { const { nodeExecutor: execute } = executionContext; const keyValuePairs = (0, get_key_value_pairs_1.getKeyValuePairs)(node); const hash = new Map(); for (const { key: keyNode, value: valueNode } of keyValuePairs) { const [key, value] = await Promise.all([ execute(keyNode, executionContext), execute(valueNode, executionContext) ]); if (valueNode.type === "spread") { for (const [valueKey, valueValue] of value) { hash.set(valueKey, valueValue); } } else { hash.set(key, value); } } return hash; }; exports.executeHashNode = executeHashNode; const executeHashNodeSynchronously = (node, executionContext) => { const { nodeExecutor: execute } = executionContext; const keyValuePairs = (0, get_key_value_pairs_1.getKeyValuePairs)(node); const hash = new Map(); for (const { key: keyNode, value: valueNode } of keyValuePairs) { const key = execute(keyNode, executionContext); const value = execute(valueNode, executionContext); if (valueNode.type === "spread") { for (const [valueKey, valueValue] of (0, context_1.getEntries)(value)) { hash.set(valueKey, valueValue); } } else { hash.set(key, value); } } return hash; }; exports.executeHashNodeSynchronously = executeHashNodeSynchronously;