How to use the @effectful/transducers.Tag.Array function in @effectful/transducers

To help you get started, we’ve selected a few @effectful/transducers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awto / effectfuljs / packages / core / src / state.js View on Github external
});
                  yield sl.tok(Tag.left, Tag.Identifier, {
                    sym,
                    lhs: true,
                    rhs: false,
                    decl: false
                  });
                  yield* init;
                  yield* sl.leave();
                  yield* sl.leave();
                }
              }
              // babel's hoist re-hack
              if (i.value.babelHoistReHack) {
                yield sl.enter(Tag.push, Tag.BlockStatement);
                yield sl.enter(Tag.body, Tag.Array);
                yield* _restoreDecls(sl.sub());
                yield* sl.leave();
                yield* sl.leave();
              }
              break;
            }
          }
        }
      }
    }
  }
}
github awto / effectfuljs / packages / core / src / state.js View on Github external
function* _restoreDecls(sw) {
    for (const i of sw) {
      yield i;
      if (i.enter) {
        if (
          ((i.value.savedDecls != null && i.value.savedDecls.size) ||
            (i.value.paramSyms && i.value.paramSyms.length)) &&
          !i.leave &&
          sl.curLev()
        ) {
          for (const j of sl.sub()) {
            yield j;
            if (j.enter && j.type === Tag.Array && j.pos === Tag.body) {
              const assigns = [];
              const decls = [];
              const { funcId } = i.value;
              if (funcId) {
                const copy = Kit.scope.newSym(funcId.orig);
                copy.num = -copy.num;
                copy.strict = true;
                funcId.strict = false;
                i.value.funcAlias = copy;
                if (
                  funcId.interpr === Bind.ctxField &&
                  funcId.declScope === i.value &&
                  // funcId.hasReads
                  ((noOpts && funcId.bound) || funcId.hasReads)
                ) {
                  assigns.push({
github awto / effectfuljs / packages / core / src / debug.js View on Github external
if (hasBind) {
              yield D.copyComment(
                i,
                D.setComment(
                  Kit.enter(i.pos, Tag.VariableDeclaration, {
                    node: {
                      kind: "var"
                      // kind:"const"
                    },
                    eff: i.value.eff
                  }),
                  "S",
                  "font-size:xx-large;color:orange"
                )
              );
              yield Kit.enter(Tag.declarations, Tag.Array);
              yield Kit.enter(Tag.push, Tag.VariableDeclarator);
              yield Kit.tok(Tag.id, Tag.Identifier, { sym: i.value.sym });
              yield Kit.enter(Tag.init, Kit.Subst);
            } else {
              yield D.copyComment(
                i,
                D.setComment(
                  Kit.enter(i.pos, Tag.ExpressionStatement, {
                    node: {},
                    eff: i.value.eff
                  }),
                  "S",
                  "font-size:xx-large;color:orange"
                )
              );
              yield Kit.enter(Tag.expression, Kit.Subst);
github awto / effectfuljs / packages / core / src / control.js View on Github external
export function* injectExplicitRet(si) {
  const s = Kit.auto(si);
  if (s.first.type === Tag.File) {
    yield* s;
    return;
  }
  let stop;
  for (const i of s) {
    yield i;
    if (i.pos === Tag.body && i.type === Tag.Array) {
      stop = i.value;
      break;
    }
  }
  let last;
  for (const j of s) {
    if (j.value === stop) {
      if (!last || last.type !== Tag.ReturnStatement)
        yield s.tok(Tag.push, Tag.ReturnStatement, { last: true });
      else last.value.last = true;
    }
    yield j;
    last = j;
  }
}
github awto / effectfuljs / packages / core / src / kit / snippets.js View on Github external
export function* peelBlockFrom(s) {
  const i = s.cur();
  if (i != null && i.type === Tag.BlockStatement) {
    yield s.peel();
    yield* s.peelTo(Tag.body);
  } else {
    yield s.enter(i.pos, Tag.BlockStatement);
    yield s.enter(Tag.body, Tag.Array);
    yield s.enter(Tag.push, Subst);
  }
}
github awto / effectfuljs / packages / core / src / kit / core.js View on Github external
value = type;
    type = null;
  }
  if (type == null) {
    type = pos;
    if (value.node && value.node.type) {
      type = Tag[value.node.type];
      if (type == null) type = pos;
    }
  }
  if (value == null) {
    value = {};
  }
  if (value.node == null) {
    switch (type) {
      case Tag.Array:
        value.node = [];
        break;
      case Tag.Null:
        value.node = null;
        break;
      default:
        value.node = {};
    }
  }
  return [pos, type, value];
}
github awto / effectfuljs / packages / core / src / kit / core.js View on Github external
export function* concatArraysPass(s) {
  let buf = null;
  for (const i of s) {
    if (buf != null) {
      if (!i.enter || i.pos !== buf.pos) {
        yield buf;
        yield i;
      }
      buf = null;
    } else if (i.leave && i.type === Tag.Array) {
      buf = i;
    } else {
      yield i;
    }
  }
  if (buf != null) yield buf;
}
github awto / effectfuljs / packages / core / src / debug.js View on Github external
yield* walk();
              yield* b.leave();
              yield* b.leave();
            }
            break;
          case "scope":
            if (i.enter) {
              yield D.copyComment(
                i,
                D.setComment(
                  b.enter(i.pos, Tag.BlockStatement),
                  `$${i.value.node.name}`,
                  "color:blue;font-size:large"
                )
              );
              yield b.enter(Tag.body, Tag.Array);
              yield b.enter(Tag.push, Kit.Subst);
              yield* walk();
              yield* b.leave();
              yield* b.leave();
              yield* b.leave();
            }
            break;
          case "writeState":
            if (i.enter) {
              yield D.copyComment(
                i,
                D.setComment(
                  b.enter(i.pos, Tag.CallExpression, {
                    node: { callee: { type: "Identifier", name: "write" } }
                  }),
                  `write`,
github awto / effectfuljs / packages / core / src / state.js View on Github external
);
              yield* sl.leave();
              yield* sl.leave();
              continue;
            case Tag.FunctionDeclaration:
              const old = decls.get(i.value.funcId);
              const init = [
                ...sl.copy(
                  Kit.setType(Kit.setPos(i, Tag.init), Tag.FunctionExpression)
                )
              ];
              if (old)
                old.init = old.init
                  ? [
                      sl.enter(Tag.init, Tag.SequenceExpression),
                      sl.enter(Tag.expressions, Tag.Array),
                      ...Kit.reposOneArr(old.init, Tag.push),
                      ...Kit.reposOneArr(init, Tag.push),
                      ...sl.leave(),
                      ...sl.leave()
                    ]
                  : init;
              else
                decls.set(i.value.funcId, {
                  raw: null,
                  init
                });
              if (i.value.wrapId) i.value.funcId = i.value.wrapId;
              continue;
            case Tag.TryStatement:
              if (!i.value.eff) {
                yield i;
github awto / effectfuljs / packages / core / src / state.js View on Github external
if (k.interpr === Bind.ctxField || k.param) {
                    if (v.init) {
                      assigns.push({
                        sym: k,
                        init: Kit.reposOneArr(v.init, Tag.right)
                      });
                    }
                  } else vars.push(v);
                }
              }
              if (vars.length) {
                const lab = sl.label();
                yield sl.enter(Tag.push, Tag.VariableDeclaration, {
                  node: { kind: "var" }
                });
                yield sl.enter(Tag.declarations, Tag.Array);
                for (const { sym, init } of vars) {
                  if (sym.substSym) continue;
                  yield sl.enter(Tag.push, Tag.VariableDeclarator);
                  yield sl.tok(Tag.id, Tag.Identifier, { sym, decl: true });
                  if (init) yield* init;
                  yield* sl.leave();
                }
                yield* lab();
              }

              for (const j of decls) if (j[1].raw != null) yield* j[1].raw;
              if (assigns.length) {
                for (const { sym, init } of assigns) {
                  yield sl.enter(Tag.push, Tag.ExpressionStatement);
                  yield sl.enter(Tag.expression, Tag.AssignmentExpression, {
                    node: { operator: "=" }