@@ -121,6 +121,17 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
121
121
if ( isPresent ( ( < any > typeOrFunc ) . parameters ) ) {
122
122
return ( < any > typeOrFunc ) . parameters ;
123
123
}
124
+
125
+ // API of tsickle for lowering decorators to properties on the class.
126
+ if ( isPresent ( ( < any > typeOrFunc ) . ctorParameters ) ) {
127
+ let ctorParameters = ( < any > typeOrFunc ) . ctorParameters ;
128
+ let paramTypes = ctorParameters . map ( ctorParam => ctorParam && ctorParam . type ) ;
129
+ let paramAnnotations = ctorParameters . map ( ctorParam =>
130
+ ctorParam && convertTsickleDecoratorIntoMetadata ( ctorParam . decorators ) ) ;
131
+ return this . _zipTypesAndAnnotations ( paramTypes , paramAnnotations ) ;
132
+ }
133
+
134
+ // API for metadata created by invoking the decorators.
124
135
if ( isPresent ( this . _reflect ) && isPresent ( this . _reflect . getMetadata ) ) {
125
136
var paramAnnotations = this . _reflect . getMetadata ( 'parameters' , typeOrFunc ) ;
126
137
var paramTypes = this . _reflect . getMetadata ( 'design:paramtypes' , typeOrFunc ) ;
@@ -143,6 +154,13 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
143
154
}
144
155
return annotations ;
145
156
}
157
+
158
+ // API of tsickle for lowering decorators to properties on the class.
159
+ if ( isPresent ( ( < any > typeOrFunc ) . decorators ) ) {
160
+ return convertTsickleDecoratorIntoMetadata ( ( < any > typeOrFunc ) . decorators ) ;
161
+ }
162
+
163
+ // API for metadata created by invoking the decorators.
146
164
if ( isPresent ( this . _reflect ) && isPresent ( this . _reflect . getMetadata ) ) {
147
165
var annotations = this . _reflect . getMetadata ( 'annotations' , typeOrFunc ) ;
148
166
if ( isPresent ( annotations ) ) return annotations ;
@@ -159,6 +177,18 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
159
177
}
160
178
return propMetadata ;
161
179
}
180
+
181
+ // API of tsickle for lowering decorators to properties on the class.
182
+ if ( isPresent ( ( < any > typeOrFunc ) . propDecorators ) ) {
183
+ let propDecorators = ( < any > typeOrFunc ) . propDecorators ;
184
+ let propMetadata = < { [ key : string ] : any [ ] } > { } ;
185
+ Object . keys ( propDecorators ) . forEach ( prop => {
186
+ propMetadata [ prop ] = convertTsickleDecoratorIntoMetadata ( propDecorators [ prop ] ) ;
187
+ } ) ;
188
+ return propMetadata ;
189
+ }
190
+
191
+ // API for metadata created by invoking the decorators.
162
192
if ( isPresent ( this . _reflect ) && isPresent ( this . _reflect . getMetadata ) ) {
163
193
var propMetadata = this . _reflect . getMetadata ( 'propMetadata' , typeOrFunc ) ;
164
194
if ( isPresent ( propMetadata ) ) return propMetadata ;
@@ -185,3 +215,17 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
185
215
// There is not a concept of import uri in Js, but this is useful in developing Dart applications.
186
216
importUri ( type : Type ) : string { return `./${ stringify ( type ) } ` ; }
187
217
}
218
+
219
+ function convertTsickleDecoratorIntoMetadata ( decoratorInvocations : any [ ] ) : any [ ] {
220
+ if ( ! decoratorInvocations ) {
221
+ return [ ] ;
222
+ }
223
+ return decoratorInvocations . map ( decoratorInvocation => {
224
+ var decoratorType = decoratorInvocation . type ;
225
+ var annotationCls = decoratorType . annotationCls ;
226
+ var annotationArgs = decoratorInvocation . args ? decoratorInvocation . args : [ ] ;
227
+ var annotation = Object . create ( annotationCls . prototype ) ;
228
+ annotationCls . apply ( annotation , annotationArgs ) ;
229
+ return annotation ;
230
+ } ) ;
231
+ }
0 commit comments