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

Function convertAst

packages/compiler/src/template/pipeline/src/ingest.ts:1063–1236  ·  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

1061 * Convert a template AST expression into an output AST expression.
1062 */
1063function convertAst(
1064 ast: e.AST,
1065 job: CompilationJob,
1066 baseSourceSpan: ParseSourceSpan | null,
1067): o.Expression {
1068 if (ast instanceof e.ASTWithSource) {
1069 return convertAst(ast.ast, job, baseSourceSpan);
1070 } else if (ast instanceof e.PropertyRead) {
1071 if (ast.receiver instanceof e.ImplicitReceiver) {
1072 return new ir.LexicalReadExpr(ast.name);
1073 } else {
1074 return new o.ReadPropExpr(
1075 convertAst(ast.receiver, job, baseSourceSpan),
1076 ast.name,
1077 null,
1078 convertSourceSpan(ast.span, baseSourceSpan),
1079 );
1080 }
1081 } else if (ast instanceof e.Call) {
1082 if (ast.receiver instanceof e.ImplicitReceiver) {
1083 throw new Error(`Unexpected ImplicitReceiver`);
1084 } else {
1085 return new o.InvokeFunctionExpr(
1086 convertAst(ast.receiver, job, baseSourceSpan),
1087 ast.args.map((arg) => convertAst(arg, job, baseSourceSpan)),
1088 undefined,
1089 convertSourceSpan(ast.span, baseSourceSpan),
1090 );
1091 }
1092 } else if (ast instanceof e.LiteralPrimitive) {
1093 return o.literal(ast.value, undefined, convertSourceSpan(ast.span, baseSourceSpan));
1094 } else if (ast instanceof e.Unary) {
1095 switch (ast.operator) {
1096 case '+':
1097 return new o.UnaryOperatorExpr(
1098 o.UnaryOperator.Plus,
1099 convertAst(ast.expr, job, baseSourceSpan),
1100 undefined,
1101 convertSourceSpan(ast.span, baseSourceSpan),
1102 );
1103 case '-':
1104 return new o.UnaryOperatorExpr(
1105 o.UnaryOperator.Minus,
1106 convertAst(ast.expr, job, baseSourceSpan),
1107 undefined,
1108 convertSourceSpan(ast.span, baseSourceSpan),
1109 );
1110 default:
1111 throw new Error(`AssertionError: unknown unary operator ${ast.operator}`);
1112 }
1113 } else if (ast instanceof e.Binary) {
1114 const operator = BINARY_OPERATORS.get(ast.operation);
1115 if (operator === undefined) {
1116 throw new Error(`AssertionError: unknown binary operator ${ast.operation}`);
1117 }
1118 return new o.BinaryOperatorExpr(
1119 operator,
1120 convertAst(ast.left, job, baseSourceSpan),

Callers 11

ingestDomPropertyFunction · 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