@@ -52,17 +52,12 @@ function scrubFileTransformer(checker: ts.TypeChecker, isAngularCoreFile: boolea
52
52
const exprStmt = node as ts . ExpressionStatement ;
53
53
if ( isDecoratorAssignmentExpression ( exprStmt ) ) {
54
54
nodes . push ( ...pickDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
55
- }
56
- if ( isDecorateAssignmentExpression ( exprStmt , tslibImports , checker ) ) {
55
+ } else if ( isDecorateAssignmentExpression ( exprStmt , tslibImports , checker )
56
+ || isAngularDecoratorExpression ( exprStmt , ngMetadata , tslibImports , checker ) ) {
57
57
nodes . push ( ...pickDecorateNodesToRemove ( exprStmt , tslibImports , ngMetadata , checker ) ) ;
58
- }
59
- if ( isAngularDecoratorMetadataExpression ( exprStmt , ngMetadata , tslibImports , checker ) ) {
60
- nodes . push ( node ) ;
61
- }
62
- if ( isPropDecoratorAssignmentExpression ( exprStmt ) ) {
58
+ } else if ( isPropDecoratorAssignmentExpression ( exprStmt ) ) {
63
59
nodes . push ( ...pickPropDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
64
- }
65
- if ( isCtorParamsAssignmentExpression ( exprStmt ) ) {
60
+ } else if ( isCtorParamsAssignmentExpression ( exprStmt ) ) {
66
61
nodes . push ( node ) ;
67
62
}
68
63
}
@@ -230,7 +225,7 @@ function isDecorateAssignmentExpression(
230
225
}
231
226
232
227
// Check if expression is `__decorate([smt, __metadata("design:type", Object)], ...)`.
233
- function isAngularDecoratorMetadataExpression (
228
+ function isAngularDecoratorExpression (
234
229
exprStmt : ts . ExpressionStatement ,
235
230
ngMetadata : ts . Node [ ] ,
236
231
tslibImports : ts . NamespaceImport [ ] ,
@@ -252,27 +247,19 @@ function isAngularDecoratorMetadataExpression(
252
247
}
253
248
const decorateArray = callExpr . arguments [ 0 ] as ts . ArrayLiteralExpression ;
254
249
// Check first array entry for Angular decorators.
255
- if ( decorateArray . elements [ 0 ] . kind !== ts . SyntaxKind . CallExpression ) {
256
- return false ;
257
- }
258
- const decoratorCall = decorateArray . elements [ 0 ] as ts . CallExpression ;
259
- if ( decoratorCall . expression . kind !== ts . SyntaxKind . Identifier ) {
260
- return false ;
261
- }
262
- const decoratorId = decoratorCall . expression as ts . Identifier ;
263
- if ( ! identifierIsMetadata ( decoratorId , ngMetadata , checker ) ) {
264
- return false ;
265
- }
266
- // Check second array entry for __metadata call.
267
- if ( decorateArray . elements [ 1 ] . kind !== ts . SyntaxKind . CallExpression ) {
268
- return false ;
269
- }
270
- const metadataCall = decorateArray . elements [ 1 ] as ts . CallExpression ;
271
- if ( ! isTslibHelper ( metadataCall , '__metadata' , tslibImports , checker ) ) {
250
+ if ( decorateArray . elements . length === 0 || ! ts . isCallExpression ( decorateArray . elements [ 0 ] ) ) {
272
251
return false ;
273
252
}
274
253
275
- return true ;
254
+ return decorateArray . elements . some ( decoratorCall => {
255
+ if ( ! ts . isCallExpression ( decoratorCall ) || ! ts . isIdentifier ( decoratorCall . expression ) ) {
256
+ return false ;
257
+ }
258
+
259
+ const decoratorId = decoratorCall . expression ;
260
+
261
+ return identifierIsMetadata ( decoratorId , ngMetadata , checker ) ;
262
+ } ) ;
276
263
}
277
264
278
265
// Check if assignment is `Clazz.propDecorators = [...];`.
@@ -357,16 +344,19 @@ function pickDecorateNodesToRemove(
357
344
ngMetadata : ts . Node [ ] ,
358
345
checker : ts . TypeChecker ,
359
346
) : ts . Node [ ] {
347
+ let callExpr : ts . CallExpression | undefined ;
348
+ if ( ts . isCallExpression ( exprStmt . expression ) ) {
349
+ callExpr = exprStmt . expression ;
350
+ } else if ( ts . isBinaryExpression ( exprStmt . expression ) ) {
351
+ const expr = exprStmt . expression ;
352
+ if ( ts . isCallExpression ( expr . right ) ) {
353
+ callExpr = expr . right ;
354
+ } else if ( ts . isBinaryExpression ( expr . right ) && ts . isCallExpression ( expr . right . right ) ) {
355
+ callExpr = expr . right . right ;
356
+ }
357
+ }
360
358
361
- const expr = expect < ts . BinaryExpression > ( exprStmt . expression , ts . SyntaxKind . BinaryExpression ) ;
362
- let callExpr : ts . CallExpression ;
363
-
364
- if ( expr . right . kind === ts . SyntaxKind . CallExpression ) {
365
- callExpr = expect < ts . CallExpression > ( expr . right , ts . SyntaxKind . CallExpression ) ;
366
- } else if ( expr . right . kind === ts . SyntaxKind . BinaryExpression ) {
367
- const innerExpr = expr . right as ts . BinaryExpression ;
368
- callExpr = expect < ts . CallExpression > ( innerExpr . right , ts . SyntaxKind . CallExpression ) ;
369
- } else {
359
+ if ( ! callExpr ) {
370
360
return [ ] ;
371
361
}
372
362
@@ -398,10 +388,6 @@ function pickDecorateNodesToRemove(
398
388
if ( el . arguments [ 0 ] . kind !== ts . SyntaxKind . StringLiteral ) {
399
389
return false ;
400
390
}
401
- const metadataTypeId = el . arguments [ 0 ] as ts . StringLiteral ;
402
- if ( metadataTypeId . text !== 'design:paramtypes' ) {
403
- return false ;
404
- }
405
391
406
392
return true ;
407
393
} ) ;
@@ -419,6 +405,7 @@ function pickDecorateNodesToRemove(
419
405
420
406
return true ;
421
407
} ) ;
408
+
422
409
ngDecoratorCalls . push ( ...metadataCalls , ...paramCalls ) ;
423
410
424
411
// If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
0 commit comments