Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 3x 3x 3x 28x 4x 4x 4x 41x 41x 41x 10x 10x 10x | import {Expression, type ExpressionResult} from '../codegen-steps';
import * as util from '../util';
import type * as types from '../types';
export const containerOperators: types.OperatorDefinition<any>[] = [
[
'len',
[],
1,
(expr: types.ExprStr, ctx) => {
return util.len(ctx.eval(expr[1], ctx));
},
(ctx: types.OperatorCodegenCtx<types.ExprStr>): ExpressionResult => {
ctx.link(util.len, 'len');
const js = `len(${ctx.operands[0]})`;
return new Expression(js);
},
] as types.OperatorDefinition<types.ExprStr>,
[
'[]',
['member'],
2,
(expr: types.ExprMember, ctx) => {
const container = ctx.eval(expr[1], ctx);
const index = ctx.eval(expr[2], ctx);
return util.member(container, index);
},
(ctx: types.OperatorCodegenCtx<types.ExprMember>): ExpressionResult => {
ctx.link(util.member, 'member');
const js = `member((${ctx.operands[0]}),(${ctx.operands[1]}))`;
return new Expression(js);
},
] as types.OperatorDefinition<types.ExprMember>,
];
|