From d24257d3e2f1f74f47191a23037c8e4d334f17e0 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 5 Jul 2026 21:25:05 +0300 Subject: [PATCH] cleanup and notes... Signed-off-by: Alex A. Naanou --- v3/pwiki/parser.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/v3/pwiki/parser.js b/v3/pwiki/parser.js index c8ce3da..6f32485 100644 --- a/v3/pwiki/parser.js +++ b/v3/pwiki/parser.js @@ -770,8 +770,6 @@ module.BaseParser = { : ast.iter() // merge resolved elements into the last item of elems... - // XXX can ast be a promise??? - // XXX elems can be unresolved -- need a merge strategy for them... var elems = [] for(var elem of ast){ // nesting... @@ -806,7 +804,6 @@ module.BaseParser = { // nested macro with no value set -- skip... if(that.macros[elem.name] instanceof Array){ continue } - //* XXX unresolved... ;(state.unresolved ??= []) .push(elem.resolving instanceof Promise ? elem.resolving @@ -818,6 +815,14 @@ module.BaseParser = { return elems }, + isResolved: function(ast){ + if(!(ast instanceof Array)){ + return false } + for(var e of ast){ + if(typeof(e) == 'object'){ + return false } } + return true }, + // XXX render api... // XXX how should this play with filters??? // ...should filters be client-side only?? @@ -830,12 +835,15 @@ module.BaseParser = { // XXX might be a good idea to limit recursion depth here... var merge = function(ast){ return Promise.awaitOrRun( - ...state.unresolved, + ...(state.unresolved ?? []), function(){ delete state.unresolved // re-resolve... ast = that.resolve(page, ast, state, nested_handlers) + // NOTE: this is essentially running in the same frame + // as .resolve(..) above so there should not be + // any races to delete .unresolved... return state.unresolved ? merge(ast) : (ast ?? '').join('') }) } @@ -844,14 +852,11 @@ module.BaseParser = { this.resolve(page, ast, state, nested_handlers), state[wait], function(ast){ - // NOTE: since we are waiting for state[wait], state.unresolved - // might get cleaned out by this point so we need to check - // manually... - for(var e of ast){ - if(typeof(e) == 'object'){ - state.unresolved = [] - break } } - return state.unresolved ? + // NOTE: in an async world where any promised macro can + // call .parse(..) / .parseNested(..) we can't trust + // the lack of .unresolved in state... + return (state.unresolved + || !that.isResolved(ast)) ? merge(ast) : (ast ?? '').join('') }) },