@@ -76,18 +76,36 @@ function decorateNodePathTraverse(plugin, trace) {
7676 for ( const name in visitors ) {
7777 if ( typeof visitors [ name ] === 'function' ) {
7878 const fn = visitors [ name ] ;
79- newVisitors [ name ] = function ( ) {
80- trace . startTraversePlugin ( name ) ;
81- fn ( ...arguments ) ;
79+ newVisitors [ name ] = function ( path , ... rest ) {
80+ trace . startTraversePlugin ( name , path . node . traceID ) ;
81+ fn ( path , ...rest ) ;
8282 trace . endTraversePlugin ( name ) ;
8383 } ;
8484 } else if ( typeof visitors [ name ] === 'object' ) {
85- debugger
85+ const obj = visitors [ name ] ;
86+
87+ // Todo: what is if already decorated
88+ if ( obj . enter ) {
89+ obj . enter = obj . enter . map ( fn => function ( path , ...rest ) {
90+ trace . startTraversePlugin ( name , path . node . traceID ) ;
91+ fn ( path , ...rest ) ;
92+ trace . endTraversePlugin ( name ) ;
93+ } )
94+ }
95+
96+ if ( obj . exit ) {
97+ obj . exit = obj . exit . map ( fn => function ( path , ...rest ) {
98+ trace . startTraversePlugin ( name , path . node . traceID ) ;
99+ fn ( path , ...rest ) ;
100+ trace . endTraversePlugin ( name ) ;
101+ } )
102+ }
103+
104+ newVisitors [ name ] = obj ;
86105 }
87106
88107 }
89108
90- visitors = newVisitors ;
91109 oldTraverse . call ( this , newVisitors , ...rest ) ;
92110
93111 }
@@ -116,8 +134,8 @@ async function importPlugin(url) {
116134 return modifiedPlugin ;
117135}
118136
119- function importPlugins ( urls ) {
120- return Promise . all ( urls . map ( url => importPlugin ( url ) ) )
137+ function importPlugins ( pluginData ) {
138+ return Promise . all ( pluginData . map ( ( { url, data } ) => importPlugin ( url ) ) )
121139 . then ( plugins => {
122140 let counter = 0 ;
123141 for ( const plugin of plugins ) {
@@ -162,16 +180,16 @@ self.onmessage = function(msg) {
162180 return trace . createTraceID ( ) ;
163181 }
164182
165- importPlugins ( msg . data . urls )
183+ importPlugins ( msg . data . pluginData )
166184 . then ( function ( modules ) {
167185 config . plugins = modules ;
168186 config . sourceFileName = 'tmpfile.js' ;
169187 config . sourceMaps = true ;
170188
171189 config . wrapPluginVisitorMethod = ( pluginAlias , visitorType , callback ) => {
172- return ( ...args ) => {
173- trace . enterPlugin ( pluginAlias ) ;
174- callback ( ...args ) ;
190+ return ( path , ...rest ) => {
191+ trace . enterPlugin ( pluginAlias , path . node . traceID ) ;
192+ callback ( path , ...rest ) ;
175193 trace . leavePlugin ( pluginAlias ) ;
176194 }
177195 } ;
0 commit comments