File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
packages/angular_devkit/build_optimizer/src/transforms Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -410,6 +410,7 @@ function pickDecorateNodesToRemove(
410
410
411
411
// Only remove constructor parameter metadata on non-whitelisted classes.
412
412
if ( platformWhitelist . indexOf ( classId . text ) === - 1 ) {
413
+ // Remove __metadata calls of type 'design:paramtypes'.
413
414
const metadataCalls = elements . filter ( ( el ) => {
414
415
if ( ! isTslibHelper ( el , '__metadata' , tslibImports , checker ) ) {
415
416
return false ;
@@ -427,7 +428,21 @@ function pickDecorateNodesToRemove(
427
428
428
429
return true ;
429
430
} ) ;
430
- ngDecoratorCalls . push ( ...metadataCalls ) ;
431
+ // Remove all __param calls.
432
+ const paramCalls = elements . filter ( ( el ) => {
433
+ if ( ! isTslibHelper ( el , '__param' , tslibImports , checker ) ) {
434
+ return false ;
435
+ }
436
+ if ( el . arguments . length != 2 ) {
437
+ return false ;
438
+ }
439
+ if ( el . arguments [ 0 ] . kind !== ts . SyntaxKind . NumericLiteral ) {
440
+ return false ;
441
+ }
442
+
443
+ return true ;
444
+ } ) ;
445
+ ngDecoratorCalls . push ( ...metadataCalls , ...paramCalls ) ;
431
446
}
432
447
433
448
// If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
Original file line number Diff line number Diff line change @@ -422,6 +422,38 @@ describe('scrub-file', () => {
422
422
} ) ;
423
423
} ) ;
424
424
425
+ describe ( '__param' , ( ) => {
426
+ it ( 'removes all constructor parameters and their type metadata' , ( ) => {
427
+ const output = tags . stripIndent `
428
+ var MyClass = /** @class */ (function () {
429
+ function MyClass(myParam) {
430
+ this.myProp = 'foo';
431
+ }
432
+ MyClass = __decorate([
433
+ myDecorator()
434
+ ], MyClass);
435
+ return MyClass;
436
+ }());
437
+ ` ;
438
+ const input = tags . stripIndent `
439
+ var MyClass = /** @class */ (function () {
440
+ function MyClass(myParam) {
441
+ this.myProp = 'foo';
442
+ }
443
+ MyClass = __decorate([
444
+ myDecorator(),
445
+ __param(0, myDecorator()),
446
+ __metadata("design:paramtypes", [Number])
447
+ ], MyClass);
448
+ return MyClass;
449
+ }());
450
+ ` ;
451
+
452
+ expect ( testScrubFile ( input ) ) . toBeTruthy ( ) ;
453
+ expect ( tags . oneLine `${ transform ( input ) } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
454
+ } ) ;
455
+ } ) ;
456
+
425
457
describe ( 'propDecorators' , ( ) => {
426
458
it ( 'removes top-level Angular propDecorators' , ( ) => {
427
459
const output = tags . stripIndent `
You can’t perform that action at this time.
0 commit comments