@@ -1767,25 +1767,44 @@ Document.prototype.$__dirty = function() {
1767
1767
*/
1768
1768
1769
1769
function compile ( tree , proto , prefix , options ) {
1770
- var keys = Object . keys ( tree ) ,
1771
- i = keys . length ,
1772
- limb ,
1773
- key ;
1770
+ var keys = Object . keys ( tree ) ;
1771
+ var i = keys . length ;
1772
+ var len = keys . length ;
1773
+ var limb ;
1774
+ var key ;
1774
1775
1775
- while ( i -- ) {
1776
- key = keys [ i ] ;
1777
- limb = tree [ key ] ;
1778
-
1779
- defineKey ( key ,
1780
- ( ( utils . getFunctionName ( limb . constructor ) === 'Object'
1781
- && Object . keys ( limb ) . length )
1782
- && ( ! limb [ options . typeKey ] || ( options . typeKey === 'type' && limb . type . type ) )
1783
- ? limb
1784
- : null )
1785
- , proto
1786
- , prefix
1787
- , keys
1788
- , options ) ;
1776
+ if ( options . retainKeyOrder ) {
1777
+ for ( i = 0 ; i < len ; ++ i ) {
1778
+ key = keys [ i ] ;
1779
+ limb = tree [ key ] ;
1780
+
1781
+ defineKey ( key ,
1782
+ ( ( utils . getFunctionName ( limb . constructor ) === 'Object'
1783
+ && Object . keys ( limb ) . length )
1784
+ && ( ! limb [ options . typeKey ] || ( options . typeKey === 'type' && limb . type . type ) )
1785
+ ? limb
1786
+ : null )
1787
+ , proto
1788
+ , prefix
1789
+ , keys
1790
+ , options ) ;
1791
+ }
1792
+ } else {
1793
+ while ( i -- ) {
1794
+ key = keys [ i ] ;
1795
+ limb = tree [ key ] ;
1796
+
1797
+ defineKey ( key ,
1798
+ ( ( utils . getFunctionName ( limb . constructor ) === 'Object'
1799
+ && Object . keys ( limb ) . length )
1800
+ && ( ! limb [ options . typeKey ] || ( options . typeKey === 'type' && limb . type . type ) )
1801
+ ? limb
1802
+ : null )
1803
+ , proto
1804
+ , prefix
1805
+ , keys
1806
+ , options ) ;
1807
+ }
1789
1808
}
1790
1809
}
1791
1810
@@ -1796,7 +1815,7 @@ function getOwnPropertyDescriptors(object) {
1796
1815
1797
1816
Object . getOwnPropertyNames ( object ) . forEach ( function ( key ) {
1798
1817
result [ key ] = Object . getOwnPropertyDescriptor ( object , key ) ;
1799
- result [ key ] . enumerable = true ;
1818
+ result [ key ] . enumerable = [ 'isNew' , '$__' , 'errors' , '_doc' ] . indexOf ( key ) === - 1 ;
1800
1819
} ) ;
1801
1820
1802
1821
return result ;
@@ -1844,7 +1863,7 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
1844
1863
}
1845
1864
1846
1865
Object . defineProperty ( nested , 'toObject' , {
1847
- enumerable : true ,
1866
+ enumerable : false ,
1848
1867
configurable : true ,
1849
1868
writable : false ,
1850
1869
value : function ( ) {
@@ -1853,7 +1872,7 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
1853
1872
} ) ;
1854
1873
1855
1874
Object . defineProperty ( nested , 'toJSON' , {
1856
- enumerable : true ,
1875
+ enumerable : false ,
1857
1876
configurable : true ,
1858
1877
writable : false ,
1859
1878
value : function ( ) {
@@ -1862,7 +1881,7 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
1862
1881
} ) ;
1863
1882
1864
1883
Object . defineProperty ( nested , '$__isNested' , {
1865
- enumerable : true ,
1884
+ enumerable : false ,
1866
1885
configurable : true ,
1867
1886
writable : false ,
1868
1887
value : true
0 commit comments