Socket
Socket
Sign inDemoInstall

babel-plugin-emotion-rename

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-emotion-rename - npm Package Compare versions

Comparing version 1.0.0-beta.2 to 1.0.0-beta.3

lib/index.spec.js

2

lib/babel.spec.js

@@ -73,3 +73,3 @@ "use strict";

testGeneration("replace css import to emotion/react if used on styled - case1", "\nimport styled, { css } from \"react-emotion\";\n\nconst normalCss = css`\n color: #fff; \n`;\nconst abnormalCss = css`\n color: #000; \n`;\nconst Cmp = styled.div`\n ${abnormalCss}\n color: 'pink';\n`;\n", "\nimport { css as css2 } from '@emotion/react';\nimport styled from \"@emotion/styled\";\nimport { css } from \"@emotion/css\";\nconst normalCss = css`\n color: #fff; \n`;\nconst abnormalCss = css2`\n color: #000; \n`;\nconst Cmp = styled.div`\n ${abnormalCss}\n color: 'pink';\n`;\n"); // testGeneration(
testGeneration("replace css import to emotion/react if used on styled - case1", "\nimport styled, { css } from \"react-emotion\";\n\nconst normalCss = css`\n color: #fff; \n`;\nconst abnormalCss = css`\n color: #000; \n`;\nconst azt = 5;\nconst Cmp = styled.div`\n ${abnormalCss}\n width: ${azt};\n color: 'pink';\n`;\n", "\nimport { css as css2 } from '@emotion/react';\nimport styled from \"@emotion/styled\";\nimport { css } from \"@emotion/css\";\nconst normalCss = css`\n color: #fff; \n`;\nconst abnormalCss = css2`\n color: #000; \n`;\nconst azt = 5;\nconst Cmp = styled.div`\n ${abnormalCss}\n width: ${azt};\n color: 'pink';\n`;\n"); // testGeneration(
// "dont replace require without binding",

@@ -76,0 +76,0 @@ // `

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

var listTags = [];
var filterTags = [];
var MAP_STYLED = {};

@@ -72,10 +73,11 @@ var emotionReactImported = false;

*/
var res = listTags.filter(function (t) {
filterTags = listTags.filter(function (t) {
return MAP_STYLED[t.name];
});
res.forEach(function (t) {
t.path.node.declarations[0].init.tag.name = "css2";
});
filterTags.forEach(function (t) {
// t.path.node.declarations[0].init.tag.name = "css2";
t.path.node.declarations[0].init.callee.name = "css2";
}); // console.log("ver", emotionReactImported, res.length, MAP_STYLED, res);
if (!emotionReactImported && res.length) {
if (!emotionReactImported && filterTags.length) {
root.unshiftContainer("body", emotionReactImportDeclaration);

@@ -87,8 +89,3 @@ emotionReactImported = true;

VariableDeclaration: function VariableDeclaration(path) {
// if (path.node.declarations[0].id.name === "abnormalCss") {
// console.log("vd1", path.node.declarations[0].id.name);
// console.log("vd2", path.node.declarations[0].init.tag.name);
// console.log("vd3", path.node.declarations[0]);
// }
if (!path.node.declarations.length || !path.node.declarations[0].id || !path.node.declarations[0].init.tag) {
if (!path.node.declarations.length || !path.node.declarations[0].id || !path.node.declarations[0].init || !path.node.declarations[0].init.tag) {
return;

@@ -116,4 +113,19 @@ }

var type = path.parent.type;
var nodeName = path.node.name; // console.log(type, nodeName);
var nodeName = path.node.name;
var stype = path.node.type;
if ( // nodeName === "abnormalCss" &&
type === "CallExpression" && stype === "Identifier") {
var _path$parent$callee$o;
var conditions = [((_path$parent$callee$o = path.parent.callee.object) === null || _path$parent$callee$o === void 0 ? void 0 : _path$parent$callee$o.name) === "styled", !!path.scope.bindings._taggedTemplateLiteral, !!path.scope.bindings.styled, !!path.scope.bindings.css];
var resultCond = conditions.every(function (c) {
return c;
}); // console.log("\n\n\n\n====", nodeName);
// console.log("conditions", resultCond);
if (resultCond) {
MAP_STYLED[nodeName] = true;
}
}
/**

@@ -123,2 +135,3 @@ * Look for template literal on styled with css embed

if (["TemplateLiteral"].indexOf(type) !== -1) {

@@ -125,0 +138,0 @@ if (path.scope.bindings.styled) {

{
"name": "babel-plugin-emotion-rename",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Babel plugin to rename old Emotion 9 import to new Emotion 10+ import",
"main": "lib/index",
"scripts": {
"build": "babel src/. -d lib/. --ignore=spec.js",
"test:babel": "node -r @babel/register src/babel.spec.js",
"build": "babel --config-file=./babel-main.config.js src/. -d lib/. --ignore=spec.js",
"test:babel": "node src/index.spec.js",
"tmp": "babel --config-file=./babel-example.config.js examples/. -d examples-dist/.",
"test": "npm-run-all test:*",

@@ -10,0 +11,0 @@ "prepublish": "npm run build"

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