Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 1.9.4-0 to 1.9.4

32

lib/index.js

@@ -24,2 +24,10 @@ "use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _default(_ref) {

@@ -30,2 +38,26 @@ var t = _ref.types;

visitor: {
// These visitors insert newly generated code and missing import/require statements
Program: {
enter(path, state) {
state.required = false;
state.items = [];
},
exit(path, state) {
var _path$node$body;
var oldLength = path.node.body.length;
(_path$node$body = path.node.body).push.apply(_path$node$body, _toConsumableArray(state.items));
var newLength = path.node.body.length;
for (var i = 0; i < newLength - oldLength; i++) {
// Queue all inserted items for revisiting so that tagged templates are transpiled
path.requeue(path.get('body')[oldLength + i]);
}
}
},
JSXAttribute(path, state) {

@@ -32,0 +64,0 @@ (0, _transpileCssProp.default)(t)(path, state);

27

lib/visitors/transpileCssProp.js

@@ -31,14 +31,11 @@ "use strict";

if (!(0, _options.useCssProp)(state)) return;
if (path.node.name.name !== 'css') return;
var program = path.findParent(function (p) {
return t.isProgram(p);
});
var importName = state.customImportName || program.scope.generateUidIdentifier('styled');
if (!state.customImportName) state.customImportName = importName; // Insert require('styled-components') if it doesn't exist yet
if (path.node.name.name !== 'css') return; // Insert require('styled-components') if it doesn't exist yet
var bindings = program.scope.bindings;
var bindings = path.findParent(function (p) {
return p.type === 'Program';
}).scope.bindings;
if (!state.required) {
if (!bindings[importName]) {
program.node.body.push(t.importDeclaration([t.importDefaultSpecifier(importName)], t.stringLiteral('styled-components')));
if (!bindings.styled) {
state.items.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier('styled'))], t.stringLiteral('styled-components')));
}

@@ -54,3 +51,3 @@

}));
var styled = t.callExpression(importName, [/^[a-z]/.test(name) ? t.stringLiteral(name) : t.identifier(name)]);
var styled = t.callExpression(t.identifier('styled'), [/^[a-z]/.test(name) ? t.stringLiteral(name) : t.identifier(name)]);
var css;

@@ -60,3 +57,4 @@

css = t.templateLiteral([t.templateElement({
raw: path.node.value.value
raw: path.node.value.value,
cooked: path.node.value.value
}, true)], []);

@@ -110,7 +108,4 @@ } else if (t.isJSXExpressionContainer(path.node.value)) {

return acc;
}, []); // Add the tagged template expression and then requeue the newly added node
// so Babel runs over it again
program.node.body.push(t.variableDeclaration('var', [t.variableDeclarator(id, t.taggedTemplateExpression(styled, css))]));
program.requeue(program.get('body')[program.get('body').length - 1]);
}, []);
state.items.push(t.variableDeclaration('var', [t.variableDeclarator(id, t.taggedTemplateExpression(styled, css))]));
};

@@ -117,0 +112,0 @@ };

{
"version": "1.9.4-0",
"version": "1.9.4",
"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