forked from angular/angular
/
api.ts
177 lines (151 loc) · 5.13 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {DirectiveMeta as T2DirectiveMeta, SchemaMetadata} from '@angular/compiler';
import * as ts from 'typescript';
import {Reference} from '../../imports';
import {ClassDeclaration} from '../../reflection';
import {ClassPropertyMapping, ClassPropertyName} from './property_mapping';
/**
* Metadata collected for an `NgModule`.
*/
export interface NgModuleMeta {
ref: Reference<ClassDeclaration>;
declarations: Reference<ClassDeclaration>[];
imports: Reference<ClassDeclaration>[];
exports: Reference<ClassDeclaration>[];
schemas: SchemaMetadata[];
/**
* The raw `ts.Expression` which gave rise to `declarations`, if one exists.
*
* If this is `null`, then either no declarations exist, or no expression was available (likely
* because the module came from a .d.ts file).
*/
rawDeclarations: ts.Expression|null;
}
/**
* Typing metadata collected for a directive within an NgModule's scope.
*/
export interface DirectiveTypeCheckMeta {
/**
* List of static `ngTemplateGuard_xx` members found on the Directive's class.
* @see `TemplateGuardMeta`
*/
ngTemplateGuards: TemplateGuardMeta[];
/**
* Whether the Directive's class has a static ngTemplateContextGuard function.
*/
hasNgTemplateContextGuard: boolean;
/**
* The set of input fields which have a corresponding static `ngAcceptInputType_` on the
* Directive's class. This allows inputs to accept a wider range of types and coerce the input to
* a narrower type with a getter/setter. See https://angular.io/guide/template-typecheck.
*/
coercedInputFields: Set<ClassPropertyName>;
/**
* The set of input fields which map to `readonly`, `private`, or `protected` members in the
* Directive's class.
*/
restrictedInputFields: Set<ClassPropertyName>;
/**
* The set of input fields which are declared as string literal members in the Directive's class.
* We need to track these separately because these fields may not be valid JS identifiers so
* we cannot use them with property access expressions when assigning inputs.
*/
stringLiteralInputFields: Set<ClassPropertyName>;
/**
* The set of input fields which do not have corresponding members in the Directive's class.
*/
undeclaredInputFields: Set<ClassPropertyName>;
/**
* Whether the Directive's class is generic, i.e. `class MyDir<T> {...}`.
*/
isGeneric: boolean;
}
export enum MetaType {
Pipe,
Directive,
}
/**
* Metadata collected for a directive within an NgModule's scope.
*/
export interface DirectiveMeta extends T2DirectiveMeta, DirectiveTypeCheckMeta {
type: MetaType.Directive;
ref: Reference<ClassDeclaration>;
/**
* Unparsed selector of the directive, or null if the directive does not have a selector.
*/
selector: string|null;
queries: string[];
/**
* A mapping of input field names to the property names.
*/
inputs: ClassPropertyMapping;
/**
* A mapping of output field names to the property names.
*/
outputs: ClassPropertyMapping;
/**
* A `Reference` to the base class for the directive, if one was detected.
*
* A value of `'dynamic'` indicates that while the analyzer detected that this directive extends
* another type, it could not statically determine the base class.
*/
baseClass: Reference<ClassDeclaration>|'dynamic'|null;
/**
* Whether the directive had some issue with its declaration that means it might not have complete
* and reliable metadata.
*/
isPoisoned: boolean;
/**
* Whether the directive is likely a structural directive (injects `TemplateRef`).
*/
isStructural: boolean;
}
/**
* Metadata that describes a template guard for one of the directive's inputs.
*/
export interface TemplateGuardMeta {
/**
* The input name that this guard should be applied to.
*/
inputName: string;
/**
* Represents the type of the template guard.
*
* - 'invocation' means that a call to the template guard function is emitted so that its return
* type can result in narrowing of the input type.
* - 'binding' means that the input binding expression itself is used as template guard.
*/
type: 'invocation'|'binding';
}
/**
* Metadata for a pipe within an NgModule's scope.
*/
export interface PipeMeta {
type: MetaType.Pipe;
ref: Reference<ClassDeclaration>;
name: string;
nameExpr: ts.Expression|null;
}
/**
* Reads metadata for directives, pipes, and modules from a particular source, such as .d.ts files
* or a registry.
*/
export interface MetadataReader {
getDirectiveMetadata(node: Reference<ClassDeclaration>): DirectiveMeta|null;
getNgModuleMetadata(node: Reference<ClassDeclaration>): NgModuleMeta|null;
getPipeMetadata(node: Reference<ClassDeclaration>): PipeMeta|null;
}
/**
* Registers new metadata for directives, pipes, and modules.
*/
export interface MetadataRegistry {
registerDirectiveMetadata(meta: DirectiveMeta): void;
registerNgModuleMetadata(meta: NgModuleMeta): void;
registerPipeMetadata(meta: PipeMeta): void;
}