Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* debDumbBindStmt(s) {
for (const i of s) {
switch (symName(i.type)) {
case "letStmt":
const hasBind = i.value.sym != null;
if (i.enter) {
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"
if (
i.enter == null ||
i.leave == null ||
i.value == null ||
i.type == null ||
i.pos == null
) {
console.error(i);
throw new Error("incomplete token information");
}
let short = ccg(i.value && i.value.node ? i.value.node : i.value);
if (short.length > MAX_TRACE_CODE_LEN)
short = short.substr(0, MAX_TRACE_CODE_LEN) + "... ";
const dir = i.enter ? (i.leave ? "*" : ">") : i.leave ? "<" : "-";
let ty = symName(i.pos);
if (i.type != null && symName(i.type) !== ty) ty += ":" + symName(i.type);
if (i.enter) level++;
yield {
enter: i.enter,
leave: i.leave,
pack: i,
obj: i.value,
prefix: "",
short,
flags: [],
flagsStyles: [],
dir,
ty,
level,
index: ++index
};
if (i.leave) level--;
}
if (
i.enter == null ||
i.leave == null ||
i.value == null ||
i.type == null ||
i.pos == null
) {
console.error(i);
throw new Error("incomplete token information");
}
let short = ccg(i.value && i.value.node ? i.value.node : i.value);
if (short.length > MAX_TRACE_CODE_LEN)
short = short.substr(0, MAX_TRACE_CODE_LEN) + "... ";
const dir = i.enter ? (i.leave ? "*" : ">") : i.leave ? "<" : "-";
let ty = symName(i.pos);
if (i.type != null && symName(i.type) !== ty) ty += ":" + symName(i.type);
if (i.enter) level++;
yield {
enter: i.enter,
leave: i.leave,
pack: i,
obj: i.value,
prefix: "",
short,
flags: [],
flagsStyles: [],
dir,
ty,
level,
index: ++index
};
function* _frame() {
for (const i of s.sub()) {
if (i.enter) {
switch (symName(i.type)) {
case "bindPat":
yield s.tok(i.pos, Tag.Identifier, { sym: i.value.sym });
Kit.skip(s.copy(i));
continue;
case "app":
yield* s.template(Tag.push, `=$I($E)`, i.value.sym);
if (!i.leave) yield* _frame();
yield* s.leave();
s.close(i);
continue;
case "letStmt":
{
const args = [];
if (i.value.sym) args.push(i.value.sym);
if (i.value.tmpVar) args.push(i.value.tmpVar);
yield* s.template(
(saved.has(i) ? "D" : "") +
(i === v.sym ? "S" : "") +
(!clos.has(i) && dst.has(i) ? "C" : "") +
(i === v.errSym ? "E" : "") +
(i === v.patSym ? "B" : ":")
)
.join()}}`
: "";
i = D.setComment(
i,
`label{${id(v.declSym)}}${paramStr}${hndl}${fin}`,
"hl"
);
if (i.dstClass) i = D.setComment(i, `class{${id(i.dstClass.declSym)}}`);
}
if (symName(i.type) === "letStmt" || symName(i.type) === "jump") {
let fin =
v.preCompose && v.preCompose.length
? `|Pre{${v.preCompose
.map(
i =>
id(i.declSym) +
"->" +
(i.contArg ? id(i.contArg.declSym) : "")
)
.join()}}`
: "";
let args = v.frameArgs
? `|Args{${[...v.frameArgs]
.map(([k, v]) => `${id(k)}=${id(v)}`)
.join()}}`
: "";
);
yield b.enter(Tag.body, Tag.Array);
yield b.enter(Tag.push, Kit.Subst);
yield* walk();
yield* lab();
}
break;
default:
if (i.type.ctrl) {
if (i.type.arg === "b") {
if (i.enter) {
yield D.copyComment(
i,
D.setComment(
b.enter(i.pos, Tag.BlockStatement),
symName(i.type),
"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;
}
}
yield i;
}
}
export function* removeNulls(s) {
const stack = [];
for (const i of s) {
if (i.type === Tag.Null) {
if (i.enter && i.pos != Tag.push && stack[0])
stack[0][symName(i.pos)] = null;
continue;
}
yield i;
if (i.enter) stack.unshift(i.value.node);
if (i.leave) stack.shift();
}
}
function* walk() {
for (const i of b.sub()) {
switch (symName(i.type)) {
case "jump":
if (i.enter) {
yield D.copyComment(i, b.enter(i.pos, Tag.CallExpression));
yield Kit.tok(Tag.callee, Tag.Identifier, {
node: { name: "jump" }
});
yield b.enter(Tag.arguments, Tag.Array);
const d = i.value.node.dst;
if (d != null)
yield Kit.tok(Tag.push, Tag.StringLiteral, {
node: { value: i.value.node.dst.name }
});
yield* walk();
yield* b.leave();
yield* b.leave();
}
export const framesTxt = (opts = {}) => si => {
const sa = Kit.toArray(si);
const s = Kit.auto(sa);
for (const i of s) {
if (i.enter && symName(i.type) === "frame")
i.value[`deb_txt_${opts.name || ""}`] = singleFrameTxt(i.value, s.sub());
}
return sa;
};