Skip to content

Commit

Permalink
feat(@angular-devkit/build-optimizer): remove constructor __param
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and alexeagle committed Sep 6, 2018
1 parent 2962ede commit 6076e16
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ function pickDecorateNodesToRemove(

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

return true;
});
ngDecoratorCalls.push(...metadataCalls);
// Remove all __param calls.
const paramCalls = elements.filter((el) => {
if (!isTslibHelper(el, '__param', tslibImports, checker)) {
return false;
}
if (el.arguments.length != 2) {
return false;
}
if (el.arguments[0].kind !== ts.SyntaxKind.NumericLiteral) {
return false;
}

return true;
});
ngDecoratorCalls.push(...metadataCalls, ...paramCalls);
}

// If all decorators are metadata decorators then return the whole `Class = __decorate([...])'`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,38 @@ describe('scrub-file', () => {
});
});

describe('__param', () => {
it('removes all constructor parameters and their type metadata', () => {
const output = tags.stripIndent`
var MyClass = /** @class */ (function () {
function MyClass(myParam) {
this.myProp = 'foo';
}
MyClass = __decorate([
myDecorator()
], MyClass);
return MyClass;
}());
`;
const input = tags.stripIndent`
var MyClass = /** @class */ (function () {
function MyClass(myParam) {
this.myProp = 'foo';
}
MyClass = __decorate([
myDecorator(),
__param(0, myDecorator()),
__metadata("design:paramtypes", [Number])
], MyClass);
return MyClass;
}());
`;

expect(testScrubFile(input)).toBeTruthy();
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
});
});

describe('propDecorators', () => {
it('removes top-level Angular propDecorators', () => {
const output = tags.stripIndent`
Expand Down

0 comments on commit 6076e16

Please sign in to comment.