@@ -191,7 +191,7 @@ describe('adjust-static-class-members Babel plugin', () => {
191
191
` ) ;
192
192
} ) ;
193
193
194
- it ( 'does wrap not class with only side effect fields' , ( ) => {
194
+ it ( 'does not wrap class with only side effect fields' , ( ) => {
195
195
testCaseNoChange ( `
196
196
class CustomComponentEffects {
197
197
constructor(_actions) {
@@ -203,6 +203,30 @@ describe('adjust-static-class-members Babel plugin', () => {
203
203
` ) ;
204
204
} ) ;
205
205
206
+ it ( 'does not wrap class with only side effect native fields' , ( ) => {
207
+ testCaseNoChange ( `
208
+ class CustomComponentEffects {
209
+ static someFieldWithSideEffects = console.log('foo');
210
+ constructor(_actions) {
211
+ this._actions = _actions;
212
+ this.doThis = this._actions;
213
+ }
214
+ }
215
+ ` ) ;
216
+ } ) ;
217
+
218
+ it ( 'does not wrap class with only instance native fields' , ( ) => {
219
+ testCaseNoChange ( `
220
+ class CustomComponentEffects {
221
+ someFieldWithSideEffects = console.log('foo');
222
+ constructor(_actions) {
223
+ this._actions = _actions;
224
+ this.doThis = this._actions;
225
+ }
226
+ }
227
+ ` ) ;
228
+ } ) ;
229
+
206
230
it ( 'wraps class with pure annotated side effect fields (#__PURE__)' , ( ) => {
207
231
testCase ( {
208
232
input : `
@@ -229,6 +253,32 @@ describe('adjust-static-class-members Babel plugin', () => {
229
253
} ) ;
230
254
} ) ;
231
255
256
+ it ( 'wraps class with pure annotated side effect native fields (#__PURE__)' , ( ) => {
257
+ testCase ( {
258
+ input : `
259
+ class CustomComponentEffects {
260
+ static someFieldWithSideEffects = /*#__PURE__*/ console.log('foo');
261
+ constructor(_actions) {
262
+ this._actions = _actions;
263
+ this.doThis = this._actions;
264
+ }
265
+ }
266
+ ` ,
267
+ expected : `
268
+ let CustomComponentEffects = /*#__PURE__*/ (() => {
269
+ class CustomComponentEffects {
270
+ static someFieldWithSideEffects = /*#__PURE__*/ console.log('foo');
271
+ constructor(_actions) {
272
+ this._actions = _actions;
273
+ this.doThis = this._actions;
274
+ }
275
+ }
276
+ return CustomComponentEffects;
277
+ })();
278
+ ` ,
279
+ } ) ;
280
+ } ) ;
281
+
232
282
it ( 'wraps class with pure annotated side effect fields (@__PURE__)' , ( ) => {
233
283
testCase ( {
234
284
input : `
@@ -335,6 +385,32 @@ describe('adjust-static-class-members Babel plugin', () => {
335
385
} ) ;
336
386
} ) ;
337
387
388
+ it ( 'wraps exported class with a pure native static field' , ( ) => {
389
+ testCase ( {
390
+ input : `
391
+ export class CustomComponentEffects {
392
+ static someField = 42;
393
+ constructor(_actions) {
394
+ this._actions = _actions;
395
+ this.doThis = this._actions;
396
+ }
397
+ }
398
+ ` ,
399
+ expected : `
400
+ export let CustomComponentEffects = /*#__PURE__*/ (() => {
401
+ class CustomComponentEffects {
402
+ static someField = 42;
403
+ constructor(_actions) {
404
+ this._actions = _actions;
405
+ this.doThis = this._actions;
406
+ }
407
+ }
408
+ return CustomComponentEffects;
409
+ })();
410
+ ` ,
411
+ } ) ;
412
+ } ) ;
413
+
338
414
it ( 'wraps class with a basic literal static field' , ( ) => {
339
415
testCase ( {
340
416
input : `
@@ -416,6 +492,32 @@ describe('adjust-static-class-members Babel plugin', () => {
416
492
` ) ;
417
493
} ) ;
418
494
495
+ it ( 'does not wrap class with only pure native static fields and some side effect static fields' , ( ) => {
496
+ testCaseNoChange ( `
497
+ class CustomComponentEffects {
498
+ static someField = 42;
499
+ constructor(_actions) {
500
+ this._actions = _actions;
501
+ this.doThis = this._actions;
502
+ }
503
+ }
504
+ CustomComponentEffects.someFieldWithSideEffects = console.log('foo');
505
+ ` ) ;
506
+ } ) ;
507
+
508
+ it ( 'does not wrap class with only some pure native static fields' , ( ) => {
509
+ testCaseNoChange ( `
510
+ class CustomComponentEffects {
511
+ static someField = 42;
512
+ static someFieldWithSideEffects = console.log('foo');
513
+ constructor(_actions) {
514
+ this._actions = _actions;
515
+ this.doThis = this._actions;
516
+ }
517
+ }
518
+ ` ) ;
519
+ } ) ;
520
+
419
521
it ( 'does not wrap class with class decorators when wrapDecorators is false' , ( ) => {
420
522
testCaseNoChange (
421
523
`
@@ -597,7 +699,7 @@ describe('adjust-static-class-members Babel plugin', () => {
597
699
} ) ;
598
700
} ) ;
599
701
600
- it ( 'wraps class with multiple Angular static field ' , ( ) => {
702
+ it ( 'wraps class with multiple Angular static fields ' , ( ) => {
601
703
testCase ( {
602
704
input : `
603
705
class CommonModule {
@@ -626,6 +728,41 @@ describe('adjust-static-class-members Babel plugin', () => {
626
728
} ) ;
627
729
} ) ;
628
730
731
+ it ( 'wraps class with multiple Angular native static fields' , ( ) => {
732
+ testCase ( {
733
+ input : `
734
+ class CommonModule {
735
+ static ɵfac = function CommonModule_Factory(t) { return new (t || CommonModule)(); };
736
+ static ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: CommonModule });
737
+ static ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ providers: [
738
+ { provide: NgLocalization, useClass: NgLocaleLocalization },
739
+ ] });
740
+ }
741
+ ` ,
742
+ expected : `
743
+ let CommonModule = /*#__PURE__*/ (() => {
744
+ class CommonModule {
745
+ static ɵfac = function CommonModule_Factory(t) {
746
+ return new (t || CommonModule)();
747
+ };
748
+ static ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({
749
+ type: CommonModule,
750
+ });
751
+ static ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({
752
+ providers: [
753
+ {
754
+ provide: NgLocalization,
755
+ useClass: NgLocaleLocalization,
756
+ },
757
+ ],
758
+ });
759
+ }
760
+ return CommonModule;
761
+ })();
762
+ ` ,
763
+ } ) ;
764
+ } ) ;
765
+
629
766
it ( 'wraps default exported class with pure static fields' , ( ) => {
630
767
testCase ( {
631
768
input : `
0 commit comments