1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. All Rights Reserved.
|
4
|
*
|
5
|
* Use of this source code is governed by an MIT-style license that can be
|
6
|
* found in the LICENSE file at https://angular.io/license
|
7
|
*/
|
8
|
import { SecurityContext } from '@angular/core';
|
9
|
import { AstPath } from '../ast_path';
|
10
|
import { CompileDirectiveSummary, CompileProviderMetadata, CompileTokenMetadata } from '../compile_metadata';
|
11
|
import { AST } from '../expression_parser/ast';
|
12
|
import { LifecycleHooks } from '../lifecycle_reflector';
|
13
|
import { ParseSourceSpan } from '../parse_util';
|
14
|
/**
|
15
|
* An Abstract Syntax Tree node representing part of a parsed Angular template.
|
16
|
*/
|
17
|
export interface TemplateAst {
|
18
|
/**
|
19
|
* The source span from which this node was parsed.
|
20
|
*/
|
21
|
sourceSpan: ParseSourceSpan;
|
22
|
/**
|
23
|
* Visit this node and possibly transform it.
|
24
|
*/
|
25
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
26
|
}
|
27
|
/**
|
28
|
* A segment of text within the template.
|
29
|
*/
|
30
|
export declare class TextAst implements TemplateAst {
|
31
|
value: string;
|
32
|
ngContentIndex: number;
|
33
|
sourceSpan: ParseSourceSpan;
|
34
|
constructor(value: string, ngContentIndex: number, sourceSpan: ParseSourceSpan);
|
35
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
36
|
}
|
37
|
/**
|
38
|
* A bound expression within the text of a template.
|
39
|
*/
|
40
|
export declare class BoundTextAst implements TemplateAst {
|
41
|
value: AST;
|
42
|
ngContentIndex: number;
|
43
|
sourceSpan: ParseSourceSpan;
|
44
|
constructor(value: AST, ngContentIndex: number, sourceSpan: ParseSourceSpan);
|
45
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
46
|
}
|
47
|
/**
|
48
|
* A plain attribute on an element.
|
49
|
*/
|
50
|
export declare class AttrAst implements TemplateAst {
|
51
|
name: string;
|
52
|
value: string;
|
53
|
sourceSpan: ParseSourceSpan;
|
54
|
constructor(name: string, value: string, sourceSpan: ParseSourceSpan);
|
55
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
56
|
}
|
57
|
/**
|
58
|
* A binding for an element property (e.g. `[property]="expression"`) or an animation trigger (e.g.
|
59
|
* `[@trigger]="stateExp"`)
|
60
|
*/
|
61
|
export declare class BoundElementPropertyAst implements TemplateAst {
|
62
|
name: string;
|
63
|
type: PropertyBindingType;
|
64
|
securityContext: SecurityContext;
|
65
|
value: AST;
|
66
|
unit: string | null;
|
67
|
sourceSpan: ParseSourceSpan;
|
68
|
constructor(name: string, type: PropertyBindingType, securityContext: SecurityContext, value: AST, unit: string | null, sourceSpan: ParseSourceSpan);
|
69
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
70
|
readonly isAnimation: boolean;
|
71
|
}
|
72
|
/**
|
73
|
* A binding for an element event (e.g. `(event)="handler()"`) or an animation trigger event (e.g.
|
74
|
* `(@trigger.phase)="callback($event)"`).
|
75
|
*/
|
76
|
export declare class BoundEventAst implements TemplateAst {
|
77
|
name: string;
|
78
|
target: string | null;
|
79
|
phase: string | null;
|
80
|
handler: AST;
|
81
|
sourceSpan: ParseSourceSpan;
|
82
|
static calcFullName(name: string, target: string | null, phase: string | null): string;
|
83
|
constructor(name: string, target: string | null, phase: string | null, handler: AST, sourceSpan: ParseSourceSpan);
|
84
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
85
|
readonly fullName: string;
|
86
|
readonly isAnimation: boolean;
|
87
|
}
|
88
|
/**
|
89
|
* A reference declaration on an element (e.g. `let someName="expression"`).
|
90
|
*/
|
91
|
export declare class ReferenceAst implements TemplateAst {
|
92
|
name: string;
|
93
|
value: CompileTokenMetadata;
|
94
|
sourceSpan: ParseSourceSpan;
|
95
|
constructor(name: string, value: CompileTokenMetadata, sourceSpan: ParseSourceSpan);
|
96
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
97
|
}
|
98
|
/**
|
99
|
* A variable declaration on a <ng-template> (e.g. `var-someName="someLocalName"`).
|
100
|
*/
|
101
|
export declare class VariableAst implements TemplateAst {
|
102
|
name: string;
|
103
|
value: string;
|
104
|
sourceSpan: ParseSourceSpan;
|
105
|
constructor(name: string, value: string, sourceSpan: ParseSourceSpan);
|
106
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
107
|
}
|
108
|
/**
|
109
|
* An element declaration in a template.
|
110
|
*/
|
111
|
export declare class ElementAst implements TemplateAst {
|
112
|
name: string;
|
113
|
attrs: AttrAst[];
|
114
|
inputs: BoundElementPropertyAst[];
|
115
|
outputs: BoundEventAst[];
|
116
|
references: ReferenceAst[];
|
117
|
directives: DirectiveAst[];
|
118
|
providers: ProviderAst[];
|
119
|
hasViewContainer: boolean;
|
120
|
queryMatches: QueryMatch[];
|
121
|
children: TemplateAst[];
|
122
|
ngContentIndex: number | null;
|
123
|
sourceSpan: ParseSourceSpan;
|
124
|
endSourceSpan: ParseSourceSpan | null;
|
125
|
constructor(name: string, attrs: AttrAst[], inputs: BoundElementPropertyAst[], outputs: BoundEventAst[], references: ReferenceAst[], directives: DirectiveAst[], providers: ProviderAst[], hasViewContainer: boolean, queryMatches: QueryMatch[], children: TemplateAst[], ngContentIndex: number | null, sourceSpan: ParseSourceSpan, endSourceSpan: ParseSourceSpan | null);
|
126
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
127
|
}
|
128
|
/**
|
129
|
* A `<ng-template>` element included in an Angular template.
|
130
|
*/
|
131
|
export declare class EmbeddedTemplateAst implements TemplateAst {
|
132
|
attrs: AttrAst[];
|
133
|
outputs: BoundEventAst[];
|
134
|
references: ReferenceAst[];
|
135
|
variables: VariableAst[];
|
136
|
directives: DirectiveAst[];
|
137
|
providers: ProviderAst[];
|
138
|
hasViewContainer: boolean;
|
139
|
queryMatches: QueryMatch[];
|
140
|
children: TemplateAst[];
|
141
|
ngContentIndex: number;
|
142
|
sourceSpan: ParseSourceSpan;
|
143
|
constructor(attrs: AttrAst[], outputs: BoundEventAst[], references: ReferenceAst[], variables: VariableAst[], directives: DirectiveAst[], providers: ProviderAst[], hasViewContainer: boolean, queryMatches: QueryMatch[], children: TemplateAst[], ngContentIndex: number, sourceSpan: ParseSourceSpan);
|
144
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
145
|
}
|
146
|
/**
|
147
|
* A directive property with a bound value (e.g. `*ngIf="condition").
|
148
|
*/
|
149
|
export declare class BoundDirectivePropertyAst implements TemplateAst {
|
150
|
directiveName: string;
|
151
|
templateName: string;
|
152
|
value: AST;
|
153
|
sourceSpan: ParseSourceSpan;
|
154
|
constructor(directiveName: string, templateName: string, value: AST, sourceSpan: ParseSourceSpan);
|
155
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
156
|
}
|
157
|
/**
|
158
|
* A directive declared on an element.
|
159
|
*/
|
160
|
export declare class DirectiveAst implements TemplateAst {
|
161
|
directive: CompileDirectiveSummary;
|
162
|
inputs: BoundDirectivePropertyAst[];
|
163
|
hostProperties: BoundElementPropertyAst[];
|
164
|
hostEvents: BoundEventAst[];
|
165
|
contentQueryStartId: number;
|
166
|
sourceSpan: ParseSourceSpan;
|
167
|
constructor(directive: CompileDirectiveSummary, inputs: BoundDirectivePropertyAst[], hostProperties: BoundElementPropertyAst[], hostEvents: BoundEventAst[], contentQueryStartId: number, sourceSpan: ParseSourceSpan);
|
168
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
169
|
}
|
170
|
/**
|
171
|
* A provider declared on an element
|
172
|
*/
|
173
|
export declare class ProviderAst implements TemplateAst {
|
174
|
token: CompileTokenMetadata;
|
175
|
multiProvider: boolean;
|
176
|
eager: boolean;
|
177
|
providers: CompileProviderMetadata[];
|
178
|
providerType: ProviderAstType;
|
179
|
lifecycleHooks: LifecycleHooks[];
|
180
|
sourceSpan: ParseSourceSpan;
|
181
|
constructor(token: CompileTokenMetadata, multiProvider: boolean, eager: boolean, providers: CompileProviderMetadata[], providerType: ProviderAstType, lifecycleHooks: LifecycleHooks[], sourceSpan: ParseSourceSpan);
|
182
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
183
|
}
|
184
|
export declare enum ProviderAstType {
|
185
|
PublicService = 0,
|
186
|
PrivateService = 1,
|
187
|
Component = 2,
|
188
|
Directive = 3,
|
189
|
Builtin = 4,
|
190
|
}
|
191
|
/**
|
192
|
* Position where content is to be projected (instance of `<ng-content>` in a template).
|
193
|
*/
|
194
|
export declare class NgContentAst implements TemplateAst {
|
195
|
index: number;
|
196
|
ngContentIndex: number;
|
197
|
sourceSpan: ParseSourceSpan;
|
198
|
constructor(index: number, ngContentIndex: number, sourceSpan: ParseSourceSpan);
|
199
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
200
|
}
|
201
|
/**
|
202
|
* Enumeration of types of property bindings.
|
203
|
*/
|
204
|
export declare enum PropertyBindingType {
|
205
|
/**
|
206
|
* A normal binding to a property (e.g. `[property]="expression"`).
|
207
|
*/
|
208
|
Property = 0,
|
209
|
/**
|
210
|
* A binding to an element attribute (e.g. `[attr.name]="expression"`).
|
211
|
*/
|
212
|
Attribute = 1,
|
213
|
/**
|
214
|
* A binding to a CSS class (e.g. `[class.name]="condition"`).
|
215
|
*/
|
216
|
Class = 2,
|
217
|
/**
|
218
|
* A binding to a style rule (e.g. `[style.rule]="expression"`).
|
219
|
*/
|
220
|
Style = 3,
|
221
|
/**
|
222
|
* A binding to an animation reference (e.g. `[animate.key]="expression"`).
|
223
|
*/
|
224
|
Animation = 4,
|
225
|
}
|
226
|
export interface QueryMatch {
|
227
|
queryId: number;
|
228
|
value: CompileTokenMetadata;
|
229
|
}
|
230
|
/**
|
231
|
* A visitor for {@link TemplateAst} trees that will process each node.
|
232
|
*/
|
233
|
export interface TemplateAstVisitor {
|
234
|
visit?(ast: TemplateAst, context: any): any;
|
235
|
visitNgContent(ast: NgContentAst, context: any): any;
|
236
|
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
|
237
|
visitElement(ast: ElementAst, context: any): any;
|
238
|
visitReference(ast: ReferenceAst, context: any): any;
|
239
|
visitVariable(ast: VariableAst, context: any): any;
|
240
|
visitEvent(ast: BoundEventAst, context: any): any;
|
241
|
visitElementProperty(ast: BoundElementPropertyAst, context: any): any;
|
242
|
visitAttr(ast: AttrAst, context: any): any;
|
243
|
visitBoundText(ast: BoundTextAst, context: any): any;
|
244
|
visitText(ast: TextAst, context: any): any;
|
245
|
visitDirective(ast: DirectiveAst, context: any): any;
|
246
|
visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any;
|
247
|
}
|
248
|
/**
|
249
|
* A visitor that accepts each node but doesn't do anything. It is intended to be used
|
250
|
* as the base class for a visitor that is only interested in a subset of the node types.
|
251
|
*/
|
252
|
export declare class NullTemplateVisitor implements TemplateAstVisitor {
|
253
|
visitNgContent(ast: NgContentAst, context: any): void;
|
254
|
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): void;
|
255
|
visitElement(ast: ElementAst, context: any): void;
|
256
|
visitReference(ast: ReferenceAst, context: any): void;
|
257
|
visitVariable(ast: VariableAst, context: any): void;
|
258
|
visitEvent(ast: BoundEventAst, context: any): void;
|
259
|
visitElementProperty(ast: BoundElementPropertyAst, context: any): void;
|
260
|
visitAttr(ast: AttrAst, context: any): void;
|
261
|
visitBoundText(ast: BoundTextAst, context: any): void;
|
262
|
visitText(ast: TextAst, context: any): void;
|
263
|
visitDirective(ast: DirectiveAst, context: any): void;
|
264
|
visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): void;
|
265
|
}
|
266
|
/**
|
267
|
* Base class that can be used to build a visitor that visits each node
|
268
|
* in an template ast recursively.
|
269
|
*/
|
270
|
export declare class RecursiveTemplateAstVisitor extends NullTemplateVisitor implements TemplateAstVisitor {
|
271
|
constructor();
|
272
|
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
|
273
|
visitElement(ast: ElementAst, context: any): any;
|
274
|
visitDirective(ast: DirectiveAst, context: any): any;
|
275
|
protected visitChildren<T extends TemplateAst>(context: any, cb: (visit: (<V extends TemplateAst>(children: V[] | undefined) => void)) => void): any;
|
276
|
}
|
277
|
/**
|
278
|
* Visit every node in a list of {@link TemplateAst}s with the given {@link TemplateAstVisitor}.
|
279
|
*/
|
280
|
export declare function templateVisitAll(visitor: TemplateAstVisitor, asts: TemplateAst[], context?: any): any[];
|
281
|
export declare type TemplateAstPath = AstPath<TemplateAst>;
|