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 { Injector } from '../di';
|
9
|
import { ErrorHandler } from '../error_handler';
|
10
|
import { NgModuleRef } from '../linker/ng_module_factory';
|
11
|
import { QueryList } from '../linker/query_list';
|
12
|
import { TemplateRef } from '../linker/template_ref';
|
13
|
import { ViewContainerRef } from '../linker/view_container_ref';
|
14
|
import { Renderer2, RendererFactory2, RendererType2 } from '../render/api';
|
15
|
import { Sanitizer, SecurityContext } from '../security';
|
16
|
import { Type } from '../type';
|
17
|
/**
|
18
|
* Factory for ViewDefinitions/NgModuleDefinitions.
|
19
|
* We use a function so we can reexeute it in case an error happens and use the given logger
|
20
|
* function to log the error from the definition of the node, which is shown in all browser
|
21
|
* logs.
|
22
|
*/
|
23
|
export interface DefinitionFactory<D extends Definition<any>> {
|
24
|
(logger: NodeLogger): D;
|
25
|
}
|
26
|
/**
|
27
|
* Function to call console.error at the right source location. This is an indirection
|
28
|
* via another function as browser will log the location that actually called
|
29
|
* `console.error`.
|
30
|
*/
|
31
|
export interface NodeLogger {
|
32
|
(): () => void;
|
33
|
}
|
34
|
export interface Definition<DF extends DefinitionFactory<any>> {
|
35
|
factory: DF | null;
|
36
|
}
|
37
|
export interface NgModuleDefinition extends Definition<NgModuleDefinitionFactory> {
|
38
|
providers: NgModuleProviderDef[];
|
39
|
providersByKey: {
|
40
|
[tokenKey: string]: NgModuleProviderDef;
|
41
|
};
|
42
|
}
|
43
|
export interface NgModuleDefinitionFactory extends DefinitionFactory<NgModuleDefinition> {
|
44
|
}
|
45
|
export interface ViewDefinition extends Definition<ViewDefinitionFactory> {
|
46
|
flags: ViewFlags;
|
47
|
updateDirectives: ViewUpdateFn;
|
48
|
updateRenderer: ViewUpdateFn;
|
49
|
handleEvent: ViewHandleEventFn;
|
50
|
/**
|
51
|
* Order: Depth first.
|
52
|
* Especially providers are before elements / anchors.
|
53
|
*/
|
54
|
nodes: NodeDef[];
|
55
|
/** aggregated NodeFlags for all nodes **/
|
56
|
nodeFlags: NodeFlags;
|
57
|
rootNodeFlags: NodeFlags;
|
58
|
lastRenderRootNode: NodeDef | null;
|
59
|
bindingCount: number;
|
60
|
outputCount: number;
|
61
|
/**
|
62
|
* Binary or of all query ids that are matched by one of the nodes.
|
63
|
* This includes query ids from templates as well.
|
64
|
* Used as a bloom filter.
|
65
|
*/
|
66
|
nodeMatchedQueries: number;
|
67
|
}
|
68
|
export interface ViewDefinitionFactory extends DefinitionFactory<ViewDefinition> {
|
69
|
}
|
70
|
export interface ViewUpdateFn {
|
71
|
(check: NodeCheckFn, view: ViewData): void;
|
72
|
}
|
73
|
export interface NodeCheckFn {
|
74
|
(view: ViewData, nodeIndex: number, argStyle: ArgumentType.Dynamic, values: any[]): any;
|
75
|
(view: ViewData, nodeIndex: number, argStyle: ArgumentType.Inline, v0?: any, v1?: any, v2?: any, v3?: any, v4?: any, v5?: any, v6?: any, v7?: any, v8?: any, v9?: any): any;
|
76
|
}
|
77
|
export declare const enum ArgumentType {
|
78
|
Inline = 0,
|
79
|
Dynamic = 1,
|
80
|
}
|
81
|
export interface ViewHandleEventFn {
|
82
|
(view: ViewData, nodeIndex: number, eventName: string, event: any): boolean;
|
83
|
}
|
84
|
/**
|
85
|
* Bitmask for ViewDefinition.flags.
|
86
|
*/
|
87
|
export declare const enum ViewFlags {
|
88
|
None = 0,
|
89
|
OnPush = 2,
|
90
|
}
|
91
|
/**
|
92
|
* A node definition in the view.
|
93
|
*
|
94
|
* Note: We use one type for all nodes so that loops that loop over all nodes
|
95
|
* of a ViewDefinition stay monomorphic!
|
96
|
*/
|
97
|
export interface NodeDef {
|
98
|
flags: NodeFlags;
|
99
|
nodeIndex: number;
|
100
|
checkIndex: number;
|
101
|
parent: NodeDef | null;
|
102
|
renderParent: NodeDef | null;
|
103
|
/** this is checked against NgContentDef.index to find matched nodes */
|
104
|
ngContentIndex: number | null;
|
105
|
/** number of transitive children */
|
106
|
childCount: number;
|
107
|
/** aggregated NodeFlags for all transitive children (does not include self) **/
|
108
|
childFlags: NodeFlags;
|
109
|
/** aggregated NodeFlags for all direct children (does not include self) **/
|
110
|
directChildFlags: NodeFlags;
|
111
|
bindingIndex: number;
|
112
|
bindings: BindingDef[];
|
113
|
bindingFlags: BindingFlags;
|
114
|
outputIndex: number;
|
115
|
outputs: OutputDef[];
|
116
|
/**
|
117
|
* references that the user placed on the element
|
118
|
*/
|
119
|
references: {
|
120
|
[refId: string]: QueryValueType;
|
121
|
};
|
122
|
/**
|
123
|
* ids and value types of all queries that are matched by this node.
|
124
|
*/
|
125
|
matchedQueries: {
|
126
|
[queryId: number]: QueryValueType;
|
127
|
};
|
128
|
/** Binary or of all matched query ids of this node. */
|
129
|
matchedQueryIds: number;
|
130
|
/**
|
131
|
* Binary or of all query ids that are matched by one of the children.
|
132
|
* This includes query ids from templates as well.
|
133
|
* Used as a bloom filter.
|
134
|
*/
|
135
|
childMatchedQueries: number;
|
136
|
element: ElementDef | null;
|
137
|
provider: ProviderDef | null;
|
138
|
text: TextDef | null;
|
139
|
query: QueryDef | null;
|
140
|
ngContent: NgContentDef | null;
|
141
|
}
|
142
|
/**
|
143
|
* Bitmask for NodeDef.flags.
|
144
|
* Naming convention:
|
145
|
* - `Type...`: flags that are mutually exclusive
|
146
|
* - `Cat...`: union of multiple `Type...` (short for category).
|
147
|
*/
|
148
|
export declare const enum NodeFlags {
|
149
|
None = 0,
|
150
|
TypeElement = 1,
|
151
|
TypeText = 2,
|
152
|
ProjectedTemplate = 4,
|
153
|
CatRenderNode = 3,
|
154
|
TypeNgContent = 8,
|
155
|
TypePipe = 16,
|
156
|
TypePureArray = 32,
|
157
|
TypePureObject = 64,
|
158
|
TypePurePipe = 128,
|
159
|
CatPureExpression = 224,
|
160
|
TypeValueProvider = 256,
|
161
|
TypeClassProvider = 512,
|
162
|
TypeFactoryProvider = 1024,
|
163
|
TypeUseExistingProvider = 2048,
|
164
|
LazyProvider = 4096,
|
165
|
PrivateProvider = 8192,
|
166
|
TypeDirective = 16384,
|
167
|
Component = 32768,
|
168
|
CatProviderNoDirective = 3840,
|
169
|
CatProvider = 20224,
|
170
|
OnInit = 65536,
|
171
|
OnDestroy = 131072,
|
172
|
DoCheck = 262144,
|
173
|
OnChanges = 524288,
|
174
|
AfterContentInit = 1048576,
|
175
|
AfterContentChecked = 2097152,
|
176
|
AfterViewInit = 4194304,
|
177
|
AfterViewChecked = 8388608,
|
178
|
EmbeddedViews = 16777216,
|
179
|
ComponentView = 33554432,
|
180
|
TypeContentQuery = 67108864,
|
181
|
TypeViewQuery = 134217728,
|
182
|
StaticQuery = 268435456,
|
183
|
DynamicQuery = 536870912,
|
184
|
CatQuery = 201326592,
|
185
|
Types = 201347067,
|
186
|
}
|
187
|
export interface BindingDef {
|
188
|
flags: BindingFlags;
|
189
|
ns: string | null;
|
190
|
name: string | null;
|
191
|
nonMinifiedName: string | null;
|
192
|
securityContext: SecurityContext | null;
|
193
|
suffix: string | null;
|
194
|
}
|
195
|
export declare const enum BindingFlags {
|
196
|
TypeElementAttribute = 1,
|
197
|
TypeElementClass = 2,
|
198
|
TypeElementStyle = 4,
|
199
|
TypeProperty = 8,
|
200
|
SyntheticProperty = 16,
|
201
|
SyntheticHostProperty = 32,
|
202
|
CatSyntheticProperty = 48,
|
203
|
Types = 15,
|
204
|
}
|
205
|
export interface OutputDef {
|
206
|
type: OutputType;
|
207
|
target: 'window' | 'document' | 'body' | 'component' | null;
|
208
|
eventName: string;
|
209
|
propName: string | null;
|
210
|
}
|
211
|
export declare const enum OutputType {
|
212
|
ElementOutput = 0,
|
213
|
DirectiveOutput = 1,
|
214
|
}
|
215
|
export declare const enum QueryValueType {
|
216
|
ElementRef = 0,
|
217
|
RenderElement = 1,
|
218
|
TemplateRef = 2,
|
219
|
ViewContainerRef = 3,
|
220
|
Provider = 4,
|
221
|
}
|
222
|
export interface ElementDef {
|
223
|
name: string | null;
|
224
|
ns: string | null;
|
225
|
/** ns, name, value */
|
226
|
attrs: [string, string, string][] | null;
|
227
|
template: ViewDefinition | null;
|
228
|
componentProvider: NodeDef | null;
|
229
|
componentRendererType: RendererType2 | null;
|
230
|
componentView: ViewDefinitionFactory | null;
|
231
|
/**
|
232
|
* visible public providers for DI in the view,
|
233
|
* as see from this element. This does not include private providers.
|
234
|
*/
|
235
|
publicProviders: {
|
236
|
[tokenKey: string]: NodeDef;
|
237
|
} | null;
|
238
|
/**
|
239
|
* same as visiblePublicProviders, but also includes private providers
|
240
|
* that are located on this element.
|
241
|
*/
|
242
|
allProviders: {
|
243
|
[tokenKey: string]: NodeDef;
|
244
|
} | null;
|
245
|
handleEvent: ElementHandleEventFn | null;
|
246
|
}
|
247
|
export interface ElementHandleEventFn {
|
248
|
(view: ViewData, eventName: string, event: any): boolean;
|
249
|
}
|
250
|
export interface ProviderDef {
|
251
|
token: any;
|
252
|
value: any;
|
253
|
deps: DepDef[];
|
254
|
}
|
255
|
export interface NgModuleProviderDef {
|
256
|
flags: NodeFlags;
|
257
|
index: number;
|
258
|
token: any;
|
259
|
value: any;
|
260
|
deps: DepDef[];
|
261
|
}
|
262
|
export interface DepDef {
|
263
|
flags: DepFlags;
|
264
|
token: any;
|
265
|
tokenKey: string;
|
266
|
}
|
267
|
/**
|
268
|
* Bitmask for DI flags
|
269
|
*/
|
270
|
export declare const enum DepFlags {
|
271
|
None = 0,
|
272
|
SkipSelf = 1,
|
273
|
Optional = 2,
|
274
|
Value = 8,
|
275
|
}
|
276
|
export interface TextDef {
|
277
|
prefix: string;
|
278
|
}
|
279
|
export interface QueryDef {
|
280
|
id: number;
|
281
|
filterId: number;
|
282
|
bindings: QueryBindingDef[];
|
283
|
}
|
284
|
export interface QueryBindingDef {
|
285
|
propName: string;
|
286
|
bindingType: QueryBindingType;
|
287
|
}
|
288
|
export declare const enum QueryBindingType {
|
289
|
First = 0,
|
290
|
All = 1,
|
291
|
}
|
292
|
export interface NgContentDef {
|
293
|
/**
|
294
|
* this index is checked against NodeDef.ngContentIndex to find the nodes
|
295
|
* that are matched by this ng-content.
|
296
|
* Note that a NodeDef with an ng-content can be reprojected, i.e.
|
297
|
* have a ngContentIndex on its own.
|
298
|
*/
|
299
|
index: number;
|
300
|
}
|
301
|
export interface NgModuleData extends Injector, NgModuleRef<any> {
|
302
|
_def: NgModuleDefinition;
|
303
|
_parent: Injector;
|
304
|
_providers: any[];
|
305
|
}
|
306
|
/**
|
307
|
* View instance data.
|
308
|
* Attention: Adding fields to this is performance sensitive!
|
309
|
*/
|
310
|
export interface ViewData {
|
311
|
def: ViewDefinition;
|
312
|
root: RootData;
|
313
|
renderer: Renderer2;
|
314
|
parentNodeDef: NodeDef | null;
|
315
|
parent: ViewData | null;
|
316
|
viewContainerParent: ViewData | null;
|
317
|
component: any;
|
318
|
context: any;
|
319
|
nodes: {
|
320
|
[key: number]: NodeData;
|
321
|
};
|
322
|
state: ViewState;
|
323
|
oldValues: any[];
|
324
|
disposables: DisposableFn[] | null;
|
325
|
}
|
326
|
/**
|
327
|
* Bitmask of states
|
328
|
*/
|
329
|
export declare const enum ViewState {
|
330
|
BeforeFirstCheck = 1,
|
331
|
FirstCheck = 2,
|
332
|
Attached = 4,
|
333
|
ChecksEnabled = 8,
|
334
|
IsProjectedView = 16,
|
335
|
CheckProjectedView = 32,
|
336
|
CheckProjectedViews = 64,
|
337
|
Destroyed = 128,
|
338
|
CatDetectChanges = 12,
|
339
|
CatInit = 13,
|
340
|
}
|
341
|
export interface DisposableFn {
|
342
|
(): void;
|
343
|
}
|
344
|
/**
|
345
|
* Node instance data.
|
346
|
*
|
347
|
* We have a separate type per NodeType to save memory
|
348
|
* (TextData | ElementData | ProviderData | PureExpressionData | QueryList<any>)
|
349
|
*
|
350
|
* To keep our code monomorphic,
|
351
|
* we prohibit using `NodeData` directly but enforce the use of accessors (`asElementData`, ...).
|
352
|
* This way, no usage site can get a `NodeData` from view.nodes and then use it for different
|
353
|
* purposes.
|
354
|
*/
|
355
|
export declare class NodeData {
|
356
|
private __brand;
|
357
|
}
|
358
|
/**
|
359
|
* Data for an instantiated NodeType.Text.
|
360
|
*
|
361
|
* Attention: Adding fields to this is performance sensitive!
|
362
|
*/
|
363
|
export interface TextData {
|
364
|
renderText: any;
|
365
|
}
|
366
|
/**
|
367
|
* Accessor for view.nodes, enforcing that every usage site stays monomorphic.
|
368
|
*/
|
369
|
export declare function asTextData(view: ViewData, index: number): TextData;
|
370
|
/**
|
371
|
* Data for an instantiated NodeType.Element.
|
372
|
*
|
373
|
* Attention: Adding fields to this is performance sensitive!
|
374
|
*/
|
375
|
export interface ElementData {
|
376
|
renderElement: any;
|
377
|
componentView: ViewData;
|
378
|
viewContainer: ViewContainerData | null;
|
379
|
template: TemplateData;
|
380
|
}
|
381
|
export interface ViewContainerData extends ViewContainerRef {
|
382
|
_embeddedViews: ViewData[];
|
383
|
}
|
384
|
export interface TemplateData extends TemplateRef<any> {
|
385
|
_projectedViews: ViewData[];
|
386
|
}
|
387
|
/**
|
388
|
* Accessor for view.nodes, enforcing that every usage site stays monomorphic.
|
389
|
*/
|
390
|
export declare function asElementData(view: ViewData, index: number): ElementData;
|
391
|
/**
|
392
|
* Data for an instantiated NodeType.Provider.
|
393
|
*
|
394
|
* Attention: Adding fields to this is performance sensitive!
|
395
|
*/
|
396
|
export interface ProviderData {
|
397
|
instance: any;
|
398
|
}
|
399
|
/**
|
400
|
* Accessor for view.nodes, enforcing that every usage site stays monomorphic.
|
401
|
*/
|
402
|
export declare function asProviderData(view: ViewData, index: number): ProviderData;
|
403
|
/**
|
404
|
* Data for an instantiated NodeType.PureExpression.
|
405
|
*
|
406
|
* Attention: Adding fields to this is performance sensitive!
|
407
|
*/
|
408
|
export interface PureExpressionData {
|
409
|
value: any;
|
410
|
}
|
411
|
/**
|
412
|
* Accessor for view.nodes, enforcing that every usage site stays monomorphic.
|
413
|
*/
|
414
|
export declare function asPureExpressionData(view: ViewData, index: number): PureExpressionData;
|
415
|
/**
|
416
|
* Accessor for view.nodes, enforcing that every usage site stays monomorphic.
|
417
|
*/
|
418
|
export declare function asQueryList(view: ViewData, index: number): QueryList<any>;
|
419
|
export interface RootData {
|
420
|
injector: Injector;
|
421
|
ngModule: NgModuleRef<any>;
|
422
|
projectableNodes: any[][];
|
423
|
selectorOrNode: any;
|
424
|
renderer: Renderer2;
|
425
|
rendererFactory: RendererFactory2;
|
426
|
errorHandler: ErrorHandler;
|
427
|
sanitizer: Sanitizer;
|
428
|
}
|
429
|
export declare abstract class DebugContext {
|
430
|
readonly abstract view: ViewData;
|
431
|
readonly abstract nodeIndex: number | null;
|
432
|
readonly abstract injector: Injector;
|
433
|
readonly abstract component: any;
|
434
|
readonly abstract providerTokens: any[];
|
435
|
readonly abstract references: {
|
436
|
[key: string]: any;
|
437
|
};
|
438
|
readonly abstract context: any;
|
439
|
readonly abstract componentRenderElement: any;
|
440
|
readonly abstract renderNode: any;
|
441
|
abstract logError(console: Console, ...values: any[]): void;
|
442
|
}
|
443
|
export declare const enum CheckType {
|
444
|
CheckAndUpdate = 0,
|
445
|
CheckNoChanges = 1,
|
446
|
}
|
447
|
export interface ProviderOverride {
|
448
|
token: any;
|
449
|
flags: NodeFlags;
|
450
|
value: any;
|
451
|
deps: ([DepFlags, any] | any)[];
|
452
|
deprecatedBehavior: boolean;
|
453
|
}
|
454
|
export interface Services {
|
455
|
setCurrentNode(view: ViewData, nodeIndex: number): void;
|
456
|
createRootView(injector: Injector, projectableNodes: any[][], rootSelectorOrNode: string | any, def: ViewDefinition, ngModule: NgModuleRef<any>, context?: any): ViewData;
|
457
|
createEmbeddedView(parent: ViewData, anchorDef: NodeDef, viewDef: ViewDefinition, context?: any): ViewData;
|
458
|
createComponentView(parentView: ViewData, nodeDef: NodeDef, viewDef: ViewDefinition, hostElement: any): ViewData;
|
459
|
createNgModuleRef(moduleType: Type<any>, parent: Injector, bootstrapComponents: Type<any>[], def: NgModuleDefinition): NgModuleRef<any>;
|
460
|
overrideProvider(override: ProviderOverride): void;
|
461
|
clearProviderOverrides(): void;
|
462
|
checkAndUpdateView(view: ViewData): void;
|
463
|
checkNoChangesView(view: ViewData): void;
|
464
|
destroyView(view: ViewData): void;
|
465
|
resolveDep(view: ViewData, elDef: NodeDef | null, allowPrivateServices: boolean, depDef: DepDef, notFoundValue?: any): any;
|
466
|
createDebugContext(view: ViewData, nodeIndex: number): DebugContext;
|
467
|
handleEvent: ViewHandleEventFn;
|
468
|
updateDirectives: (view: ViewData, checkType: CheckType) => void;
|
469
|
updateRenderer: (view: ViewData, checkType: CheckType) => void;
|
470
|
dirtyParentQueries: (view: ViewData) => void;
|
471
|
}
|
472
|
/**
|
473
|
* This object is used to prevent cycles in the source files and to have a place where
|
474
|
* debug mode can hook it. It is lazily filled when `isDevMode` is known.
|
475
|
*/
|
476
|
export declare const Services: Services;
|