@@ -12,7 +12,7 @@ const srcDir = join(baseDir, 'src');
1212describe ( 'optimization' , ( ) => {
1313 describe ( 'purgeStaticFieldDecorators' , ( ) => {
1414
15- it ( 'should remove the static decorator ' , ( ) => {
15+ it ( 'should remove the static decorators ' , ( ) => {
1616 // arrange
1717 const decoratorStatement = `
1818 import { Taco } from 'blah';
@@ -252,7 +252,7 @@ some more content
252252 } ) ;
253253
254254 it ( 'should not remove decorators when it has an injectable statement in it' , ( ) => {
255- const knownContent = `
255+ const knownContent = `
256256var ActionSheetController = (function () {
257257 /**
258258 * @param {?} _app
@@ -294,7 +294,7 @@ ActionSheetController.ctorParameters = function () { return [
294294 } ) ;
295295
296296 it ( 'should work with the ionic-angular index file' , ( ) => {
297- const ionicModuleDecorator = `
297+ const ionicModuleDecorator = `
298298IonicModule.decorators = [
299299 { type: NgModule, args: [{
300300 imports: [
@@ -408,7 +408,7 @@ IonicModule.decorators = [
408408 },] },
409409];
410410 ` ;
411- const knownContent = `
411+ const knownContent = `
412412import { ANALYZE_FOR_ENTRY_COMPONENTS, APP_INITIALIZER, ComponentFactoryResolver, Inject, Injector, NgModule, NgZone, Optional } from '@angular/core';
413413import { APP_BASE_HREF, Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy, PlatformLocation } from '@angular/common';
414414import { DOCUMENT } from '@angular/platform-browser';
@@ -782,14 +782,14 @@ export function provideLocationStrategy(platformLocationStrategy, baseHref, conf
782782 expect ( result . indexOf ( ionicModuleDecorator ) ) . toEqual ( - 1 ) ;
783783 } ) ;
784784
785- it ( 'shoud process component file correctly' , ( ) => {
785+ it ( 'should process component file correctly' , ( ) => {
786786
787- const propDecorators = `
787+ const propDecorators = `
788788ActionSheetCmp.propDecorators = {
789789 'keyUp': [{ type: HostListener, args: ['body:keyup', ['$event'],] },],
790790};
791791` ;
792- const decoratorContent = `
792+ const decoratorContent = `
793793ActionSheetCmp.decorators = [
794794 { type: Component, args: [{
795795 selector: 'ion-action-sheet',
@@ -821,7 +821,7 @@ ActionSheetCmp.decorators = [
821821 },] },
822822];
823823 ` ;
824- const knownContent = `
824+ const knownContent = `
825825import { Component, ElementRef, HostListener, Renderer, ViewEncapsulation } from '@angular/core';
826826import { GestureController, BLOCK_ALL } from '../../gestures/gesture-controller';
827827import { Config } from '../../config/config';
@@ -1003,42 +1003,42 @@ let actionSheetIds = -1;
10031003 describe ( 'purgeTranspiledDecorators' , ( ) => {
10041004 it ( 'should purge out transpiled decorators' , ( ) => {
10051005
1006- const inputDecorator = `
1006+ const inputDecorator = `
10071007__decorate([
10081008 Input(),
10091009 __metadata("design:type", String)
10101010], AboutPage.prototype, "someVariable", void 0);
10111011 ` ;
10121012
1013- const outputDecorator = `
1013+ const outputDecorator = `
10141014__decorate([
10151015 Output(),
10161016 __metadata("design:type", typeof (_a = typeof EventEmitter !== "undefined" && EventEmitter) === "function" && _a || Object)
10171017], AboutPage.prototype, "emitter", void 0);
10181018 ` ;
10191019
1020- const viewChildDecorator = `
1020+ const viewChildDecorator = `
10211021__decorate([
10221022 ViewChild('test', { read: ElementRef }),
10231023 __metadata("design:type", Object)
10241024], AboutPage.prototype, "test", void 0);
10251025 ` ;
10261026
1027- const viewChildrenDecorator = `
1027+ const viewChildrenDecorator = `
10281028__decorate([
10291029 ViewChildren('test'),
10301030 __metadata("design:type", Object)
10311031], AboutPage.prototype, "tests", void 0);
10321032 ` ;
10331033
1034- const hostBindingDecorator = `
1034+ const hostBindingDecorator = `
10351035__decorate([
10361036 HostBinding('class.searchbar-has-focus'),
10371037 __metadata("design:type", Boolean)
10381038], AboutPage.prototype, "_sbHasFocus", void 0);
10391039 ` ;
10401040
1041- const hostListenerDecorator = `
1041+ const hostListenerDecorator = `
10421042__decorate([
10431043 HostListener('click', ['$event']),
10441044 __metadata("design:type", Function),
@@ -1047,7 +1047,7 @@ __decorate([
10471047], AboutPage.prototype, "someFunction", null);
10481048 ` ;
10491049
1050- const classDecorators = `
1050+ const classDecorators = `
10511051AboutPage = __decorate([
10521052 IonicPage(),
10531053 Component({
@@ -1058,7 +1058,7 @@ AboutPage = __decorate([
10581058], AboutPage);
10591059 ` ;
10601060
1061- const knownContent = `
1061+ const knownContent = `
10621062var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10631063 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10641064 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1113,14 +1113,14 @@ var _a, _b, _c;
11131113
11141114 it ( 'should not purge any injectable decorators' , ( ) => {
11151115
1116- const injectableDecorator = `
1116+ const injectableDecorator = `
11171117ConferenceData = __decorate([
11181118 Injectable(),
11191119 __metadata("design:paramtypes", [typeof (_a = typeof Http !== "undefined" && Http) === "function" && _a || Object, typeof (_b = typeof UserData !== "undefined" && UserData) === "function" && _b || Object])
11201120], ConferenceData);
11211121 ` ;
11221122
1123- const knownContent = `
1123+ const knownContent = `
11241124var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11251125 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11261126 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1283,7 +1283,7 @@ var _a, _b;
12831283
12841284 describe ( 'addPureAnnotation' , ( ) => {
12851285 it ( 'should add the pure annotation to a transpiled class' , ( ) => {
1286- const knownContent = `
1286+ const knownContent = `
12871287var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12881288 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12891289 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1407,7 +1407,7 @@ function CardContent_tsickle_Closure_declarations() {
14071407//# sourceMappingURL=card-content.js.map
14081408` ;
14091409
1410- const expectedContent = `
1410+ const expectedContent = `
14111411var __extends = (this && this.__extends) || (function () {
14121412 var extendStatics = Object.setPrototypeOf ||
14131413 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -1464,4 +1464,98 @@ function CardContent_tsickle_Closure_declarations() {
14641464 expect ( result ) . toEqual ( expectedContent ) ;
14651465 } ) ;
14661466 } ) ;
1467+
1468+ describe ( 'purgeStaticCtorFields' , ( ) => {
1469+ it ( 'should purge the ctor field' , ( ) => {
1470+
1471+ const ctorParams = `
1472+ Badge.ctorParameters = function () { return [
1473+ { type: Config, },
1474+ { type: ElementRef, },
1475+ { type: Renderer, },
1476+ ]; };
1477+ ` ;
1478+ const knownContent = `
1479+ var __extends = (this && this.__extends) || (function () {
1480+ var extendStatics = Object.setPrototypeOf ||
1481+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1482+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1483+ return function (d, b) {
1484+ extendStatics(d, b);
1485+ function __() { this.constructor = d; }
1486+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1487+ };
1488+ })();
1489+ import { Directive, ElementRef, Renderer } from '@angular/core';
1490+ import { Config } from '../../config/config';
1491+ import { Ion } from '../ion';
1492+
1493+ var Badge = (function (_super) {
1494+ __extends(Badge, _super);
1495+
1496+ function Badge(config, elementRef, renderer) {
1497+ return _super.call(this, config, elementRef, renderer, 'badge') || this;
1498+ }
1499+ return Badge;
1500+ }(Ion));
1501+ export { Badge };
1502+ Badge.decorators = [
1503+ { type: Directive, args: [{
1504+ selector: 'ion-badge'
1505+ },] },
1506+ ];
1507+
1508+ ${ ctorParams }
1509+ function Badge_tsickle_Closure_declarations() {
1510+
1511+ Badge.decorators;
1512+
1513+ Badge.ctorParameters;
1514+ }
1515+ //# sourceMappingURL=badge.js.map
1516+ ` ;
1517+
1518+
1519+
1520+ let magicString = new MagicString ( knownContent ) ;
1521+ const filePath = join ( ionicAngular , 'components' , 'badge' , 'badge.js' ) ;
1522+ magicString = decorators . purgeStaticCtorFields ( filePath , knownContent , ionicAngular , angularDir , srcDir , magicString ) ;
1523+ const result : string = magicString . toString ( ) ;
1524+ expect ( result . indexOf ( ctorParams ) ) . toEqual ( - 1 ) ;
1525+ } ) ;
1526+
1527+ it ( 'should purge an empty ctor field' , ( ) => {
1528+ const ctorParams = `
1529+ Avatar.ctorParameters = function () { return []; };
1530+ ` ;
1531+ const knownContent = `
1532+
1533+ var Avatar = (function () {
1534+ function Avatar() {
1535+ }
1536+ return Avatar;
1537+ }());
1538+ export { Avatar };
1539+ Avatar.decorators = [
1540+ { type: Directive, args: [{
1541+ selector: 'ion-avatar'
1542+ },] },
1543+ ];
1544+
1545+ ${ ctorParams }
1546+ function Avatar_tsickle_Closure_declarations() {
1547+ Avatar.decorators;
1548+
1549+ Avatar.ctorParameters;
1550+ }
1551+ //# sourceMappingURL=avatar.js.map
1552+ ` ;
1553+
1554+ let magicString = new MagicString ( knownContent ) ;
1555+ const filePath = join ( ionicAngular , 'components' , 'badge' , 'badge.js' ) ;
1556+ magicString = decorators . purgeStaticCtorFields ( filePath , knownContent , ionicAngular , angularDir , srcDir , magicString ) ;
1557+ const result : string = magicString . toString ( ) ;
1558+ expect ( result . indexOf ( ctorParams ) ) . toEqual ( - 1 ) ;
1559+ } ) ;
1560+ } ) ;
14671561} ) ;
0 commit comments