@@ -22,8 +22,7 @@ export default function({ types: t }) {
2222 }
2323
2424 function callOnTrace ( methodName , args = [ ] , shouldBeStatement = false ) {
25- let call = t . callExpression ( t . memberExpression ( t . identifier ( Trace . traceIdentifierName ) , t . identifier ( methodName ) ) ,
26- args ) ;
25+ let call = t . callExpression ( t . memberExpression ( t . identifier ( Trace . traceIdentifierName ) , t . identifier ( methodName ) ) , args ) ;
2726 if ( shouldBeStatement ) {
2827 call = t . expressionStatement ( call ) ;
2928 }
@@ -74,7 +73,7 @@ export default function({ types: t }) {
7473 } ,
7574 post ( ) {
7675 if ( pluginDefinedTrace ) {
77- delete window [ Trace . traceIdentifierName ] ;
76+ window [ Trace . traceIdentifierName ] = undefined ;
7877 }
7978 } ,
8079 visitor : {
@@ -86,32 +85,41 @@ export default function({ types: t }) {
8685 return ;
8786 }
8887
89-
9088 path . node . alreadyVisited = true ;
9189 let callee = path . get ( 'callee' ) ;
9290 let name ;
9391
9492 if ( t . isMemberExpression ( callee ) ) {
95- callee . node . computed = true ;
96- callee = path . get ( 'callee.property' ) ;
93+ if ( callee . node . computed ) {
94+ callee = path . get ( 'callee.property' ) ;
9795
98- name = callee . node . name || 'anonymous function' ;
96+ name = callee . node ;
97+ } else {
98+ callee . node . computed = true ;
99+ callee = path . get ( 'callee.property' ) ;
100+
101+ name = t . stringLiteral ( callee . node . name || 'anonymous function' ) ;
102+ }
103+
104+
105+
106+ const loc = location ( callee . node , this ) ;
99107
100108 const aboutToEnter = callOnTrace ( 'aboutToEnter' ,
101109 [
102- location ( callee . node , this ) ,
103- t . stringLiteral ( name )
110+ loc ,
111+ name
104112 ] ) ;
105- callee . replaceWith ( t . stringLiteral ( name ) ) ;
113+ callee . replaceWith ( name ) ;
106114 callee . insertBefore ( aboutToEnter ) ;
107115
108116 const left = callOnTrace ( 'left' ,
109117 [
110- location ( path . node , this ) ,
118+ loc ,
111119 path . node
112120 ] ) ;
113121
114- path . replaceWith ( left )
122+ path . replaceWith ( left )
115123 return ;
116124 } else if ( t . isFunctionExpression ( callee ) ) {
117125 name = callee . node . id . name || 'anonymous function' ;
@@ -154,7 +162,7 @@ export default function({ types: t }) {
154162 ] ) ) ;
155163 } else {
156164 modifyFunction ( 'anonymous function' , path , this ) ;
157- }
165+ }
158166 } ,
159167 "ClassMethod|ObjectMethod" ( path ) {
160168 const key = path . node . key ;
0 commit comments