Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
export function tok(pos, type, value) {
[pos, type, value] = guessType(pos, type, value);
value = tagValue(pos, type, value);
return { enter: true, leave: true, type, pos, value };
}
export function enter() {
let [pos, type, value] = guessType.apply(null, arguments);
invariant(pos && type && value);
value = tagValue(pos, type, value);
return { enter: true, leave: false, type, pos, value };
}
export const Any = symbol("Any", "ctrl");
export function leave() {
if (!arguments.length)
return { enter: false, leave: true, type: Any, pos: Any, value: {} };
const [pos, type, value] = arguments.length
? guessType.apply(null, arguments)
: [Any, Any, {}];
return { enter: false, leave: true, type, pos, value };
}
/**
* sets `parentType` field describing current parent node type
* in the stream for each token
*/
export function* resetParent(s) {
}
/** calculates for each Identifier lhs/rhs fields */
function* calcRefKind(si) {
for (const i of Kit.resetFieldInfo(si)) {
yield i;
if (i.enter) {
const fi = i.value.fieldInfo;
i.value.lhs = fi && fi.mod;
i.value.rhs = fi && fi.expr;
}
}
}
/** identifier is passed threaded between effectful frames as their args */
export const byVal = symbol("state.byVal");
/** identifier is passed as field of an object */
export const byRef = symbol("state.byRef");
/** handles byVal, byRef directives */
function calcVarsHandling(si) {
const s = Kit.auto(si);
const top = s.first.value;
function* walk() {
for (const i of s.sub()) {
if (i.enter) {
switch (i.type) {
case byVal:
case byRef:
for (const i of s.sub()) {
if (i.enter) {
if (i.type !== Tag.Identifier || i.value.sym)
if (i.enter) {
invariant(!i.leave);
yield* subst(i.pos);
}
} else yield i;
}
}
yield* walk();
}
export const complete = pipe(
completeAny,
resetLevel
);
export const Subst = symbol("Subst", "ctrl");
export function* wrap(i, tok, value) {
if (i.enter) yield enter(i.pos, tok, value);
yield i;
if (i.leave) yield leave(i.pos, tok, value);
}
export function* bracket(i, pos, tok, value) {
yield enter(pos, tok, value);
yield* i;
yield leave(pos, tok, value);
}
export const map = curry(function* map(f, s) {
for (const i of s) yield f(i);
});
}
}
}
}
walk(["#ret"], new Map());
sl.close(top);
}
scope(sl.take());
return sa;
}
/**
* specify a jump to end or beginning of `scope`,
* normilized to jumps end only
*/
export const jump = symbol("jump", "ctrl");
/** removes AST JS LabeledStatement nodes */
export function removeLabeledStatement(s) {
const sl = Kit.auto(s);
function* walk(cur) {
for (const i of sl.sub()) {
if (i.enter) {
if (i.type === Tag.LabeledStatement) {
const c = sl.cur();
if (c.pos === Tag.label) Kit.skip(sl.one());
const labs = cur || [];
labs.push(i.value.node.label.name);
yield* Kit.reposOne(walk(labs), i.pos);
sl.close(i);
continue;
}
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();
}
}
Tag.AutoClose = symbol("AutoClose", "ctrl");
export function* completeAutoClose(s) {
const stack = [];
let level = 0;
for (const i of s) {
if (i.pos === Tag.AutoClose) {
if (i.enter) stack.push(level);
if (i.leave) {
for (let j = stack.shift(); j < level; j++) yield leave();
}
} else {
if (i.enter) level++;
if (i.leave) level--;
yield i;
}
}
/** calculates for each Identifier lhs/rhs fields */
function* calcRefKind(si) {
for (const i of Kit.resetFieldInfo(si)) {
yield i;
if (i.enter) {
const fi = i.value.fieldInfo;
i.value.lhs = fi && fi.mod;
i.value.rhs = fi && fi.expr;
}
}
}
/** identifier is passed threaded between effectful frames as their args */
export const byVal = symbol("state.byVal");
/** identifier is passed as field of an object */
export const byRef = symbol("state.byRef");
/** handles byVal, byRef directives */
function calcVarsHandling(si) {
const s = Kit.auto(si);
const top = s.first.value;
function* walk() {
for (const i of s.sub()) {
if (i.enter) {
switch (i.type) {
case byVal:
case byRef:
for (const i of s.sub()) {
if (i.enter) {
if (i.type !== Tag.Identifier || i.value.sym)
throw s.error("expected list of declared identifiers");
i.value.sym.byVal = i.type === byVal;