MCPcopy Create free account
hub / github.com/angular/angular / convertAst

Function convertAst

packages/compiler/src/template/pipeline/src/ingest.ts:1179–1352  ·  view source on GitHub ↗

* Convert a template AST expression into an output AST expression.

(
  ast: e.AST,
  job: CompilationJob,
  baseSourceSpan: ParseSourceSpan | null,
)

Source from the content-addressed store, hash-verified

1177 * Convert a template AST expression into an output AST expression.
1178 */
1179function convertAst(
1180 ast: e.AST,
1181 job: CompilationJob,
1182 baseSourceSpan: ParseSourceSpan | null,
1183): o.Expression {
1184 if (ast instanceof e.ASTWithSource) {
1185 return convertAst(ast.ast, job, baseSourceSpan);
1186 } else if (ast instanceof e.PropertyRead) {
1187 if (ast.receiver instanceof e.ImplicitReceiver) {
1188 return new ir.LexicalReadExpr(ast.name);
1189 } else {
1190 return new o.ReadPropExpr(
1191 convertAst(ast.receiver, job, baseSourceSpan),
1192 ast.name,
1193 null,
1194 convertSourceSpan(ast.span, baseSourceSpan),
1195 );
1196 }
1197 } else if (ast instanceof e.Call) {
1198 if (ast.receiver instanceof e.ImplicitReceiver) {
1199 throw new Error(`Unexpected ImplicitReceiver`);
1200 } else {
1201 return new o.InvokeFunctionExpr(
1202 convertAst(ast.receiver, job, baseSourceSpan),
1203 ast.args.map((arg) => convertAst(arg, job, baseSourceSpan)),
1204 undefined,
1205 convertSourceSpan(ast.span, baseSourceSpan),
1206 );
1207 }
1208 } else if (ast instanceof e.LiteralPrimitive) {
1209 return o.literal(ast.value, undefined, convertSourceSpan(ast.span, baseSourceSpan));
1210 } else if (ast instanceof e.Unary) {
1211 switch (ast.operator) {
1212 case '+':
1213 return new o.UnaryOperatorExpr(
1214 o.UnaryOperator.Plus,
1215 convertAst(ast.expr, job, baseSourceSpan),
1216 undefined,
1217 convertSourceSpan(ast.span, baseSourceSpan),
1218 );
1219 case '-':
1220 return new o.UnaryOperatorExpr(
1221 o.UnaryOperator.Minus,
1222 convertAst(ast.expr, job, baseSourceSpan),
1223 undefined,
1224 convertSourceSpan(ast.span, baseSourceSpan),
1225 );
1226 default:
1227 throw new Error(`AssertionError: unknown unary operator ${ast.operator}`);
1228 }
1229 } else if (ast instanceof e.Binary) {
1230 const operator = BINARY_OPERATORS.get(ast.operation);
1231 if (operator === undefined) {
1232 throw new Error(`AssertionError: unknown binary operator ${ast.operation}`);
1233 }
1234 return new o.BinaryOperatorExpr(
1235 operator,
1236 convertAst(ast.left, job, baseSourceSpan),

Callers 12

ingestDomPropertyFunction · 0.85
ingestForeignComponentFunction · 0.85
ingestBoundTextFunction · 0.85
ingestIfBlockFunction · 0.85
ingestSwitchBlockFunction · 0.85
ingestDeferTriggersFunction · 0.85
ingestForBlockFunction · 0.85
ingestLetDeclarationFunction · 0.85
convertTemplateLiteralFunction · 0.85
makeListenerHandlerOpsFunction · 0.85

Calls 5

convertSourceSpanFunction · 0.85
convertTemplateLiteralFunction · 0.85
mapMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected