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
2
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.2.1 to 1.3.0

lib/visitors/assignStyledRequired.js

7

lib/index.js

@@ -22,2 +22,5 @@ 'use strict';

(0, _templateLiterals2.default)(path, state);
},
VariableDeclarator(path, state) {
(0, _assignStyledRequired2.default)(path, state);
}

@@ -40,4 +43,8 @@ }

var _assignStyledRequired = require('./visitors/assignStyledRequired');
var _assignStyledRequired2 = _interopRequireDefault(_assignStyledRequired);
var _noParserImport = require('./visitors/noParserImport');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

2

lib/minify/index.js

@@ -11,3 +11,3 @@ 'use strict';

var makeMultilineCommentRegex = function makeMultilineCommentRegex(newlinePattern) {
return new RegExp('\\/\\*(.|' + newlinePattern + ')*?\\*\\/', 'g');
return new RegExp('\\/\\*[^!](.|' + newlinePattern + ')*?\\*\\/', 'g');
};

@@ -14,0 +14,0 @@ var lineCommentStart = /\/\//g;

@@ -15,24 +15,68 @@ 'use strict';

var importLocalName = function importLocalName(name, state) {
var imports = state.file.metadata.modules.imports;
var styledImports = imports.find(function (x) {
return x.source === 'styled-components';
var localName = name === 'default' ? 'styled' : name;
state.file.path.traverse({
ImportDeclaration: {
exit(path) {
var node = path.node;
if (node.source.value === 'styled-components') {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = path.get('specifiers')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var specifier = _step.value;
if (specifier.isImportDefaultSpecifier()) {
localName = specifier.node.local.name;
}
if (specifier.isImportSpecifier() && specifier.node.imported.name === name) {
localName = specifier.node.local.name;
}
if (specifier.isImportNamespaceSpecifier()) {
localName = specifier.node.local.name;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}
}
});
if (styledImports) {
var specifier = styledImports.specifiers.find(function (x) {
return x.imported === name;
});
if (specifier) {
return specifier.local;
}
}
// import not found - return default name
return name === 'default' ? 'styled' : name;
return localName;
};
var isStyled = exports.isStyled = function isStyled(tag, state) {
if (t.isCallExpression(tag) && t.isMemberExpression(tag.callee)) {
// styled.something()
return isStyled(tag.callee.object, state);
} else {
return t.isMemberExpression(tag) && tag.object.name === importLocalName('default', state) || t.isCallExpression(tag) && tag.callee.name === importLocalName('default', state);
if (t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name !== 'default' /** ignore default for #93 below */) {
// styled.something()
return isStyled(tag.callee.object, state);
} else {
return t.isMemberExpression(tag) && tag.object.name === importLocalName('default', state) || t.isCallExpression(tag) && tag.callee.name === importLocalName('default', state) ||
/**
* #93 Support require()
* styled-components might be imported using a require()
* call and assigned to a variable of any name.
* - styled.default.div``
* - styled.default.something()
*/
state.styledRequired && t.isMemberExpression(tag) && t.isMemberExpression(tag.object) && tag.object.property.name === 'default' && tag.object.object.name === state.styledRequired || state.styledRequired && t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name === 'default' && tag.callee.object.name === state.styledRequired;
}

@@ -39,0 +83,0 @@ };

@@ -88,2 +88,3 @@ 'use strict';

var COMPONENT_POSITION = 'styled-components-component-position';
var separatorRegExp = new RegExp(`\\${_path2.default.sep}`, 'g');

@@ -100,3 +101,3 @@ var getFileHash = function getFileHash(state) {

var moduleRoot = findModuleRoot(filename);
var filePath = moduleRoot && _path2.default.relative(moduleRoot, filename).replace(_path2.default.sep, '/');
var filePath = moduleRoot && _path2.default.relative(moduleRoot, filename).replace(separatorRegExp, '/');
var moduleName = moduleRoot && JSON.parse(_fs2.default.readFileSync(_path2.default.join(moduleRoot, 'package.json'))).name;

@@ -103,0 +104,0 @@ var code = file.code;

{
"version": "1.2.1",
"version": "1.3.0",
"name": "babel-plugin-styled-components",

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

"babel-preset-env": "^1.2.2",
"jest": "^17.0.3"
"jest": "^17.0.3",
"rimraf": "^2.6.2"
},
"scripts": {
"clean": "rm -rf lib",
"clean": "rimraf lib",
"build": "babel src -d lib",

@@ -38,4 +39,4 @@ "test": "jest",

"babel-types": "^6.26.0",
"stylis": "^3.2.1"
"stylis": "3.x"
}
}
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