@@ -150,23 +150,10 @@ function isAngularCoreImport(node: ts.ImportDeclaration, isAngularCoreFile: bool
150
150
151
151
// Check if assignment is `Clazz.decorators = [...];`.
152
152
function isDecoratorAssignmentExpression ( exprStmt : ts . ExpressionStatement ) : boolean {
153
- if ( exprStmt . expression . kind !== ts . SyntaxKind . BinaryExpression ) {
153
+ if ( ! isAssignmentExpressionTo ( exprStmt , 'decorators' ) ) {
154
154
return false ;
155
155
}
156
156
const expr = exprStmt . expression as ts . BinaryExpression ;
157
- if ( expr . left . kind !== ts . SyntaxKind . PropertyAccessExpression ) {
158
- return false ;
159
- }
160
- const propAccess = expr . left as ts . PropertyAccessExpression ;
161
- if ( propAccess . expression . kind !== ts . SyntaxKind . Identifier ) {
162
- return false ;
163
- }
164
- if ( propAccess . name . text !== 'decorators' ) {
165
- return false ;
166
- }
167
- if ( expr . operatorToken . kind !== ts . SyntaxKind . FirstAssignment ) {
168
- return false ;
169
- }
170
157
if ( expr . right . kind !== ts . SyntaxKind . ArrayLiteralExpression ) {
171
158
return false ;
172
159
}
@@ -275,32 +262,33 @@ function isAngularDecoratorMetadataExpression(
275
262
276
263
// Check if assignment is `Clazz.propDecorators = [...];`.
277
264
function isPropDecoratorAssignmentExpression ( exprStmt : ts . ExpressionStatement ) : boolean {
278
- if ( exprStmt . expression . kind !== ts . SyntaxKind . BinaryExpression ) {
265
+ if ( ! isAssignmentExpressionTo ( exprStmt , 'propDecorators' ) ) {
279
266
return false ;
280
267
}
281
268
const expr = exprStmt . expression as ts . BinaryExpression ;
282
- if ( expr . left . kind !== ts . SyntaxKind . PropertyAccessExpression ) {
283
- return false ;
284
- }
285
- const propAccess = expr . left as ts . PropertyAccessExpression ;
286
- if ( propAccess . expression . kind !== ts . SyntaxKind . Identifier ) {
287
- return false ;
288
- }
289
- if ( propAccess . name . text !== 'propDecorators' ) {
269
+ if ( expr . right . kind !== ts . SyntaxKind . ObjectLiteralExpression ) {
290
270
return false ;
291
271
}
292
- if ( expr . operatorToken . kind !== ts . SyntaxKind . FirstAssignment ) {
272
+
273
+ return true ;
274
+ }
275
+
276
+ // Check if assignment is `Clazz.ctorParameters = [...];`.
277
+ function isCtorParamsAssignmentExpression ( exprStmt : ts . ExpressionStatement ) : boolean {
278
+ if ( ! isAssignmentExpressionTo ( exprStmt , 'ctorParameters' ) ) {
293
279
return false ;
294
280
}
295
- if ( expr . right . kind !== ts . SyntaxKind . ObjectLiteralExpression ) {
281
+ const expr = exprStmt . expression as ts . BinaryExpression ;
282
+ if ( expr . right . kind !== ts . SyntaxKind . FunctionExpression
283
+ && expr . right . kind !== ts . SyntaxKind . ArrowFunction
284
+ ) {
296
285
return false ;
297
286
}
298
287
299
288
return true ;
300
289
}
301
290
302
- // Check if assignment is `Clazz.ctorParameters = [...];`.
303
- function isCtorParamsAssignmentExpression ( exprStmt : ts . ExpressionStatement ) : boolean {
291
+ function isAssignmentExpressionTo ( exprStmt : ts . ExpressionStatement , name : string ) {
304
292
if ( exprStmt . expression . kind !== ts . SyntaxKind . BinaryExpression ) {
305
293
return false ;
306
294
}
@@ -309,7 +297,7 @@ function isCtorParamsAssignmentExpression(exprStmt: ts.ExpressionStatement): boo
309
297
return false ;
310
298
}
311
299
const propAccess = expr . left as ts . PropertyAccessExpression ;
312
- if ( propAccess . name . text !== 'ctorParameters' ) {
300
+ if ( propAccess . name . text !== name ) {
313
301
return false ;
314
302
}
315
303
if ( propAccess . expression . kind !== ts . SyntaxKind . Identifier ) {
@@ -318,11 +306,6 @@ function isCtorParamsAssignmentExpression(exprStmt: ts.ExpressionStatement): boo
318
306
if ( expr . operatorToken . kind !== ts . SyntaxKind . FirstAssignment ) {
319
307
return false ;
320
308
}
321
- if ( expr . right . kind !== ts . SyntaxKind . FunctionExpression
322
- && expr . right . kind !== ts . SyntaxKind . ArrowFunction
323
- ) {
324
- return false ;
325
- }
326
309
327
310
return true ;
328
311
}
0 commit comments