@@ -148,22 +148,22 @@ export default function(babel: *, options: *) {
148148 } ,
149149 Program ( path : * , state : * ) {
150150 let macros = { }
151- let jsxCoreImports : Array < {
151+ let jsxReactImports : Array < {
152152 importSource : string ,
153153 export : string ,
154154 cssExport : string
155155 } > = [
156156 { importSource : '@emotion/react' , export : 'jsx' , cssExport : 'css' }
157157 ]
158- state . jsxCoreImport = jsxCoreImports [ 0 ]
158+ state . jsxReactImport = jsxReactImports [ 0 ]
159159 Object . keys ( state . opts . importMap || { } ) . forEach ( importSource => {
160160 let value = state . opts . importMap [ importSource ]
161161 let transformers = { }
162162 Object . keys ( value ) . forEach ( localExportName => {
163163 let { canonicalImport, ...options } = value [ localExportName ]
164164 let [ packageName , exportName ] = canonicalImport
165165 if ( packageName === '@emotion/react' && exportName === 'jsx' ) {
166- jsxCoreImports . push ( {
166+ jsxReactImports . push ( {
167167 importSource,
168168 export : localExportName ,
169169 cssExport : getCssExport ( 'jsx' , importSource , value )
@@ -191,7 +191,9 @@ export default function(babel: *, options: *) {
191191 ) {
192192 // this is supposed to override defaultOptions value
193193 // and let correct value to be set if coming in options
194- extraOptions = { styledBaseImport : undefined }
194+ extraOptions = {
195+ styledBaseImport : undefined
196+ }
195197 }
196198
197199 let [ exportTransformer , defaultOptions ] =
@@ -202,7 +204,11 @@ export default function(babel: *, options: *) {
202204
203205 transformers [ localExportName ] = [
204206 exportTransformer ,
205- { ...defaultOptions , ...extraOptions , ...options }
207+ {
208+ ...defaultOptions ,
209+ ...extraOptions ,
210+ ...options
211+ }
206212 ]
207213 } )
208214 macros [ importSource ] = createTransformerMacro ( transformers , {
@@ -217,26 +223,28 @@ export default function(babel: *, options: *) {
217223 '@emotion/css' : vanillaEmotionMacro ,
218224 ...macros
219225 }
220- if ( state . opts . cssPropOptimization === undefined ) {
221- for ( const node of path . node . body ) {
222- if ( t . isImportDeclaration ( node ) ) {
223- let jsxCoreImport = jsxCoreImports . find (
224- thing =>
225- node . source . value === thing . importSource &&
226- node . specifiers . some (
227- x =>
228- t . isImportSpecifier ( x ) && x . imported . name === thing . export
229- )
230- )
231- if ( jsxCoreImport ) {
232- state . transformCssProp = true
233- state . jsxCoreImport = jsxCoreImport
234- break
235- }
226+
227+ for ( const node of path . node . body ) {
228+ if ( t . isImportDeclaration ( node ) ) {
229+ let jsxReactImport = jsxReactImports . find (
230+ thing =>
231+ node . source . value === thing . importSource &&
232+ node . specifiers . some (
233+ x =>
234+ t . isImportSpecifier ( x ) && x . imported . name === thing . export
235+ )
236+ )
237+ if ( jsxReactImport ) {
238+ state . jsxReactImport = jsxReactImport
239+ break
236240 }
237241 }
242+ }
243+
244+ if ( state . opts . cssPropOptimization === false ) {
245+ state . transformCssProp = false
238246 } else {
239- state . transformCssProp = state . opts . cssPropOptimization
247+ state . transformCssProp = true
240248 }
241249
242250 if ( state . opts . sourceMap === false ) {
@@ -262,7 +270,7 @@ export default function(babel: *, options: *) {
262270 state,
263271 babel,
264272 path,
265- cssImport : state . jsxCoreImport
273+ cssImport : state . jsxReactImport
266274 } )
267275 }
268276 }
0 commit comments