@@ -33,7 +33,7 @@ describe('decorators', function(){
33
33
expect ( calls ) . to . eql ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
34
34
} ) ;
35
35
36
- it ( 'should call descriptors in reverse order per-method' , function ( ) {
36
+ it ( 'should call decorators in reverse order per-method' , function ( ) {
37
37
const calls = [ ] ;
38
38
function dec ( id ) {
39
39
return function ( ) {
@@ -639,6 +639,36 @@ describe('decorators', function(){
639
639
expect ( inst . prop ) . to . be . undefined ;
640
640
} ) ;
641
641
642
+ it ( 'should support mutating an initialzer into an accessor' , function ( ) {
643
+ function dec ( target , name , descriptor ) {
644
+ expect ( target ) . to . be . ok ;
645
+ expect ( name ) . to . eql ( "prop" ) ;
646
+ expect ( descriptor ) . to . be . an ( 'object' ) ;
647
+
648
+ let { initializer} = descriptor ;
649
+ delete descriptor . initializer ;
650
+ delete descriptor . writable ;
651
+
652
+ let value ;
653
+ descriptor . get = function ( ) {
654
+ if ( initializer ) {
655
+ value = '__' + initializer . call ( this ) + '__' ;
656
+ initializer = null ;
657
+ }
658
+ return value ;
659
+ } ;
660
+ }
661
+
662
+ class Example {
663
+ @dec
664
+ prop = 3 ;
665
+ }
666
+
667
+ let inst = new Example ( ) ;
668
+
669
+ expect ( inst . prop ) . to . eql ( '__3__' ) ;
670
+ } ) ;
671
+
642
672
it ( 'should allow returning a descriptor' , function ( ) {
643
673
function dec ( target , name , descriptor ) {
644
674
expect ( target ) . to . be . ok ;
@@ -854,6 +884,34 @@ describe('decorators', function(){
854
884
expect ( Example . prop ) . to . be . undefined ;
855
885
} ) ;
856
886
887
+ it ( 'should support mutating an initialzer into an accessor' , function ( ) {
888
+ function dec ( target , name , descriptor ) {
889
+ expect ( target ) . to . be . ok ;
890
+ expect ( name ) . to . eql ( "prop" ) ;
891
+ expect ( descriptor ) . to . be . an ( 'object' ) ;
892
+
893
+ let { initializer} = descriptor ;
894
+ delete descriptor . initializer ;
895
+ delete descriptor . writable ;
896
+
897
+ let value ;
898
+ descriptor . get = function ( ) {
899
+ if ( initializer ) {
900
+ value = '__' + initializer . call ( this ) + '__' ;
901
+ initializer = null ;
902
+ }
903
+ return value ;
904
+ } ;
905
+ }
906
+
907
+ class Example {
908
+ @dec
909
+ static prop = 3 ;
910
+ }
911
+
912
+ expect ( Example . prop ) . to . eql ( '__3__' ) ;
913
+ } ) ;
914
+
857
915
it ( 'should allow returning a descriptor' , function ( ) {
858
916
function dec ( target , name , descriptor ) {
859
917
expect ( target ) . to . be . ok ;
@@ -1405,6 +1463,34 @@ describe('decorators', function(){
1405
1463
} ;
1406
1464
} ) ;
1407
1465
1466
+ it ( 'should support mutating an initialzer into an accessor' , function ( ) {
1467
+ function dec ( target , name , descriptor ) {
1468
+ expect ( target ) . to . be . ok ;
1469
+ expect ( name ) . to . eql ( "prop" ) ;
1470
+ expect ( descriptor ) . to . be . an ( 'object' ) ;
1471
+
1472
+ let { initializer} = descriptor ;
1473
+ delete descriptor . initializer ;
1474
+ delete descriptor . writable ;
1475
+
1476
+ let value ;
1477
+ descriptor . get = function ( ) {
1478
+ if ( initializer ) {
1479
+ value = '__' + initializer . call ( this ) + '__' ;
1480
+ initializer = null ;
1481
+ }
1482
+ return value ;
1483
+ } ;
1484
+ }
1485
+
1486
+ let inst = {
1487
+ @dec
1488
+ prop : 3
1489
+ } ;
1490
+
1491
+ expect ( inst . prop ) . to . eql ( '__3__' ) ;
1492
+ } ) ;
1493
+
1408
1494
it ( 'should allow returning a descriptor' , function ( ) {
1409
1495
function dec ( target , name , descriptor ) {
1410
1496
expect ( target ) . to . be . ok ;
0 commit comments