UNPKG

twing

Version:

First-class Twig engine for Node.js

32 lines (31 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeEmbedNodeSynchronously = exports.executeEmbedNode = void 0; const include_1 = require("../include"); const traceable_method_1 = require("../../helpers/traceable-method"); const executeEmbedNode = (node, executionContext) => { return (0, include_1.executeBaseIncludeNode)(node, executionContext, ({ template }) => { const { index } = node.attributes; const loadEmbeddedTemplate = (0, traceable_method_1.getTraceableMethod)(() => { const { embeddedTemplates } = template; // by design, it is guaranteed that an embed node is always executed with an index that corresponds to an existing embedded template const embeddedTemplate = embeddedTemplates.get(index); return Promise.resolve(embeddedTemplate); }, node, template.source); return loadEmbeddedTemplate(); }); }; exports.executeEmbedNode = executeEmbedNode; const executeEmbedNodeSynchronously = (node, executionContext) => { return (0, include_1.executeBaseIncludeNodeSynchronously)(node, executionContext, ({ template }) => { const { index } = node.attributes; const loadEmbeddedTemplate = (0, traceable_method_1.getSynchronousTraceableMethod)(() => { const { embeddedTemplates } = template; // by design, it is guaranteed that an embed node is always executed with an index that corresponds to an existing embedded template const embeddedTemplate = embeddedTemplates.get(index); return embeddedTemplate; }, node, template.source); return loadEmbeddedTemplate(); }); }; exports.executeEmbedNodeSynchronously = executeEmbedNodeSynchronously;