@@ -57,16 +57,22 @@ async function unloadModule(path) {
5757 delete System . loads [ normalizedPath ]
5858}
5959
60+ function decorateFunction ( toBeDecorated , decorator ) {
61+ return function ( ) {
62+ const result = toBeDecorated ( ...arguments ) ;
63+ decorator ( result ) ;
64+ return result ;
65+ }
66+ }
67+
6068
6169async function importPlugin ( url ) {
6270 const module = await System . import ( url ) ;
6371 const plugin = module . default ;
64-
65- const modifiedPlugin = function ( ...args ) {
66- const result = plugin ( ...args )
72+
73+ const modifiedPlugin = decorateFunction ( plugin , result => {
6774 result . name = result . name || 'Please name your plugin!' ;
68- return result ;
69- }
75+ } ) ;
7076
7177 return modifiedPlugin ;
7278}
@@ -93,6 +99,16 @@ self.onmessage = function(msg) {
9399 const Trace = imports [ 0 ] . default ;
94100 const babel = imports [ 1 ] . default . babel ;
95101 const wrapAST = imports [ 2 ] . default ;
102+
103+ babel . traverse . NodePath = function ( ) {
104+ debugger
105+
106+ const result = babel . traverse . NodePath ( ...arguments ) ;
107+ result . traverse = function ( ) {
108+ debugger
109+ result . traverse ( ...arguments ) ;
110+ } ;
111+ }
96112
97113 const config = {
98114 filename : 'tmpfile.js' ,
@@ -130,8 +146,34 @@ self.onmessage = function(msg) {
130146 trace . leavePlugin ( pluginAlias ) ;
131147 }
132148 } ;
149+
150+ config . plugins = config . plugins
151+ . map ( plugin => decorateFunction ( plugin , result => {
152+ if ( result . pre ) {
153+ const oldPre = result . pre ;
154+ result . pre = function ( path ) {
155+ const oldTraverse = path . prototype . traverse ;
156+ path . prototype . traverse = function ( ) {
157+ trace . startTraversePlugin ( ) ;
158+ oldTraverse ( ...arguments ) ;
159+ trace . endTraversePlugin ( ) ;
160+ }
161+ oldPre ( ...arguments ) ;
162+ } ;
163+ } else {
164+ result . pre = function ( path ) {
165+ const oldTraverse = path . prototype . traverse ;
166+ path . prototype . traverse = function ( ) {
167+ trace . startTraversePlugin ( ) ;
168+ oldTraverse ( ...arguments ) ;
169+ trace . endTraversePlugin ( ) ;
170+ }
171+ } ;
172+ }
173+ } ) ) ;
133174
134175 trace . startTraversion ( ) ;
176+ debugger
135177 const ast = babel . transform ( msg . data . source , enumerationConfig ( createTraceID ) ) . ast ;
136178 const oldASTAsString = JSON . stringify ( ast ) ;
137179
0 commit comments