Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switch (expressionContext) {
case ExpressionContext.Expression: {
// in classic mode, this is always a this-fallback
let name = context.meta.upvars![freeVar];
concatExpressions(
encoder,
context,
[op(Op.GetVariable, 0), op(Op.GetProperty, name)],
constants
);
break;
}
case ExpressionContext.AppendSingleId: {
let resolver = context.syntax.program.resolverDelegate;
let name = context.meta.upvars![freeVar];
let resolvedHelper = resolver.lookupHelper(name, context.meta.referrer);
let expressions: ExpressionCompileActions;
if (resolvedHelper) {
expressions = Call({ handle: resolvedHelper, params: null, hash: null });
} else {
// in classic mode, this is always a this-fallback
expressions = [op(Op.GetVariable, 0), op(Op.GetProperty, name)];
}
concatExpressions(encoder, context, expressions, constants);
break;
return [];
} else if (val === true) {
return [[Op.StaticAttr, name, '', namespace]];
} else if (typeof val === 'string') {
return [[Op.StaticAttr, name, val, namespace]];
} else {
throw new Error(`Unexpected/unimplemented literal attribute ${JSON.stringify(val)}`);
}
}
default:
return [
[
Op.DynamicAttr,
name,
buildExpression(value, ExpressionContext.AppendSingleId, symbols),
namespace,
],
];
}
}
private mustacheAttrValue(value: AST.TextNode | AST.MustacheStatement): value is AST.TextNode {
if (value.type === 'TextNode') {
this.opcode(['literal', value.chars]);
return true;
} else if (isKeyword(value)) {
this.keyword(value);
} else if (isHelperInvocation(value)) {
this.prepareHelper(value, 'helper');
this.expression(value.path, ExpressionContext.CallHead, value);
this.opcode(['helper'], value);
} else {
this.expression(value.path, ExpressionContext.AppendSingleId, value);
}
return false;
}
function mustacheContext(body: AST.Expression): ExpressionContext {
if (body.type === 'PathExpression') {
if (body.parts.length > 1 || body.data) {
return ExpressionContext.Expression;
} else {
return ExpressionContext.AppendSingleId;
}
} else {
return ExpressionContext.Expression;
}
}
export function normalizeStatement(statement: BuilderStatement): NormalizedStatement {
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);
}
}