@@ -52,17 +52,12 @@ function scrubFileTransformer(checker: ts.TypeChecker, isAngularCoreFile: boolea
5252 const exprStmt = node as ts . ExpressionStatement ;
5353 if ( isDecoratorAssignmentExpression ( exprStmt ) ) {
5454 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 ) ) {
5757 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 ) ) {
6359 nodes . push ( ...pickPropDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
64- }
65- if ( isCtorParamsAssignmentExpression ( exprStmt ) ) {
60+ } else if ( isCtorParamsAssignmentExpression ( exprStmt ) ) {
6661 nodes . push ( node ) ;
6762 }
6863 }
@@ -230,7 +225,7 @@ function isDecorateAssignmentExpression(
230225}
231226
232227// Check if expression is `__decorate([smt, __metadata("design:type", Object)], ...)`.
233- function isAngularDecoratorMetadataExpression (
228+ function isAngularDecoratorExpression (
234229 exprStmt : ts . ExpressionStatement ,
235230 ngMetadata : ts . Node [ ] ,
236231 tslibImports : ts . NamespaceImport [ ] ,
@@ -252,27 +247,19 @@ function isAngularDecoratorMetadataExpression(
252247 }
253248 const decorateArray = callExpr . arguments [ 0 ] as ts . ArrayLiteralExpression ;
254249 // 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 ] ) ) {
272251 return false ;
273252 }
274253
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+ } ) ;
276263}
277264
278265// Check if assignment is `Clazz.propDecorators = [...];`.
@@ -357,16 +344,19 @@ function pickDecorateNodesToRemove(
357344 ngMetadata : ts . Node [ ] ,
358345 checker : ts . TypeChecker ,
359346) : 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+ }
360358
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 ) {
370360 return [ ] ;
371361 }
372362
@@ -398,10 +388,6 @@ function pickDecorateNodesToRemove(
398388 if ( el . arguments [ 0 ] . kind !== ts . SyntaxKind . StringLiteral ) {
399389 return false ;
400390 }
401- const metadataTypeId = el . arguments [ 0 ] as ts . StringLiteral ;
402- if ( metadataTypeId . text !== 'design:paramtypes' ) {
403- return false ;
404- }
405391
406392 return true ;
407393 } ) ;
@@ -419,6 +405,7 @@ function pickDecorateNodesToRemove(
419405
420406 return true ;
421407 } ) ;
408+
422409 ngDecoratorCalls . push ( ...metadataCalls , ...paramCalls ) ;
423410
424411 // If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
0 commit comments