@@ -3,28 +3,12 @@ import * as t from '@babel/types';
3
3
4
4
import type { Metadata } from '../types' ;
5
5
import { buildCompiledCloneElement } from '../utils/build-compiled-component' ;
6
- import { buildCssVariables } from '../utils/build-css-variables' ;
7
6
import { buildCss } from '../utils/css-builders' ;
8
7
import { getRuntimeClassNameLibrary } from '../utils/get-runtime-class-name-library' ;
9
8
import { resolveIdentifierComingFromDestructuring } from '../utils/resolve-binding' ;
10
9
import { transformCssItems } from '../utils/transform-css-items' ;
11
10
import type { CSSOutput } from '../utils/types' ;
12
11
13
- /**
14
- * Handles style prop value. If variables are present it will replace its value with it
15
- * otherwise will add undefined.
16
- *
17
- * @param variables CSS variables prop to be placed as inline styles
18
- * @param path Any Expression path
19
- */
20
- const handleStyleProp = ( variables : CSSOutput [ 'variables' ] , path : NodePath < t . Expression > ) => {
21
- const styleValue = variables . length
22
- ? t . objectExpression ( buildCssVariables ( variables ) )
23
- : t . identifier ( 'undefined' ) ;
24
-
25
- path . replaceWith ( styleValue ) ;
26
- } ;
27
-
28
12
/**
29
13
* Extracts styles from an expression.
30
14
*
@@ -128,9 +112,13 @@ export const visitCloneElementPath = (path: NodePath<t.CallExpression>, meta: Me
128
112
// find ancestor cloneElement callExpression
129
113
const ancestorPath = path . findParent (
130
114
( p ) =>
131
- p . isCallExpression ( ) &&
132
- t . isIdentifier ( p . node . callee ) &&
133
- p . node . callee . name === 'cloneElement'
115
+ ( p . isCallExpression ( ) &&
116
+ t . isIdentifier ( p . node . callee ) &&
117
+ p . node . callee . name === meta . state . reactImports ?. cloneElement ) ||
118
+ ( p . isCallExpression ( ) &&
119
+ t . isMemberExpression ( p . node . callee ) &&
120
+ t . isIdentifier ( p . node . callee . property ) &&
121
+ p . node . callee . property . name === 'cloneElement' )
134
122
) as NodePath < t . CallExpression > ;
135
123
136
124
if ( ! ancestorPath ) {
@@ -140,44 +128,4 @@ export const visitCloneElementPath = (path: NodePath<t.CallExpression>, meta: Me
140
128
ancestorPath . replaceWith ( buildCompiledCloneElement ( ancestorPath . node , builtCss , meta ) ) ;
141
129
} ,
142
130
} ) ;
143
-
144
- // // Second pass to replace all usages of `style`.
145
- // path.traverse({
146
- // Expression(path) {
147
- // if (t.isIdentifier(path.node)) {
148
- // if (path.parentPath.isProperty()) {
149
- // return;
150
- // }
151
-
152
- // // style={style}
153
- // if (path.node.name === 'style' && path.scope.hasOwnBinding('style')) {
154
- // handleStyleProp(collectedVariables, path);
155
- // }
156
-
157
- // // style={style} rename prop
158
- // if (path.scope.hasOwnBinding(path.node.name)) {
159
- // const binding = path.scope.getBinding(path.node.name)?.path.node;
160
-
161
- // if (
162
- // !!resolveIdentifierComingFromDestructuring({
163
- // name: 'style',
164
- // node: binding as t.Expression,
165
- // })
166
- // ) {
167
- // handleStyleProp(collectedVariables, path);
168
- // }
169
- // }
170
- // } else if (t.isMemberExpression(path.node)) {
171
- // // filter out invalid calls like dontexist.style
172
- // if (t.isIdentifier(path.node.object) && !path.scope.hasOwnBinding(path.node.object.name)) {
173
- // return;
174
- // }
175
-
176
- // // style={props.style}
177
- // if (t.isIdentifier(path.node.property) && path.node.property.name === 'style') {
178
- // handleStyleProp(collectedVariables, path);
179
- // }
180
- // }
181
- // },
182
- // });
183
131
} ;
0 commit comments