@@ -58,11 +58,9 @@ function scrubFileTransformer(checker: ts.TypeChecker, isAngularCoreFile: boolea
5858 nodes . push ( node ) ;
5959 } else if ( isDecoratorAssignmentExpression ( exprStmt ) ) {
6060 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 ) ) {
6263 nodes . push ( ...pickDecorateNodesToRemove ( exprStmt , tslibImports , ngMetadata , checker ) ) ;
63- } else if ( isAngularDecoratorMetadataExpression ( exprStmt ,
64- ngMetadata , tslibImports , checker ) ) {
65- nodes . push ( node ) ;
6664 } else if ( isPropDecoratorAssignmentExpression ( exprStmt ) ) {
6765 nodes . push ( ...pickPropDecorationNodesToRemove ( exprStmt , ngMetadata , checker ) ) ;
6866 }
@@ -218,7 +216,7 @@ function isDecorateAssignmentExpression(
218216}
219217
220218// Check if expression is `__decorate([smt, __metadata("design:type", Object)], ...)`.
221- function isAngularDecoratorMetadataExpression (
219+ function isAngularDecoratorExpression (
222220 exprStmt : ts . ExpressionStatement ,
223221 ngMetadata : ts . Node [ ] ,
224222 tslibImports : ts . NamespaceImport [ ] ,
@@ -240,27 +238,19 @@ function isAngularDecoratorMetadataExpression(
240238 }
241239 const decorateArray = callExpr . arguments [ 0 ] as ts . ArrayLiteralExpression ;
242240 // 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 ] ) ) {
260242 return false ;
261243 }
262244
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+ } ) ;
264254}
265255
266256// Check if assignment is `Clazz.propDecorators = [...];`.
@@ -359,16 +349,19 @@ function pickDecorateNodesToRemove(
359349 ngMetadata : ts . Node [ ] ,
360350 checker : ts . TypeChecker ,
361351) : 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+ }
362363
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 ) {
372365 return [ ] ;
373366 }
374367
@@ -400,10 +393,6 @@ function pickDecorateNodesToRemove(
400393 if ( el . arguments [ 0 ] . kind !== ts . SyntaxKind . StringLiteral ) {
401394 return false ;
402395 }
403- const metadataTypeId = el . arguments [ 0 ] as ts . StringLiteral ;
404- if ( metadataTypeId . text !== 'design:paramtypes' ) {
405- return false ;
406- }
407396
408397 return true ;
409398 } ) ;
@@ -421,6 +410,7 @@ function pickDecorateNodesToRemove(
421410
422411 return true ;
423412 } ) ;
413+
424414 ngDecoratorCalls . push ( ...metadataCalls , ...paramCalls ) ;
425415
426416 // If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
0 commit comments