@@ -12,7 +12,7 @@ const srcDir = join(baseDir, 'src');
12
12
describe ( 'optimization' , ( ) => {
13
13
describe ( 'purgeStaticFieldDecorators' , ( ) => {
14
14
15
- it ( 'should remove the static decorator ' , ( ) => {
15
+ it ( 'should remove the static decorators ' , ( ) => {
16
16
// arrange
17
17
const decoratorStatement = `
18
18
import { Taco } from 'blah';
@@ -252,7 +252,7 @@ some more content
252
252
} ) ;
253
253
254
254
it ( 'should not remove decorators when it has an injectable statement in it' , ( ) => {
255
- const knownContent = `
255
+ const knownContent = `
256
256
var ActionSheetController = (function () {
257
257
/**
258
258
* @param {?} _app
@@ -294,7 +294,7 @@ ActionSheetController.ctorParameters = function () { return [
294
294
} ) ;
295
295
296
296
it ( 'should work with the ionic-angular index file' , ( ) => {
297
- const ionicModuleDecorator = `
297
+ const ionicModuleDecorator = `
298
298
IonicModule.decorators = [
299
299
{ type: NgModule, args: [{
300
300
imports: [
@@ -408,7 +408,7 @@ IonicModule.decorators = [
408
408
},] },
409
409
];
410
410
` ;
411
- const knownContent = `
411
+ const knownContent = `
412
412
import { ANALYZE_FOR_ENTRY_COMPONENTS, APP_INITIALIZER, ComponentFactoryResolver, Inject, Injector, NgModule, NgZone, Optional } from '@angular/core';
413
413
import { APP_BASE_HREF, Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy, PlatformLocation } from '@angular/common';
414
414
import { DOCUMENT } from '@angular/platform-browser';
@@ -782,14 +782,14 @@ export function provideLocationStrategy(platformLocationStrategy, baseHref, conf
782
782
expect ( result . indexOf ( ionicModuleDecorator ) ) . toEqual ( - 1 ) ;
783
783
} ) ;
784
784
785
- it ( 'shoud process component file correctly' , ( ) => {
785
+ it ( 'should process component file correctly' , ( ) => {
786
786
787
- const propDecorators = `
787
+ const propDecorators = `
788
788
ActionSheetCmp.propDecorators = {
789
789
'keyUp': [{ type: HostListener, args: ['body:keyup', ['$event'],] },],
790
790
};
791
791
` ;
792
- const decoratorContent = `
792
+ const decoratorContent = `
793
793
ActionSheetCmp.decorators = [
794
794
{ type: Component, args: [{
795
795
selector: 'ion-action-sheet',
@@ -821,7 +821,7 @@ ActionSheetCmp.decorators = [
821
821
},] },
822
822
];
823
823
` ;
824
- const knownContent = `
824
+ const knownContent = `
825
825
import { Component, ElementRef, HostListener, Renderer, ViewEncapsulation } from '@angular/core';
826
826
import { GestureController, BLOCK_ALL } from '../../gestures/gesture-controller';
827
827
import { Config } from '../../config/config';
@@ -1003,42 +1003,42 @@ let actionSheetIds = -1;
1003
1003
describe ( 'purgeTranspiledDecorators' , ( ) => {
1004
1004
it ( 'should purge out transpiled decorators' , ( ) => {
1005
1005
1006
- const inputDecorator = `
1006
+ const inputDecorator = `
1007
1007
__decorate([
1008
1008
Input(),
1009
1009
__metadata("design:type", String)
1010
1010
], AboutPage.prototype, "someVariable", void 0);
1011
1011
` ;
1012
1012
1013
- const outputDecorator = `
1013
+ const outputDecorator = `
1014
1014
__decorate([
1015
1015
Output(),
1016
1016
__metadata("design:type", typeof (_a = typeof EventEmitter !== "undefined" && EventEmitter) === "function" && _a || Object)
1017
1017
], AboutPage.prototype, "emitter", void 0);
1018
1018
` ;
1019
1019
1020
- const viewChildDecorator = `
1020
+ const viewChildDecorator = `
1021
1021
__decorate([
1022
1022
ViewChild('test', { read: ElementRef }),
1023
1023
__metadata("design:type", Object)
1024
1024
], AboutPage.prototype, "test", void 0);
1025
1025
` ;
1026
1026
1027
- const viewChildrenDecorator = `
1027
+ const viewChildrenDecorator = `
1028
1028
__decorate([
1029
1029
ViewChildren('test'),
1030
1030
__metadata("design:type", Object)
1031
1031
], AboutPage.prototype, "tests", void 0);
1032
1032
` ;
1033
1033
1034
- const hostBindingDecorator = `
1034
+ const hostBindingDecorator = `
1035
1035
__decorate([
1036
1036
HostBinding('class.searchbar-has-focus'),
1037
1037
__metadata("design:type", Boolean)
1038
1038
], AboutPage.prototype, "_sbHasFocus", void 0);
1039
1039
` ;
1040
1040
1041
- const hostListenerDecorator = `
1041
+ const hostListenerDecorator = `
1042
1042
__decorate([
1043
1043
HostListener('click', ['$event']),
1044
1044
__metadata("design:type", Function),
@@ -1047,7 +1047,7 @@ __decorate([
1047
1047
], AboutPage.prototype, "someFunction", null);
1048
1048
` ;
1049
1049
1050
- const classDecorators = `
1050
+ const classDecorators = `
1051
1051
AboutPage = __decorate([
1052
1052
IonicPage(),
1053
1053
Component({
@@ -1058,7 +1058,7 @@ AboutPage = __decorate([
1058
1058
], AboutPage);
1059
1059
` ;
1060
1060
1061
- const knownContent = `
1061
+ const knownContent = `
1062
1062
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1063
1063
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1064
1064
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1113,14 +1113,14 @@ var _a, _b, _c;
1113
1113
1114
1114
it ( 'should not purge any injectable decorators' , ( ) => {
1115
1115
1116
- const injectableDecorator = `
1116
+ const injectableDecorator = `
1117
1117
ConferenceData = __decorate([
1118
1118
Injectable(),
1119
1119
__metadata("design:paramtypes", [typeof (_a = typeof Http !== "undefined" && Http) === "function" && _a || Object, typeof (_b = typeof UserData !== "undefined" && UserData) === "function" && _b || Object])
1120
1120
], ConferenceData);
1121
1121
` ;
1122
1122
1123
- const knownContent = `
1123
+ const knownContent = `
1124
1124
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1125
1125
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1126
1126
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1283,7 +1283,7 @@ var _a, _b;
1283
1283
1284
1284
describe ( 'addPureAnnotation' , ( ) => {
1285
1285
it ( 'should add the pure annotation to a transpiled class' , ( ) => {
1286
- const knownContent = `
1286
+ const knownContent = `
1287
1287
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1288
1288
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1289
1289
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1407,7 +1407,7 @@ function CardContent_tsickle_Closure_declarations() {
1407
1407
//# sourceMappingURL=card-content.js.map
1408
1408
` ;
1409
1409
1410
- const expectedContent = `
1410
+ const expectedContent = `
1411
1411
var __extends = (this && this.__extends) || (function () {
1412
1412
var extendStatics = Object.setPrototypeOf ||
1413
1413
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -1464,4 +1464,98 @@ function CardContent_tsickle_Closure_declarations() {
1464
1464
expect ( result ) . toEqual ( expectedContent ) ;
1465
1465
} ) ;
1466
1466
} ) ;
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
+ } ) ;
1467
1561
} ) ;
0 commit comments