Socket
Socket
Sign inDemoInstall

babel-plugin-styled-components

Package Overview
Dependencies
Maintainers
3
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-styled-components - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1-test

34

lib/visitors/transpileCssProp.js

@@ -108,4 +108,5 @@ "use strict";

if (!css) return;
elem.node.attributes = elem.node.attributes.filter(attr => attr !== path.node);
if (!css) return; // strip off css prop from final output
elem.node.attributes = elem.node.attributes.filter(x => t.isJSXAttribute(x) ? x.name.name !== 'css' : false);
elem.node.name = t.jSXIdentifier(id.name);

@@ -132,3 +133,4 @@

t.isIdentifier(property.key) && path.scope.hasBinding(property.key.name) && ( // but not a object reference shorthand like css={{ color }}
t.isIdentifier(property.value) ? property.key.name !== property.value.name : true)) {
t.isIdentifier(property.value) ? property.key.name !== property.value.name : true) && // and not a tricky expression
!t.isLogicalExpression(property.value) && !t.isConditionalExpression(property.value)) {
replaceObjectWithPropFunction = true;

@@ -160,5 +162,25 @@ const identifier = getLocalIdentifier(path);

replaceObjectWithPropFunction = true;
const identifier = getLocalIdentifier(path);
elem.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(identifier.name), t.jSXExpressionContainer(property.value)));
acc.push(t.objectProperty(property.key, t.memberExpression(p, identifier)));
if ( // handle tricky expressions
t.isConditionalExpression(property.value) || t.isLogicalExpression(property.value)) {
const jSXIdentifier = getLocalIdentifier(path);
const injectedIdentifier = getLocalIdentifier(path);
let insertionPoint = elem;
while (insertionPoint.key !== 'body') {
insertionPoint = insertionPoint.parentPath;
} // convert complicated expressions into hoisted local variables
// TODO: add logic to put the injected variables just above JSXOpeningElement instead of at the root in case there is
// any variable manipulation happening
insertionPoint.unshiftContainer('body', t.variableDeclaration('var', [t.variableDeclarator(injectedIdentifier, property.value)]));
elem.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(jSXIdentifier.name), t.jSXExpressionContainer(injectedIdentifier))); // now push the properties back into the assembled object
acc.push(t.objectProperty(t.identifier(property.key.name), t.memberExpression(p, jSXIdentifier)));
} else {
const identifier = getLocalIdentifier(path);
elem.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(identifier.name), t.jSXExpressionContainer(property.value)));
acc.push(t.objectProperty(property.key, t.memberExpression(p, identifier)));
}
} else {

@@ -165,0 +187,0 @@ // some sort of primitive which is safe to pass through as-is

2

package.json
{
"version": "2.0.0",
"version": "2.0.1-test",
"name": "babel-plugin-styled-components",

@@ -4,0 +4,0 @@ "description": "Improve the debugging experience and add server-side rendering support to styled-components",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc