more tweaking and testing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-02-10 16:51:47 +03:00
parent 9c0ffbb88c
commit 7fe24c06fc

View File

@ -587,9 +587,16 @@ module.BaseParser = {
// <item> ::= // <item> ::=
// <string> // <string>
// | { data: <ast> } // | { data: <ast> }
// | <func>
//
// <func>(state)
// -> <ast>
//
//
// NOTE: <func>(..) is called in the context of page...
// //
// XXX should this also resolve e.data??? // XXX should this also resolve e.data???
/* XXX EXPERIMENTAL... //* XXX EXPERIMENTAL...
resolve: function(page, ast, state={}){ resolve: function(page, ast, state={}){
var that = this var that = this
ast = ast ast = ast
@ -598,6 +605,7 @@ module.BaseParser = {
this.expand(page, ast, state) this.expand(page, ast, state)
: ast : ast
// NOTE: this expects .flat() on the containing array...
var handleItem = function(e){ var handleItem = function(e){
// expand delayed sections... // expand delayed sections...
e = typeof(e) == 'function' ? e = typeof(e) == 'function' ?
@ -618,24 +626,12 @@ module.BaseParser = {
} else { } else {
return [e] } } return [e] } }
// XXX do we need this??? return ast instanceof Array ?
var issync = ast instanceof Array
&& ast.reduce(function(e, res){
return res === false ?
res
: e instanceof Promise }, true)
// NOTE: we need to await for ast here as we need stage 2 of
// parsing to happen AFTER everything else completes...
// XXX
return issync ?
Promise.all(ast)
.then(function(ast){
return ast.map(handleItem)
.flat() })
: ast instanceof Array ?
ast.map(handleItem) ast.map(handleItem)
.flat() .flat()
// NOTE: we need to await for ast here as we need stage 2 of
// parsing to happen AFTER everything else completes...
// XXX
: ast.then(function(ast){ : ast.then(function(ast){
return ast.map(handleItem) return ast.map(handleItem)
.flat() }) .flat() })