11import Trace from 'demos/tom/trace.js' ;
2+ import copyAST from 'demos/tom/copyAST.js' ;
23
3- const excludedProperties = [ 'end' , 'loc' , 'start' , 'traceID' , 'type' ] ;
4-
5- function copy ( value ) {
6- return value ; // JSON.parse(JSON.stringify(value));
7- }
4+ export const excludedProperties = [ 'end' , 'loc' , 'start' , 'traceID' , 'type' ] ;
85
96function createObservingAccessorsOn ( object , propertyName , observer ) {
107 const newPropertyName = '_' + propertyName ;
118 object [ newPropertyName ] = object [ propertyName ] ;
129 Object . defineProperty ( object , propertyName , {
1310 get ( ) { return object [ newPropertyName ] ; } ,
1411 set ( value ) {
15- observer . notify ( object . traceID , propertyName , object [ newPropertyName ] , value ) ;
12+ const pluginRound = window [ Trace . traceIdentifierName ] . pluginRound ;
1613 wrapAST ( value , observer , true ) ;
14+ observer . notify ( object . traceID ,
15+ propertyName ,
16+ copyAST ( object [ newPropertyName ] , pluginRound ) ,
17+ copyAST ( value , pluginRound ) ) ;
1718 object [ newPropertyName ] = value ;
1819 }
1920 } )
@@ -24,8 +25,10 @@ const handler = (observer, key) => {
2425 set : function ( obj , prop , value ) {
2526 // Todo: Reflect.set()
2627 if ( Number . isInteger ( Number . parseInt ( prop ) ) ) {
27- observer . notify ( prop , copy ( obj [ prop ] ) , copy ( value ) , key ) ;
28+ const pluginRound = window [ Trace . traceIdentifierName ] . pluginRound ;
29+ debugger
2830 wrapAST ( value , observer , true ) ;
31+ observer . notify ( prop , copyAST ( obj [ prop ] , pluginRound ) , copyAST ( value , pluginRound ) , key ) ;
2932 }
3033 obj [ prop ] = value ;
3134 return true ;
@@ -37,56 +40,6 @@ function wrappedArray(array, observer, key) {
3740 return new Proxy ( array , handler ( observer , key ) ) ;
3841}
3942
40- function copyUnknownASTParts ( astNode ) {
41- // simply check if the object is an astNode
42- if ( astNode && astNode . type ) {
43- // if already in AST return only a reference
44- if ( astNode . traceID ) {
45- return astNode . traceID ;
46- }
47-
48- const objectCopy = { } ;
49-
50- const keys = Object . keys ( astNode ) . filter ( key => ! excludedProperties . includes ( key ) ) ;
51- for ( const key of keys ) {
52- const value = astNode [ key ] ;
53-
54- if ( Array . isArray ( value ) ) {
55- const copiedArray = [ ] ;
56- objectCopy [ key ] = copiedArray ;
57-
58- for ( const entry of value ) {
59- copiedArray . push ( copyUnknownASTParts ( entry ) ) ;
60- }
61-
62- continue ;
63- }
64-
65- if ( value === null ) {
66- objectCopy [ key ] = value ;
67- continue ;
68- }
69-
70- switch ( typeof value ) {
71- case 'function' :
72- // ignore functions
73- break ;
74- case 'object' :
75- // assume it is an astNode
76- objectCopy [ key ] = copyUnknownASTParts ( value ) ;
77- break ;
78- default :
79- objectCopy [ key ] = value ;
80- }
81- }
82-
83- return objectCopy ;
84- } else {
85- // probably not an AST node => do a generic copy
86- return JSON . parse ( JSON . stringify ( astNode ) ) ;
87- }
88- }
89-
9043export default function wrapAST ( astNode , observer , onlyUnknownNodes ) {
9144 // simply check if the object is an astNode
9245 if ( astNode && astNode . type ) {
0 commit comments