Skip to content

Commit 6076e16

Browse files
filipesilvaalexeagle
authored andcommitted
feat(@angular-devkit/build-optimizer): remove constructor __param
1 parent 2962ede commit 6076e16

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/angular_devkit/build_optimizer/src/transforms/scrub-file.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ function pickDecorateNodesToRemove(
410410

411411
// Only remove constructor parameter metadata on non-whitelisted classes.
412412
if (platformWhitelist.indexOf(classId.text) === -1) {
413+
// Remove __metadata calls of type 'design:paramtypes'.
413414
const metadataCalls = elements.filter((el) => {
414415
if (!isTslibHelper(el, '__metadata', tslibImports, checker)) {
415416
return false;
@@ -427,7 +428,21 @@ function pickDecorateNodesToRemove(
427428

428429
return true;
429430
});
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);
431446
}
432447

433448
// If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`

packages/angular_devkit/build_optimizer/src/transforms/scrub-file_spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,38 @@ describe('scrub-file', () => {
422422
});
423423
});
424424

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+
425457
describe('propDecorators', () => {
426458
it('removes top-level Angular propDecorators', () => {
427459
const output = tags.stripIndent`

0 commit comments

Comments
 (0)