Socket
Socket
Sign inDemoInstall

babel-plugin-emotion

Package Overview
Dependencies
55
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.2.2 to 7.3.0

3

package.json
{
"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 => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc