Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
symbols: Symbols
): WireFormat.Statement[] {
let out: WireFormat.Statement[] = [[Op.OpenElement, name, !hasSplat(attrs)]];
if (attrs) {
let { attributes, args } = buildAttrs(attrs, symbols);
out.push(...attributes);
assert(args === null, `Can't pass args to a simple element`);
}
out.push([Op.FlushElement]);
if (Array.isArray(block)) {
block.forEach(s => out.push(...buildStatement(s, symbols)));
} else if (block === null) {
// do nothing
} else {
throw assertNever(block);
}
out.push([Op.CloseElement]);
return out;
}
// BuilderCallExpression
}
} else if (typeof expression !== 'object') {
switch (typeof expression) {
case 'string': {
return normalizeDottedPathExpression(expression);
}
case 'boolean':
case 'number':
return { type: ExpressionKind.Literal, value: expression };
default:
throw assertNever(expression);
}
} else {
throw assertNever(expression);
}
}
);
}
}
// BuilderCallExpression
}
} else if (typeof expression !== 'object') {
switch (typeof expression) {
case 'string': {
return normalizeDottedPathExpression(expression);
}
case 'boolean':
case 'number':
return { type: ExpressionKind.Literal, value: expression };
default:
throw assertNever(expression);
}
} else {
throw assertNever(expression);
}
}
} else if (Array.isArray(action)) {
for (let item of action) {
concatStatements(context, item);
}
} else if (action.type === 'Number') {
pushOp(context.encoder, context.syntax.program.constants, action);
} else {
if (action.type === 'Compile') {
pushCompileOp(context, action);
} else if (action.type === 'Resolution') {
pushResolutionOp(context.encoder, context, action, context.syntax.program.constants);
} else if (action.type === 'Simple') {
pushBuilderOp(context, action);
} else if (action.type === 'Error') {
} else {
throw assertNever(action, `unexpected action type`);
}
}
}
};
}
}
case 'boolean':
case 'number':
return {
expr: { type: ExpressionKind.Literal, value: expression },
kind: HeadKind.AppendExpr,
trusted: true,
};
default:
throw assertNever(expression);
}
} else {
throw assertNever(expression);
}
}
if (Array.isArray(statement)) {
if (statementIsExpression(statement)) {
return normalizeAppendExpression(statement, ExpressionContext.AppendSingleId);
} else if (isSugaryArrayStatement(statement)) {
return normalizeSugaryArrayStatement(statement);
} else {
return normalizeVerboseStatement(statement);
}
} else if (typeof statement === 'string') {
return {
kind: HeadKind.AppendPath,
path: normalizeDottedPath(statement),
trusted: false,
};
} else {
throw assertNever(statement);
}
}
let path = buildPath(normalized.path, ExpressionContext.BlockHead, symbols);
return [[Op.Block, path, params, hash, blocks]];
}
case HeadKind.Element:
return buildElement(normalized, symbols);
case HeadKind.Modifier:
throw unimpl('modifier');
case HeadKind.DynamicComponent:
throw unimpl('dynamic component');
default:
throw assertNever(normalized);
}
}
} else if (action.type === 'Number') {
pushOp(encoder, constants, action);
} else if (action.type === 'Resolution') {
pushResolutionOp(encoder, context, action, constants);
} else if (action.type === 'Simple') {
pushBuilderOp(context, action);
} else if (action.type === 'Error') {
encoder.error({
problem: action.op1.problem,
span: {
start: action.op1.start,
end: action.op1.end,
},
});
} else {
throw assertNever(action, 'unexpected action kind');
}
}
return ['undefined'];
case Op.Call:
return [
'call',
this.formatOpcode(opcode[3]),
this.formatParams(opcode[4]),
this.formatHash(opcode[5]),
];
case Op.Concat:
return ['concat', this.formatParams(opcode[1] as WireFormat.Core.Params)];
default: {
let opName = opcode[0];
throw assertNever(opName, `unexpected ${opName}`);
}
}
} else {
return opcode;
}
}