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.6.0 to 1.6.1

36

lib/css/placeholderUtils.js

@@ -6,20 +6,32 @@ "use strict";

});
exports.splitByPlaceholders = exports.makePlaceholder = exports.placeholderRegex = void 0;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
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 _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
// The capture group makes sure that the split contains the interpolation index
var placeholderRegex = exports.placeholderRegex = /(?:__PLACEHOLDER_(\d+)__)/g;
var placeholderRegex = /(?:__PLACEHOLDER_(\d+)__)/g; // Alternative regex that splits without a capture group
// Alternative regex that splits without a capture group
var placeholderNonCapturingRegex = /__PLACEHOLDER_(?:\d+)__/g;
exports.placeholderRegex = placeholderRegex;
var placeholderNonCapturingRegex = /__PLACEHOLDER_(?:\d+)__/g; // Generates a placeholder from an index
// Generates a placeholder from an index
var makePlaceholder = exports.makePlaceholder = function makePlaceholder(index) {
var makePlaceholder = function makePlaceholder(index) {
return `__PLACEHOLDER_${index}__`;
};
}; // Splits CSS by placeholders
// Splits CSS by placeholders
var splitByPlaceholders = exports.splitByPlaceholders = function splitByPlaceholders(_ref) {
exports.makePlaceholder = makePlaceholder;
var splitByPlaceholders = function splitByPlaceholders(_ref) {
var _ref2 = _toArray(_ref),

@@ -31,2 +43,4 @@ css = _ref2[0],

return [css.split(capture ? placeholderRegex : placeholderNonCapturingRegex)].concat(_toConsumableArray(rest));
};
};
exports.splitByPlaceholders = splitByPlaceholders;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,50 +6,42 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (_ref) {
var _minify = _interopRequireDefault(require("./visitors/minify"));
var _desugarStyled = _interopRequireDefault(require("./visitors/desugarStyled"));
var _displayNameAndId = _interopRequireDefault(require("./visitors/displayNameAndId"));
var _templateLiterals = _interopRequireDefault(require("./visitors/templateLiterals"));
var _assignStyledRequired = _interopRequireDefault(require("./visitors/assignStyledRequired"));
var _rewriteStyledImport = _interopRequireDefault(require("./visitors/rewriteStyledImport"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _default(_ref) {
var t = _ref.types;
return {
visitor: {
ImportDeclaration(path, state) {
(0, _rewriteStyledImport2.default)(t)(path, state);
(0, _rewriteStyledImport.default)(t)(path, state);
},
MemberExpression(path, state) {
(0, _desugarStyled2.default)(t)(path, state);
(0, _desugarStyled.default)(t)(path, state);
},
TaggedTemplateExpression(path, state) {
(0, _minify2.default)(t)(path, state);
(0, _displayNameAndId2.default)(t)(path, state);
(0, _templateLiterals2.default)(t)(path, state);
(0, _minify.default)(t)(path, state);
(0, _displayNameAndId.default)(t)(path, state);
(0, _templateLiterals.default)(t)(path, state);
},
VariableDeclarator(path, state) {
(0, _assignStyledRequired2.default)(t)(path, state);
(0, _assignStyledRequired.default)(t)(path, state);
}
}
};
};
var _minify = require('./visitors/minify');
var _minify2 = _interopRequireDefault(_minify);
var _desugarStyled = require('./visitors/desugarStyled');
var _desugarStyled2 = _interopRequireDefault(_desugarStyled);
var _displayNameAndId = require('./visitors/displayNameAndId');
var _displayNameAndId2 = _interopRequireDefault(_displayNameAndId);
var _templateLiterals = require('./visitors/templateLiterals');
var _templateLiterals2 = _interopRequireDefault(_templateLiterals);
var _assignStyledRequired = require('./visitors/assignStyledRequired');
var _assignStyledRequired2 = _interopRequireDefault(_assignStyledRequired);
var _rewriteStyledImport = require('./visitors/rewriteStyledImport');
var _rewriteStyledImport2 = _interopRequireDefault(_rewriteStyledImport);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.minifyCookedValues = exports.minifyRawValues = exports.minifyCooked = exports.minifyRaw = exports.compressSymbols = exports.stripLineComment = undefined;
exports.minifyCookedValues = exports.minifyRawValues = exports.minifyCooked = exports.minifyRaw = exports.compressSymbols = exports.stripLineComment = void 0;
var _difference = require('lodash/difference');
var _difference = _interopRequireDefault(require("lodash/difference"));
var _difference2 = _interopRequireDefault(_difference);
var _placeholderUtils = require("../css/placeholderUtils");
var _placeholderUtils = require('../css/placeholderUtils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -19,3 +17,2 @@

var i = 0;
return strArr.reduce(function (str, val, index, arr) {

@@ -29,11 +26,11 @@ return str + val + (index < arr.length - 1 ? (0, _placeholderUtils.makePlaceholder)(i++) : '');

};
var lineCommentStart = /\/\//g;
var symbolRegex = /(\s*[;:{},]\s*)/g;
var symbolRegex = /(\s*[;:{},]\s*)/g; // Counts occurences of substr inside str
// Counts occurences of substr inside str
var countOccurences = function countOccurences(str, substr) {
return str.split(substr).length - 1;
};
}; // Joins substrings until predicate returns true
// Joins substrings until predicate returns true
var reduceSubstr = function reduceSubstr(substrs, join, predicate) {

@@ -56,7 +53,7 @@ var length = substrs.length;

return res;
};
}; // Joins at comment starts when it's inside a string or parantheses
// effectively removing line comments
// Joins at comment starts when it's inside a string or parantheses
// effectively removing line comments
var stripLineComment = exports.stripLineComment = function stripLineComment(line) {
var stripLineComment = function stripLineComment(line) {
return reduceSubstr(line.split(lineCommentStart), '//', function (str) {

@@ -68,3 +65,5 @@ return !str.endsWith(':') && // NOTE: This is another guard against urls, if they're not inside strings or parantheses.

var compressSymbols = exports.compressSymbols = function compressSymbols(code) {
exports.stripLineComment = stripLineComment;
var compressSymbols = function compressSymbols(code) {
return code.split(symbolRegex).reduce(function (str, fragment, index) {

@@ -74,5 +73,5 @@ // Even-indices are non-symbol fragments

return str + fragment;
}
} // Only manipulate symbols outside of strings
// Only manipulate symbols outside of strings
if (countOccurences(str, "'") % 2 === 0 && countOccurences(str, '"') % 2 === 0) {

@@ -84,14 +83,15 @@ return str + fragment.trim();

}, '');
};
}; // Detects lines that are exclusively line comments
// Detects lines that are exclusively line comments
exports.compressSymbols = compressSymbols;
var isLineComment = function isLineComment(line) {
return line.trim().startsWith('//');
};
}; // Creates a minifier with a certain linebreak pattern
// Creates a minifier with a certain linebreak pattern
var minify = function minify(linebreakPattern) {
var linebreakRegex = new RegExp(linebreakPattern + '\\s*', 'g');
var multilineCommentRegex = makeMultilineCommentRegex(linebreakPattern);
return function (code) {

@@ -106,6 +106,5 @@ var newCode = code.replace(multilineCommentRegex, '\n') // Remove multiline comments

var eliminatedExpressionIndices = (0, _difference2.default)(code.match(_placeholderUtils.placeholderRegex), newCode.match(_placeholderUtils.placeholderRegex)).map(function (x) {
var eliminatedExpressionIndices = (0, _difference.default)(code.match(_placeholderUtils.placeholderRegex), newCode.match(_placeholderUtils.placeholderRegex)).map(function (x) {
return parseInt(x.match(/\d+/)[0], 10);
});
return [compressSymbols(newCode), eliminatedExpressionIndices];

@@ -115,11 +114,17 @@ };

var minifyRaw = exports.minifyRaw = minify('(?:\\\\r|\\\\n|\\r|\\n)');
var minifyCooked = exports.minifyCooked = minify('[\\r\\n]');
var minifyRaw = minify('(?:\\\\r|\\\\n|\\r|\\n)');
exports.minifyRaw = minifyRaw;
var minifyCooked = minify('[\\r\\n]');
exports.minifyCooked = minifyCooked;
var minifyRawValues = exports.minifyRawValues = function minifyRawValues(rawValues) {
var minifyRawValues = function minifyRawValues(rawValues) {
return (0, _placeholderUtils.splitByPlaceholders)(minifyRaw(injectUniquePlaceholders(rawValues)), false);
};
var minifyCookedValues = exports.minifyCookedValues = function minifyCookedValues(cookedValues) {
exports.minifyRawValues = minifyRawValues;
var minifyCookedValues = function minifyCookedValues(cookedValues) {
return (0, _placeholderUtils.splitByPlaceholders)(minifyCooked(injectUniquePlaceholders(cookedValues)), false);
};
};
exports.minifyCookedValues = minifyCookedValues;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {

});
exports.isHelper = exports.isKeyframesHelper = exports.isInjectGlobalHelper = exports.isCreateGlobalStyleHelper = exports.isCSSHelper = exports.isStyled = exports.isValidTopLevelImport = void 0;
var VALID_TOP_LEVEL_IMPORT_PATHS = ['styled-components', 'styled-components/no-tags', 'styled-components/native', 'styled-components/primitives'];
var isValidTopLevelImport = exports.isValidTopLevelImport = function isValidTopLevelImport(x) {
var isValidTopLevelImport = function isValidTopLevelImport(x) {
return VALID_TOP_LEVEL_IMPORT_PATHS.includes(x);
};
exports.isValidTopLevelImport = isValidTopLevelImport;
var importLocalName = function importLocalName(name, state) {
var localName = name === 'default' ? 'styled' : name;
state.file.path.traverse({

@@ -21,3 +23,2 @@ ImportDeclaration: {

if (isValidTopLevelImport(node.source.value)) {

@@ -49,3 +50,3 @@ var _iteratorNormalCompletion = true;

try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();

@@ -61,11 +62,12 @@ }

}
}
});
return localName;
};
var isStyled = exports.isStyled = function isStyled(t) {
var isStyled = function isStyled(t) {
return function (tag, state) {
if (t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name !== 'default' /** ignore default for #93 below */
if (t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name !== 'default'
/** ignore default for #93 below */
) {

@@ -88,3 +90,5 @@ // styled.something()

var isCSSHelper = exports.isCSSHelper = function isCSSHelper(t) {
exports.isStyled = isStyled;
var isCSSHelper = function isCSSHelper(t) {
return function (tag, state) {

@@ -95,3 +99,5 @@ return t.isIdentifier(tag) && tag.name === importLocalName('css', state);

var isCreateGlobalStyleHelper = exports.isCreateGlobalStyleHelper = function isCreateGlobalStyleHelper(t) {
exports.isCSSHelper = isCSSHelper;
var isCreateGlobalStyleHelper = function isCreateGlobalStyleHelper(t) {
return function (tag, state) {

@@ -102,3 +108,5 @@ return t.isIdentifier(tag) && tag.name === importLocalName('createGlobalStyle', state);

var isInjectGlobalHelper = exports.isInjectGlobalHelper = function isInjectGlobalHelper(t) {
exports.isCreateGlobalStyleHelper = isCreateGlobalStyleHelper;
var isInjectGlobalHelper = function isInjectGlobalHelper(t) {
return function (tag, state) {

@@ -109,3 +117,5 @@ return t.isIdentifier(tag) && tag.name === importLocalName('injectGlobal', state);

var isKeyframesHelper = exports.isKeyframesHelper = function isKeyframesHelper(t) {
exports.isInjectGlobalHelper = isInjectGlobalHelper;
var isKeyframesHelper = function isKeyframesHelper(t) {
return function (tag, state) {

@@ -116,6 +126,10 @@ return t.isIdentifier(tag) && tag.name === importLocalName('keyframes', state);

var isHelper = exports.isHelper = function isHelper(t) {
exports.isKeyframesHelper = isKeyframesHelper;
var isHelper = function isHelper(t) {
return function (tag, state) {
return isCSSHelper(t)(tag, state) || isKeyframesHelper(t)(tag, state);
};
};
};
exports.isHelper = isHelper;

@@ -6,2 +6,3 @@ "use strict";

});
exports.default = void 0;

@@ -15,18 +16,13 @@ /**

*/
exports.default = function (t) {
var _default = function _default(t) {
return function (path) {
var namedNode = void 0;
var namedNode;
path.find(function (path) {
// const X = styled
if (path.isAssignmentExpression()) {
namedNode = path.node.left;
// const X = { Y: styled }
namedNode = path.node.left; // const X = { Y: styled }
} else if (path.isObjectProperty()) {
namedNode = path.node.key;
// class Y { (static) X = styled }
namedNode = path.node.key; // class Y { (static) X = styled }
} else if (path.isClassProperty()) {
namedNode = path.node.key;
// let X; X = styled
namedNode = path.node.key; // let X; X = styled
} else if (path.isVariableDeclarator()) {

@@ -37,16 +33,17 @@ namedNode = path.node.id;

return true;
}
} // we've got an displayName (if we need it) no need to continue
// we've got an displayName (if we need it) no need to continue
if (namedNode) return true;
});
}); // foo.bar -> bar
// foo.bar -> bar
if (t.isMemberExpression(namedNode)) {
namedNode = namedNode.property;
}
} // identifiers are the only thing we can reliably get a name from
// identifiers are the only thing we can reliably get a name from
return t.isIdentifier(namedNode) ? namedNode.name : undefined;
};
};
};
exports.default = _default;

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

});
exports.default = void 0;
/**

@@ -22,13 +24,10 @@ * JS Implementation of MurmurHash2

var i = 0;
var k = void 0;
var k;
while (l >= 4) {
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
k ^= k >>> 24;
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k;
l -= 4;

@@ -38,7 +37,12 @@ ++i;

/* eslint-disable no-fallthrough */switch (l) {
/* eslint-disable no-fallthrough */
switch (l) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:

@@ -50,9 +54,10 @@ h ^= str.charCodeAt(i) & 0xff;

h ^= h >>> 13;
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16);
h ^= h >>> 15;
return (h >>> 0).toString(36);
}
exports.default = murmurhash2_32_gc;
var _default = murmurhash2_32_gc;
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,12 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.useNoTags = exports.useTranspileTemplateLiterals = exports.useMinify = exports.useFileName = exports.useSSR = exports.useDisplayName = undefined;
exports.useNoTags = exports.useTranspileTemplateLiterals = exports.useMinify = exports.useFileName = exports.useSSR = exports.useDisplayName = void 0;
var _semver = require('semver');
var _semver = _interopRequireDefault(require("semver"));
var _semver2 = _interopRequireDefault(_semver);
var _package = _interopRequireDefault(require("styled-components/package.json"));
var _package = require('styled-components/package.json');
var _package2 = _interopRequireDefault(_package);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -22,22 +18,32 @@

var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return opts[name] === undefined || opts[name] === null ? defaultValue : opts[name];
}
var useDisplayName = exports.useDisplayName = function useDisplayName(state) {
var useDisplayName = function useDisplayName(state) {
return getOption(state, 'displayName');
};
var useSSR = exports.useSSR = function useSSR(state) {
exports.useDisplayName = useDisplayName;
var useSSR = function useSSR(state) {
return getOption(state, 'ssr', true);
};
var useFileName = exports.useFileName = function useFileName(state) {
exports.useSSR = useSSR;
var useFileName = function useFileName(state) {
return getOption(state, 'fileName');
};
var useMinify = exports.useMinify = function useMinify(state) {
exports.useFileName = useFileName;
var useMinify = function useMinify(state) {
return getOption(state, 'minify');
};
var useTranspileTemplateLiterals = exports.useTranspileTemplateLiterals = function useTranspileTemplateLiterals(state) {
exports.useMinify = useMinify;
var useTranspileTemplateLiterals = function useTranspileTemplateLiterals(state) {
return getOption(state, 'transpileTemplateLiterals');
};
/**

@@ -48,4 +54,10 @@ * When using the babel plugin, we desugar styled.div to styled('div'), which means we can

*/
var useNoTags = exports.useNoTags = function useNoTags() {
return _semver2.default.satisfies(_package2.default.version, '>= 4');
};
exports.useTranspileTemplateLiterals = useTranspileTemplateLiterals;
var useNoTags = function useNoTags() {
return _semver.default.satisfies(_package.default.version, '>= 4');
};
exports.useNoTags = useNoTags;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -7,4 +7,5 @@ Object.defineProperty(exports, "__esModule", {

exports.default = prefixLeadingDigit;
function prefixLeadingDigit(str) {
return str.replace(/^(\d)/, 'sc-$1');
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _detectors = require('../utils/detectors');
var _detectors = require("../utils/detectors");
exports.default = function (t) {
var _default = function _default(t) {
return function (path, state) {

@@ -16,2 +17,4 @@ if (t.isCallExpression(path.node.init) && t.isIdentifier(path.node.init.callee) && path.node.init.callee.name === 'require' && path.node.init.arguments && path.node.init.arguments[0] && t.isLiteral(path.node.init.arguments[0]) && (0, _detectors.isValidTopLevelImport)(path.node.init.arguments[0].value)) {

};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,12 +6,11 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _get = require('lodash/get');
var _get = _interopRequireDefault(require("lodash/get"));
var _get2 = _interopRequireDefault(_get);
var _detectors = require("../utils/detectors");
var _detectors = require('../utils/detectors');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (t) {
var _default = function _default(t) {
return function (path, state) {

@@ -25,15 +24,16 @@ /**

*/
var sugar = (0, _get2.default)(path, 'node.property.name');
var sugar = (0, _get.default)(path, 'node.property.name');
var isAssignment = t.isAssignmentExpression(path.parent);
/**
* If the left side of the function is a complex path, e.g.
* "styled_default.default.div", we want to preserve the "styled_default.default"
* part and just reuse that AST object.
*/
var leftSide = t.isMemberExpression(path.node.object) ? path.node.object : t.identifier(path.node.object.name);
if (sugar) {
if (sugar && !isAssignment) {
/**
* If the left side of the function is a complex path, e.g.
* "styled_default.default.div", we want to preserve the "styled_default.default"
* part and just reuse that AST object.
*/
var leftSide = t.isMemberExpression(path.node.object) ? path.node.object : t.identifier(path.node.object.name);
/**
* "styled.div" -> "styled('div')"
*/
path.replaceWith(t.callExpression(leftSide, [t.stringLiteral(sugar)]));

@@ -43,2 +43,4 @@ }

};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,27 +6,18 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _path = require('path');
var _path = _interopRequireDefault(require("path"));
var _path2 = _interopRequireDefault(_path);
var _fs = _interopRequireDefault(require("fs"));
var _fs = require('fs');
var _options = require("../utils/options");
var _fs2 = _interopRequireDefault(_fs);
var _getName = _interopRequireDefault(require("../utils/getName"));
var _options = require('../utils/options');
var _prefixDigit = _interopRequireDefault(require("../utils/prefixDigit"));
var _getName = require('../utils/getName');
var _hash = _interopRequireDefault(require("../utils/hash"));
var _getName2 = _interopRequireDefault(_getName);
var _detectors = require("../utils/detectors");
var _prefixDigit = require('../utils/prefixDigit');
var _prefixDigit2 = _interopRequireDefault(_prefixDigit);
var _hash = require('../utils/hash');
var _hash2 = _interopRequireDefault(_hash);
var _detectors = require('../utils/detectors');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -41,10 +32,12 @@

var withConfigProps = [];
if (displayName) {
withConfigProps.push(t.objectProperty(t.identifier('displayName'), t.stringLiteral(displayName)));
}
if (componentId) {
withConfigProps.push(t.objectProperty(t.identifier('componentId'), t.stringLiteral(componentId)));
}
} // Replace x`...` with x.withConfig({ })`...`
// Replace x`...` with x.withConfig({ })`...`
path.node.tag = t.callExpression(t.memberExpression(path.node.tag, t.identifier('withConfig')), [t.objectExpression(withConfigProps)]);

@@ -55,4 +48,5 @@ };

var getBlockName = function getBlockName(file) {
var name = _path2.default.basename(file.opts.filename, _path2.default.extname(file.opts.filename));
return name !== 'index' ? name : _path2.default.basename(_path2.default.dirname(file.opts.filename));
var name = _path.default.basename(file.opts.filename, _path.default.extname(file.opts.filename));
return name !== 'index' ? name : _path.default.basename(_path.default.dirname(file.opts.filename));
};

@@ -63,10 +57,12 @@

var file = state.file;
var componentName = (0, _getName.default)(t)(path);
var componentName = (0, _getName2.default)(t)(path);
if (file) {
var blockName = getBlockName(file);
if (blockName === componentName) {
return componentName;
}
return componentName ? `${(0, _prefixDigit2.default)(blockName)}__${componentName}` : (0, _prefixDigit2.default)(blockName);
return componentName ? `${(0, _prefixDigit.default)(blockName)}__${componentName}` : (0, _prefixDigit.default)(blockName);
} else {

@@ -82,4 +78,6 @@ return componentName;

}
var dir = _path2.default.dirname(filename);
if (_fs2.default.existsSync(_path2.default.join(dir, 'package.json'))) {
var dir = _path.default.dirname(filename);
if (_fs.default.existsSync(_path.default.join(dir, 'package.json'))) {
return dir;

@@ -95,7 +93,6 @@ } else if (dir !== filename) {

var COMPONENT_POSITION = 'styled-components-component-position';
var separatorRegExp = new RegExp(`\\${_path2.default.sep}`, 'g');
var separatorRegExp = new RegExp(`\\${_path.default.sep}`, 'g');
var getFileHash = function getFileHash(state) {
var file = state.file;
// hash calculation is costly due to fs operations, so we'll cache it per file.
var file = state.file; // hash calculation is costly due to fs operations, so we'll cache it per file.

@@ -105,9 +102,11 @@ if (file.get(FILE_HASH)) {

}
var filename = file.opts.filename;
// find module root directory
var filename = file.opts.filename; // find module root directory
var moduleRoot = findModuleRoot(filename);
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;
var filePath = moduleRoot && _path.default.relative(moduleRoot, filename).replace(separatorRegExp, '/');
var moduleName = moduleRoot && JSON.parse(_fs.default.readFileSync(_path.default.join(moduleRoot, 'package.json'))).name;
var code = file.code;
var stuffToHash = [moduleName];

@@ -121,3 +120,3 @@

var fileHash = (0, _hash2.default)(stuffToHash.join(''));
var fileHash = (0, _hash.default)(stuffToHash.join(''));
file.set(FILE_HASH, fileHash);

@@ -135,13 +134,14 @@ return fileHash;

// Prefix the identifier with a character because CSS classes cannot start with a number
return `${(0, _prefixDigit2.default)(getFileHash(state))}-${getNextId(state)}`;
return `${(0, _prefixDigit.default)(getFileHash(state))}-${getNextId(state)}`;
};
exports.default = function (t) {
var _default = function _default(t) {
return function (path, state) {
if ((0, _detectors.isStyled)(t)(path.node.tag, state)) {
var displayName = (0, _options.useDisplayName)(state) && getDisplayName(t)(path, (0, _options.useFileName)(state) && state);
addConfig(t)(path, displayName && displayName.replace(/[^_a-zA-Z0-9-]/g, ''), (0, _options.useSSR)(state) && getComponentId(state));
}
};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,12 +6,19 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _options = require("../utils/options");
var _options = require('../utils/options');
var _detectors = require("../utils/detectors");
var _detectors = require('../utils/detectors');
var _minify = require("../minify");
var _minify = require('../minify');
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
exports.default = function (t) {
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var _default = function _default(t) {
return function (path, state) {

@@ -41,3 +48,2 @@ if ((0, _options.useMinify)(state) && ((0, _detectors.isStyled)(t)(path.node.tag, state) || (0, _detectors.isHelper)(t)(path.node.tag, state))) {

var element = templateLiteral.quasis[i];
element.value.raw = rawValuesMinified[i];

@@ -48,2 +54,4 @@ element.value.cooked = cookedValuesMinfified[i];

};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _options = require('../utils/options');
var _options = require("../utils/options");

@@ -15,3 +16,3 @@ /**

*/
exports.default = function (t) {
var _default = function _default(t) {
return function (path) {

@@ -22,2 +23,4 @@ if ((0, _options.useNoTags)() && path.node.source.value === 'styled-components') {

};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,17 +6,18 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _options = require('../../utils/options');
var _options = require("../../utils/options");
var _transpile = require('./transpile');
var _transpile = _interopRequireDefault(require("./transpile"));
var _transpile2 = _interopRequireDefault(_transpile);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (t) {
var _default = function _default(t) {
return function (path, state) {
if ((0, _options.useTranspileTemplateLiterals)(state)) {
(0, _transpile2.default)(t)(path, state);
(0, _transpile.default)(t)(path, state);
}
};
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,15 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _detectors = require('../../utils/detectors');
var _detectors = require("../../utils/detectors");
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
exports.default = function (t) {
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; } }
var _default = function _default(t) {
return function (path, state) {

@@ -20,4 +27,2 @@ if ((0, _detectors.isStyled)(t)(path.node.tag, state) || (0, _detectors.isHelper)(t)(path.node.tag, state)) {

expressions = _path$node$quasi.expressions;
var values = t.arrayExpression(quasis.filter(function (quasi) {

@@ -28,6 +33,7 @@ return quasi.value.cooked !== undefined;

}));
path.replaceWith(t.callExpression(callee, [values].concat(_toConsumableArray(expressions))));
}
};
};
};
exports.default = _default;
{
"version": "1.6.0",
"version": "1.6.1",
"name": "babel-plugin-styled-components",

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

"devDependencies": {
"babel-cli": "^6.24.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.2.2",
"jest": "^17.0.3",
"prettier": "^1.12.1",
"jest": "^23.5.0",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",

@@ -31,2 +33,5 @@ "styled-components": "^3.4.5"

},
"resolutions": {
"babel-core": "7.0.0-bridge.0"
},
"peerDependencies": {

@@ -33,0 +38,0 @@ "styled-components": ">= 2"

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