minor fix + cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-06-29 17:29:34 +03:00
parent 28648fff06
commit 157761de03

View File

@ -123,7 +123,7 @@ object.Constructor('Walk', {
handler instanceof types.Generator ? handler instanceof types.Generator ?
handler handler
: Object.assign( : Object.assign(
function*(){ yield handler(...arguments) }, function*(){ yield handler.call(this, ...arguments) },
{toString: function(){ return handler.toString() }}) }, {toString: function(){ return handler.toString() }}) },
__call__: function*(_, obj, path=[], type='root', seen=new Map()){ __call__: function*(_, obj, path=[], type='root', seen=new Map()){
var that = this var that = this
@ -204,16 +204,13 @@ module.OBJECT_LISTERS = {
if(obj === null){ if(obj === null){
throw module.STOP } }, throw module.STOP } },
/* XXX not sure if this should be here... // XXX this is diff-specific...
// XXX TEXT...
// XXX also this is diff-specific...
text: function(obj){ text: function(obj){
return typeof(obj) == 'string' return typeof(obj) == 'string'
&& obj.includes('\n') && obj.includes('\n')
&& obj.split(/\n/g).entries() && obj.split(/\n/g).entries()
.map(function([k, v]){ .map(function([k, v]){
return [[module.CONTENT, k], v] }) }, return [[module.CONTENT, k], v] }) },
//*/
set: function(obj){ set: function(obj){
return obj instanceof Set return obj instanceof Set
@ -263,18 +260,8 @@ module.OBJECT_LISTERS = {
var objectWalker = var objectWalker =
module.objectWalker = module.objectWalker =
Walk({ Walk({
//noText: true,
handler: function(obj, path, next, type){ handler: function(obj, path, next, type){
// text...
// XXX TEXT...
// XXX should this be here or in OBJECT_LISTERS???
// XXX also this is diff-specific...
if(typeof(obj) == 'string' && obj.includes('\n')){
next.push(['text',
obj.split(/\n/g).entries()
.map(function([k, v]){
return [[module.CONTENT, k], v] }) ])
return [path, {type: 'text'}] }
// other types...
return type == 'LINK' ? return type == 'LINK' ?
[path, 'LINK', next] [path, 'LINK', next]
: [ : [
@ -283,9 +270,11 @@ Walk({
obj obj
: typeof(obj) == 'object' ? : typeof(obj) == 'object' ?
{type: obj.constructor.name} {type: obj.constructor.name}
// XXX TEXT... // text...
//: typeof(obj) == 'string' && obj.includes('\n') ? : !this.noText
// {type: 'text'} && typeof(obj) == 'string'
&& obj.includes('\n') ?
{type: 'text'}
: obj, : obj,
] }, ] },
listers: module.OBJECT_LISTERS, listers: module.OBJECT_LISTERS,