@@ -14,9 +14,6 @@ const normalizeOptions = options => ({
1414 || defaultWrappersConfig ,
1515} ) ;
1616
17- const findContainer = ( path , t ) => ( path . node . body
18- ? path : findContainer ( path . parentPath , t ) ) ;
19-
2017const findCandidateNameForExpression = ( path ) => {
2118 let id ;
2219 path . find ( ( currentPath ) => {
@@ -67,14 +64,26 @@ module.exports = function displayNamePlugin(babel, options = {}) {
6764 } ) ;
6865
6966 if ( args && displayName ) {
70- const nodes = t . expressionStatement (
71- t . assignmentExpression (
72- '=' ,
73- t . memberExpression ( nameNodeId , t . identifier ( 'displayName' ) ) ,
74- t . stringLiteral ( displayName ) ,
67+ const tempId = path . scope . generateUidIdentifier ( ) ;
68+ path . replaceWith (
69+ t . callExpression (
70+ t . arrowFunctionExpression (
71+ [ t . cloneNode ( tempId ) ] ,
72+ t . blockStatement ( [
73+ t . expressionStatement (
74+ t . assignmentExpression (
75+ '=' ,
76+ t . memberExpression ( t . cloneNode ( tempId ) , t . identifier ( 'displayName' ) ) ,
77+ t . stringLiteral ( displayName ) ,
78+ ) ,
79+ ) ,
80+ t . returnStatement ( t . cloneNode ( tempId ) ) ,
81+ ] ) ,
82+ ) ,
83+ [ path . node ] ,
7584 ) ,
7685 ) ;
77- findContainer ( path , t ) . pushContainer ( 'body' , nodes ) ;
86+ path . skip ( ) ;
7887 }
7988 } ;
8089
0 commit comments