@@ -93,27 +93,72 @@ const getDebugId = (path: NodePath<t.CallExpression>) => {
93
93
return ;
94
94
}
95
95
96
- // Special case: Handle `export const [themeClass, vars] = createTheme({});`
97
- // when it's already been compiled into this :
96
+ // Special case 1 : Handle `export const [themeClass, vars] = createTheme({});`
97
+ // when it's already been compiled into one of the following forms :
98
98
//
99
99
// var _createTheme = createTheme({}),
100
100
// _createTheme2 = _slicedToArray(_createTheme, 2),
101
101
// themeClass = _createTheme2[0],
102
102
// vars = _createTheme2[1];
103
- if (
104
- t . isVariableDeclaration ( firstRelevantParentPath . parent ) &&
105
- firstRelevantParentPath . parent . declarations . length === 4
106
- ) {
107
- const [ themeDeclarator , , classNameDeclarator ] =
108
- firstRelevantParentPath . parent . declarations ;
109
-
110
- if (
111
- t . isCallExpression ( themeDeclarator . init ) &&
112
- t . isIdentifier ( themeDeclarator . init . callee , { name : 'createTheme' } ) &&
113
- t . isVariableDeclarator ( classNameDeclarator ) &&
114
- t . isIdentifier ( classNameDeclarator . id )
115
- ) {
116
- return classNameDeclarator . id . name ;
103
+ if ( t . isVariableDeclaration ( firstRelevantParentPath . parent ) ) {
104
+ if ( firstRelevantParentPath . parent . declarations . length === 4 ) {
105
+ const [ themeDeclarator , , classNameDeclarator ] =
106
+ firstRelevantParentPath . parent . declarations ;
107
+
108
+ if (
109
+ t . isCallExpression ( themeDeclarator . init ) &&
110
+ t . isIdentifier ( themeDeclarator . init . callee , { name : 'createTheme' } ) &&
111
+ t . isIdentifier ( classNameDeclarator . id )
112
+ ) {
113
+ return classNameDeclarator . id . name ;
114
+ }
115
+ }
116
+ // alternative compiled form:
117
+ //
118
+ // var ref = _slicedToArray(createTheme({}), 2);
119
+ // export var themeClass = ref[0],
120
+ // vars = ref[1];
121
+ else if ( firstRelevantParentPath . parent . declarations . length === 1 ) {
122
+ const [ themeDeclarator ] = firstRelevantParentPath . parent . declarations ;
123
+ const nextSibling =
124
+ firstRelevantParentPath . parentPath ?. getNextSibling ( ) . node ;
125
+
126
+ if (
127
+ t . isCallExpression ( themeDeclarator . init ) &&
128
+ t . isCallExpression ( themeDeclarator . init . arguments [ 0 ] ) &&
129
+ t . isIdentifier ( themeDeclarator . init . arguments [ 0 ] . callee , {
130
+ name : 'createTheme' ,
131
+ } ) &&
132
+ t . isExportNamedDeclaration ( nextSibling ) &&
133
+ t . isVariableDeclaration ( nextSibling . declaration ) &&
134
+ t . isVariableDeclarator ( nextSibling . declaration . declarations [ 0 ] ) &&
135
+ t . isIdentifier ( nextSibling . declaration . declarations [ 0 ] . id )
136
+ ) {
137
+ return nextSibling . declaration . declarations [ 0 ] . id . name ;
138
+ }
139
+ }
140
+ // Special case 2: Handle `const [themeClass, vars] = createTheme({});
141
+ // export { themeClass, vars };`
142
+ // when compiled into the following:
143
+ //
144
+ // var ref = _slicedToArray(createTheme({}), 2),
145
+ // myThemeClass = ref[0],
146
+ // vars = ref[1];
147
+ // export { themeClass, vars };
148
+ else if ( firstRelevantParentPath . parent . declarations . length === 3 ) {
149
+ const [ themeDeclarator , classNameDeclarator ] =
150
+ firstRelevantParentPath . parent . declarations ;
151
+
152
+ if (
153
+ t . isCallExpression ( themeDeclarator . init ) &&
154
+ t . isCallExpression ( themeDeclarator . init . arguments [ 0 ] ) &&
155
+ t . isIdentifier ( themeDeclarator . init . arguments [ 0 ] . callee , {
156
+ name : 'createTheme' ,
157
+ } ) &&
158
+ t . isIdentifier ( classNameDeclarator . id )
159
+ ) {
160
+ return classNameDeclarator . id . name ;
161
+ }
117
162
}
118
163
}
119
164
0 commit comments