Skip to content

Commit

Permalink
WIP stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Mar 6, 2019
1 parent e61677d commit 2f410be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
12 changes: 10 additions & 2 deletions packages/babel-plugin-emotion/src/css-macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ export const transformCssCallExpression = ({
}
}

export let coreCssTransformer = ({ state, babel, importPath, reference }) => {
reference.replaceWith(addImport(state, importPath, 'default', 'css'))
export let coreCssTransformer = ({
state,
babel,
importPath,
reference,
importSpecifierName
}) => {
reference.replaceWith(
addImport(state, importPath, importSpecifierName, 'css')
)
transformCssCallExpression({ babel, state, path: reference.parentPath })
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-emotion/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default function(babel: *) {
)
let macros = {}
let jsxCoreImports = [['@emotion/core', 'jsx']]
Object.keys(state.opts.importMap).forEach(packageName => {
Object.keys(state.opts.importMap || {}).forEach(packageName => {
let value = state.opts.importMap[packageName]
let transformers = {}
Object.keys(value).forEach(localExportName => {
Expand Down
13 changes: 7 additions & 6 deletions packages/babel-plugin-emotion/src/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
createTransformerMacro
} from './utils'

let createEmotionTransformer = (imported: string, isPure: boolean) => ({
let createEmotionTransformer = (isPure: boolean) => ({
state,
babel,
importPath,
reference
reference,
importSpecifierName
}: Object) => {
const path = reference.parentPath

reference.replaceWith(addImport(state, importPath, imported))
reference.replaceWith(addImport(state, importPath, importSpecifierName))
if (isPure) {
path.addComment('leading', '#__PURE__')
}
Expand All @@ -29,9 +30,9 @@ let createEmotionTransformer = (imported: string, isPure: boolean) => ({
}

export let transformers = {
css: createEmotionTransformer('css', true),
injectGlobal: createEmotionTransformer('injectGlobal', false),
keyframes: createEmotionTransformer('keyframes', true)
css: createEmotionTransformer(true),
injectGlobal: createEmotionTransformer(false),
keyframes: createEmotionTransformer(true)
}

export let createEmotionMacro = (instancePath: string) =>
Expand Down
16 changes: 12 additions & 4 deletions packages/babel-plugin-emotion/src/styled-macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ export let styledTransformer = ({
babel,
importPath,
reference,
options: { baseImportPath = importPath, isWeb }
importSpecifierName,
options: {
baseImport: [
baseImportPath = importPath,
baseImportSpecifierName = importSpecifierName
] = [],
isWeb
}
}: Object) => {
let getStyledIdentifier = () => {
return addImport(state, baseImportPath, 'default', 'styled')
return addImport(state, baseImportPath, baseImportSpecifierName, 'styled')
}
let getOriginalImportPathStyledIdentifier = () => {
return addImport(state, importPath, 'default', 'styled')
return addImport(state, importPath, importSpecifierName, 'styled')
}
let t = babel.types
let isCall = false
Expand Down Expand Up @@ -80,6 +87,7 @@ export let styledTransformer = ({
export let createStyledMacro = ({
importPath,
originalImportPath = importPath,
baseImportSpecifierName = 'default',
isWeb
}: {
importPath: string,
Expand All @@ -91,7 +99,7 @@ export let createStyledMacro = ({
default: [
styledTransformer,
{
baseImportPath: importPath,
baseImport: [importPath, baseImportSpecifierName],
isWeb
}
]
Expand Down

0 comments on commit 2f410be

Please sign in to comment.