babel-plugin-emotion
Advanced tools
Comparing version 7.2.2 to 7.3.0
{ | ||
"name": "babel-plugin-emotion", | ||
"version": "7.2.2", | ||
"version": "7.3.0", | ||
"description": "A recommended babel preprocessing plugin for emotion, the The Next Generation of CSS-in-JS.", | ||
@@ -17,2 +17,3 @@ "main": "lib/index.js", | ||
"autoprefixer": "^7.1.2", | ||
"babel-macros": "^1.0.2", | ||
"babel-plugin-syntax-jsx": "^6.18.0", | ||
@@ -19,0 +20,0 @@ "emotion-utils": "^7.2.2", |
@@ -13,3 +13,3 @@ export default function(path, state, t) { | ||
if (name === 'css') { | ||
if (name === state.importedNames.css) { | ||
cssPath = attrPath | ||
@@ -95,7 +95,9 @@ } | ||
if (!state.cssPropIdentifier) { | ||
state.cssPropIdentifier = path.scope.generateUidIdentifier('css') | ||
state.cssPropIdentifier = path.scope.generateUidIdentifier( | ||
state.importedNames.css | ||
) | ||
} | ||
return state.cssPropIdentifier | ||
} else { | ||
return t.identifier('css') | ||
return t.identifier(state.importedNames.css) | ||
} | ||
@@ -102,0 +104,0 @@ } |
@@ -231,2 +231,7 @@ // @flow weak | ||
const defaultImportedNames = { | ||
styled: 'styled', | ||
css: 'css' | ||
} | ||
export default function(babel) { | ||
@@ -241,2 +246,26 @@ const { types: t } = babel | ||
enter(path, state) { | ||
state.importedNames = { | ||
...defaultImportedNames, | ||
...state.opts.importedNames | ||
} | ||
state.file.metadata.modules.imports.forEach( | ||
({ source, imported, specifiers }) => { | ||
if (source.indexOf('emotion') !== -1) { | ||
const importedNames = specifiers | ||
.filter(v => ['default', 'css'].includes(v.imported)) | ||
.reduce( | ||
(acc, { imported, local }) => ({ | ||
...acc, | ||
[imported === 'default' ? 'styled' : imported]: local | ||
}), | ||
defaultImportedNames | ||
) | ||
state.importedNames = { | ||
...importedNames, | ||
...state.opts.importedNames | ||
} | ||
} | ||
} | ||
) | ||
state.extractStatic = | ||
@@ -300,6 +329,6 @@ // path.hub.file.opts.filename !== 'unknown' || | ||
(t.isCallExpression(path.node.callee) && | ||
path.node.callee.callee.name === 'styled') || | ||
path.node.callee.callee.name === state.importedNames.styled) || | ||
(t.isMemberExpression(path.node.callee) && | ||
t.isIdentifier(path.node.callee.object) && | ||
path.node.callee.object.name === 'styled') | ||
path.node.callee.object.name === state.importedNames.styled) | ||
) { | ||
@@ -314,7 +343,11 @@ const identifier = t.isCallExpression(path.node.callee) | ||
if ( | ||
path.node.callee.name === 'css' && | ||
path.node.callee.name === state.importedNames.css && | ||
!path.node.arguments[1] && | ||
path.node.arguments[0] | ||
) { | ||
replaceCssObjectCallExpression(path, t.identifier('css'), t) | ||
replaceCssObjectCallExpression( | ||
path, | ||
t.identifier(state.importedNames.css), | ||
t | ||
) | ||
} | ||
@@ -331,3 +364,3 @@ } catch (e) { | ||
t.isMemberExpression(path.node.tag) && | ||
path.node.tag.object.name === 'styled' | ||
path.node.tag.object.name === state.importedNames.styled | ||
) { | ||
@@ -346,3 +379,3 @@ path.replaceWith( | ||
t.isCallExpression(path.node.tag) && | ||
path.node.tag.callee.name === 'styled' | ||
path.node.tag.callee.name === state.importedNames.styled | ||
) { | ||
@@ -359,4 +392,9 @@ path.replaceWith( | ||
} else if (t.isIdentifier(path.node.tag)) { | ||
if (path.node.tag.name === 'css') { | ||
replaceCssWithCallExpression(path, t.identifier('css'), state, t) | ||
if (path.node.tag.name === state.importedNames.css) { | ||
replaceCssWithCallExpression( | ||
path, | ||
t.identifier(state.importedNames.css), | ||
state, | ||
t | ||
) | ||
} else if (path.node.tag.name === 'keyframes') { | ||
@@ -363,0 +401,0 @@ replaceCssWithCallExpression( |
@@ -8,4 +8,7 @@ import { | ||
import { omit } from 'emotion-utils' | ||
import { createMacro } from 'babel-macros' | ||
module.exports = function macro(options) { | ||
module.exports = createMacro(macro) | ||
function macro(options) { | ||
const { references, state, babel: { types: t } } = options | ||
@@ -12,0 +15,0 @@ if (!state.inline) state.inline = true |
@@ -7,4 +7,7 @@ import { | ||
import { forEach, keys } from 'emotion-utils' | ||
import { createMacro } from 'babel-macros' | ||
module.exports = function macro({ references, state, babel: { types: t } }) { | ||
module.exports = createMacro(macro) | ||
function macro({ references, state, babel: { types: t } }) { | ||
if (!state.inline) state.inline = true | ||
@@ -11,0 +14,0 @@ forEach(keys(references), referenceKey => { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
0
38034
8
9
1190
+ Addedbabel-macros@^1.0.2
+ Addedargparse@1.0.10(transitive)
+ Addedbabel-macros@1.2.0(transitive)
+ Addedcosmiconfig@3.1.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-directory@0.3.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedparse-json@3.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedsprintf-js@1.0.3(transitive)