From b98e4ca5c0d23625e70112bfc3b0720193017745 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 5 Jul 2026 15:30:50 +0300 Subject: [PATCH] moved recursion testing up one level... Signed-off-by: Alex A. Naanou --- v3/pwiki/parser.js | 61 ++++++++++++++++++++--------------------- v3/pwiki/test/parser.js | 2 ++ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/v3/pwiki/parser.js b/v3/pwiki/parser.js index f11ad40..ec8c3e9 100644 --- a/v3/pwiki/parser.js +++ b/v3/pwiki/parser.js @@ -1313,48 +1313,47 @@ module.parser = { // content handler... handler ??= function(page, body, path, text, state){ - // check for recursion... - var include_stack = state.include_stack ??= [] + return args.isolated ? + this.resolve( + page, + text, + args.isolated == 'partial' ? + serialize.partialDeepCopy(state) + : {}) + : this.expand(page, text, state) } + + var pageHandler = + function([path, text]){ + // recursion... + // XXX for some reason this does not work for async... + // ...and works quite differently in tests and + // in console -- returns [object Object] in the + // former and hangs in the later... + var include_stack = state.include_stack ??= [] if(include_stack.includes(path)){ if(!recursive){ throw new Error('Recursive macro: '+include_stack) } return that.expand(page, recursive, state) } include_stack.push(path) - // XXX check cache??? + // XXX cache??? - var res = args.isolated ? - this.resolve( - page, - text, - Object.assign( - args.isolated == 'partial' ? - serialize.partialDeepCopy(state) - : {}, - {include_stack})) - : this.expand(page, text, state) - - // handle recursion... - return Promise.awaitOrRun( - res, - function(){ - state.include_stack.at(-1) == src - && state.include_stack.pop() - // cleanup... - if(state.include_stack.length == 0){ - delete state.include_stack - delete state.recursive } - - return res }) } - - var pageHandler = - function([path, text]){ - // handle nested promises... + // call the handler... return Promise.awaitOrRun( text, function(text){ - return handler.call(that, page, body, path, text, state) }) } + return Promise.awaitOrRun( + handler.call(that, page, body, path, text, state), + function(res){ + // recursion + state.include_stack.at(-1) == src + && state.include_stack.pop() + // cleanup... + if(state.include_stack.length == 0){ + delete state.include_stack + delete state.recursive } + return res }) }) } // get and run things... return Promise.awaitOrRun( diff --git a/v3/pwiki/test/parser.js b/v3/pwiki/test/parser.js index d098c49..08d74b9 100755 --- a/v3/pwiki/test/parser.js +++ b/v3/pwiki/test/parser.js @@ -301,6 +301,7 @@ test.Setups({ page: P, code:[ '@include(/recursive/Self recursive="recursion found")', + // XXX this hangs... '@include(/async/recursive/Self recursive="recursion found")', '<< recursion found >>', ], } }, include_recursive_b: function(assert){ @@ -308,6 +309,7 @@ test.Setups({ page: P, code:[ '@include(/recursive/SelfOther recursive="recursion found")', + // XXX this hangs... '@include(/async/recursive/SelfOther recursive="recursion found")', '<< << recursion found >> >>', ], } },