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

32

lib/index.js

@@ -24,10 +24,2 @@ "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) {

@@ -38,26 +30,2 @@ 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) {

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

30

lib/visitors/transpileCssProp.js

@@ -8,2 +8,4 @@ "use strict";

var _helperModuleImports = require("@babel/helper-module-imports");
var _options = require("../utils/options");

@@ -32,16 +34,17 @@

if (!(0, _options.useCssProp)(state)) return;
if (path.node.name.name !== 'css') return; // Insert require('styled-components') if it doesn't exist yet
if (path.node.name.name !== 'css') return;
var program = state.file.path; // state.customImportName is passed through from styled-components/macro if it's used
// since the macro also inserts the import
var bindings = path.findParent(function (p) {
return p.type === 'Program';
}).scope.bindings;
var importName = state.customImportName; // Insert import if it doesn't exist yet
if (!state.required) {
if (!bindings.styled) {
state.items.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier('styled'))], t.stringLiteral('styled-components')));
}
var bindings = program.scope.bindings;
state.required = true;
if (!importName || !bindings[importName.name]) {
importName = (0, _helperModuleImports.addDefault)(path, 'styled-components', {
nameHint: importName ? importName.name : 'styled'
});
}
if (!state.customImportName) state.customImportName = importName;
var elem = path.parentPath;

@@ -52,3 +55,3 @@ var name = getName(elem.node.name, t);

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

@@ -108,4 +111,7 @@

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

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

3

package.json
{
"version": "1.9.4",
"version": "1.9.5-0",
"name": "babel-plugin-styled-components",

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

"@babel/helper-annotate-as-pure": "^7.0.0",
"@babel/helper-module-imports": "^7.0.0",
"babel-plugin-syntax-jsx": "^6.18.0",

@@ -32,0 +33,0 @@ "lodash": "^4.17.10"

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