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

Class Unparser

packages/compiler/test/expression_parser/utils/unparser.ts:44–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42} from '../../../src/expression_parser/ast';
43
44class Unparser implements AstVisitor {
45 private static _quoteRegExp = /"/g;
46 // using non-null assertion because they're both re(set) by unparse()
47 private _expression!: string;
48
49 unparse(ast: AST) {
50 this._expression = '';
51 this._visit(ast);
52 return this._expression;
53 }
54
55 visitPropertyRead(ast: PropertyRead, context: any) {
56 this._visit(ast.receiver);
57 this._expression +=
58 ast.receiver instanceof ImplicitReceiver || ast.receiver instanceof ThisReceiver
59 ? `${ast.name}`
60 : `.${ast.name}`;
61 }
62
63 visitUnary(ast: Unary, context: any) {
64 this._expression += ast.operator;
65 this._visit(ast.expr);
66 }
67
68 visitBinary(ast: Binary, context: any) {
69 this._visit(ast.left);
70 this._expression += ` ${ast.operation} `;
71 this._visit(ast.right);
72 }
73
74 visitChain(ast: Chain, context: any) {
75 const len = ast.expressions.length;
76 for (let i = 0; i < len; i++) {
77 this._visit(ast.expressions[i]);
78 this._expression += i == len - 1 ? ';' : '; ';
79 }
80 }
81
82 visitConditional(ast: Conditional, context: any) {
83 this._visit(ast.condition);
84 this._expression += ' ? ';
85 this._visit(ast.trueExp);
86 this._expression += ' : ';
87 this._visit(ast.falseExp);
88 }
89
90 visitPipe(ast: BindingPipe, context: any) {
91 this._expression += '(';
92 this._visit(ast.exp);
93 this._expression += ` | ${ast.name}`;
94 ast.args.forEach((arg) => {
95 this._expression += ':';
96 this._visit(arg);
97 });
98 this._expression += ')';
99 }
100
101 visitCall(ast: Call, context: any) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected