@@ -58,11 +58,9 @@ function scrubFileTransformer(checker: ts.TypeChecker, isAngularCoreFile: boolea
58
58
nodes . push ( node ) ;
59
59
} else if ( isDecoratorAssignmentExpression ( exprStmt ) ) {
60
60
nodes . push ( ...pickDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
61
- } else if ( isDecorateAssignmentExpression ( exprStmt , tslibImports , checker ) ) {
61
+ } else if ( isDecorateAssignmentExpression ( exprStmt , tslibImports , checker )
62
+ || isAngularDecoratorExpression ( exprStmt , ngMetadata , tslibImports , checker ) ) {
62
63
nodes . push ( ...pickDecorateNodesToRemove ( exprStmt , tslibImports , ngMetadata , checker ) ) ;
63
- } else if ( isAngularDecoratorMetadataExpression ( exprStmt ,
64
- ngMetadata , tslibImports , checker ) ) {
65
- nodes . push ( node ) ;
66
64
} else if ( isPropDecoratorAssignmentExpression ( exprStmt ) ) {
67
65
nodes . push ( ...pickPropDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
68
66
}
@@ -218,7 +216,7 @@ function isDecorateAssignmentExpression(
218
216
}
219
217
220
218
// Check if expression is `__decorate([smt, __metadata("design:type", Object)], ...)`.
221
- function isAngularDecoratorMetadataExpression (
219
+ function isAngularDecoratorExpression (
222
220
exprStmt : ts . ExpressionStatement ,
223
221
ngMetadata : ts . Node [ ] ,
224
222
tslibImports : ts . NamespaceImport [ ] ,
@@ -240,27 +238,19 @@ function isAngularDecoratorMetadataExpression(
240
238
}
241
239
const decorateArray = callExpr . arguments [ 0 ] as ts . ArrayLiteralExpression ;
242
240
// Check first array entry for Angular decorators.
243
- if ( decorateArray . elements [ 0 ] . kind !== ts . SyntaxKind . CallExpression ) {
244
- return false ;
245
- }
246
- const decoratorCall = decorateArray . elements [ 0 ] as ts . CallExpression ;
247
- if ( decoratorCall . expression . kind !== ts . SyntaxKind . Identifier ) {
248
- return false ;
249
- }
250
- const decoratorId = decoratorCall . expression as ts . Identifier ;
251
- if ( ! identifierIsMetadata ( decoratorId , ngMetadata , checker ) ) {
252
- return false ;
253
- }
254
- // Check second array entry for __metadata call.
255
- if ( decorateArray . elements [ 1 ] . kind !== ts . SyntaxKind . CallExpression ) {
256
- return false ;
257
- }
258
- const metadataCall = decorateArray . elements [ 1 ] as ts . CallExpression ;
259
- if ( ! isTslibHelper ( metadataCall , '__metadata' , tslibImports , checker ) ) {
241
+ if ( decorateArray . elements . length === 0 || ! ts . isCallExpression ( decorateArray . elements [ 0 ] ) ) {
260
242
return false ;
261
243
}
262
244
263
- return true ;
245
+ return decorateArray . elements . some ( decoratorCall => {
246
+ if ( ! ts . isCallExpression ( decoratorCall ) || ! ts . isIdentifier ( decoratorCall . expression ) ) {
247
+ return false ;
248
+ }
249
+
250
+ const decoratorId = decoratorCall . expression ;
251
+
252
+ return identifierIsMetadata ( decoratorId , ngMetadata , checker ) ;
253
+ } ) ;
264
254
}
265
255
266
256
// Check if assignment is `Clazz.propDecorators = [...];`.
@@ -359,16 +349,19 @@ function pickDecorateNodesToRemove(
359
349
ngMetadata : ts . Node [ ] ,
360
350
checker : ts . TypeChecker ,
361
351
) : ts . Node [ ] {
352
+ let callExpr : ts . CallExpression | undefined ;
353
+ if ( ts . isCallExpression ( exprStmt . expression ) ) {
354
+ callExpr = exprStmt . expression ;
355
+ } else if ( ts . isBinaryExpression ( exprStmt . expression ) ) {
356
+ const expr = exprStmt . expression ;
357
+ if ( ts . isCallExpression ( expr . right ) ) {
358
+ callExpr = expr . right ;
359
+ } else if ( ts . isBinaryExpression ( expr . right ) && ts . isCallExpression ( expr . right . right ) ) {
360
+ callExpr = expr . right . right ;
361
+ }
362
+ }
362
363
363
- const expr = expect < ts . BinaryExpression > ( exprStmt . expression , ts . SyntaxKind . BinaryExpression ) ;
364
- let callExpr : ts . CallExpression ;
365
-
366
- if ( expr . right . kind === ts . SyntaxKind . CallExpression ) {
367
- callExpr = expect < ts . CallExpression > ( expr . right , ts . SyntaxKind . CallExpression ) ;
368
- } else if ( expr . right . kind === ts. SyntaxKind . BinaryExpression ) {
369
- const innerExpr = expr . right as ts . BinaryExpression ;
370
- callExpr = expect < ts . CallExpression > ( innerExpr . right , ts . SyntaxKind . CallExpression ) ;
371
- } else {
364
+ if ( ! callExpr ) {
372
365
return [ ] ;
373
366
}
374
367
@@ -400,10 +393,6 @@ function pickDecorateNodesToRemove(
400
393
if ( el . arguments [ 0 ] . kind !== ts . SyntaxKind . StringLiteral ) {
401
394
return false ;
402
395
}
403
- const metadataTypeId = el . arguments [ 0 ] as ts . StringLiteral ;
404
- if ( metadataTypeId . text !== 'design:paramtypes' ) {
405
- return false ;
406
- }
407
396
408
397
return true ;
409
398
} ) ;
@@ -421,6 +410,7 @@ function pickDecorateNodesToRemove(
421
410
422
411
return true ;
423
412
} ) ;
413
+
424
414
ngDecoratorCalls . push ( ...metadataCalls , ...paramCalls ) ;
425
415
426
416
// If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
0 commit comments