tina4-nodejs 3.10.31 → 3.10.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1329,10 +1329,24 @@ export class Frond {
1329
1329
  childBlocks: Record<string, string>,
1330
1330
  ): string {
1331
1331
  const pattern = /\{%[-\s]*block\s+(\w+)\s*[-]?%\}([\s\S]*?)\{%[-\s]*endblock\s*[-]?%\}/g;
1332
+ const engine = this;
1333
+
1334
+ const result = parentSource.replace(pattern, (_match, name: string, parentContent: string) => {
1335
+ const blockSource = childBlocks[name] ?? parentContent;
1336
+
1337
+ // Make parent() and super() available inside child blocks
1338
+ let renderedParent: SafeString | null = null;
1339
+ const getParent = (): SafeString => {
1340
+ if (renderedParent === null) {
1341
+ renderedParent = new SafeString(
1342
+ engine.renderTokens(tokenize(parentContent), context),
1343
+ );
1344
+ }
1345
+ return renderedParent;
1346
+ };
1332
1347
 
1333
- const result = parentSource.replace(pattern, (_match, name: string, defaultContent: string) => {
1334
- const blockSource = childBlocks[name] ?? defaultContent;
1335
- return this.renderTokens(tokenize(blockSource), context);
1348
+ const blockCtx = { ...context, parent: getParent, super: getParent };
1349
+ return this.renderTokens(tokenize(blockSource), blockCtx);
1336
1350
  });
1337
1351
 
1338
1352
  return this.renderTokens(tokenize(result), context);