babel-plugin-emotion-rename
Advanced tools
Comparing version 1.0.0-beta.15 to 1.0.0-beta.17
@@ -93,3 +93,4 @@ "use strict"; | ||
*/ | ||
var cssListKeys = Object.keys(MAP_CSS_LIST); | ||
var cssListKeys = Object.keys(MAP_CSS_LIST); // console.log(">>", cssListKeys, MAP_STYLED_VARS); | ||
var cssList = cssListKeys.map(function (key) { | ||
@@ -144,3 +145,3 @@ return { | ||
FunctionExpression: function FunctionExpression(path) { | ||
var _path$scope$block$bod, _path$scope$block$bod2, _path$scope$block$bod3, _path$scope$block$bod4, _path$scope$block$bod5, _path$scope$block$bod6, _path$scope$block$bod7; | ||
var _path$parent$id2, _path$scope$block$bod, _path$scope$block$bod2, _path$scope$block$bod3, _path$scope$block$bod4, _path$scope$block$bod5, _path$scope$block$bod6, _path$scope$block$bod7, _path$scope$block$bod8, _path$scope$block$bod9, _path$scope$block$bod10, _path$scope$block$bod11; | ||
@@ -150,6 +151,8 @@ /** | ||
*/ | ||
if (((_path$scope$block$bod = path.scope.block.body) === null || _path$scope$block$bod === void 0 ? void 0 : (_path$scope$block$bod2 = _path$scope$block$bod.body[0]) === null || _path$scope$block$bod2 === void 0 ? void 0 : (_path$scope$block$bod3 = _path$scope$block$bod2.argument) === null || _path$scope$block$bod3 === void 0 ? void 0 : _path$scope$block$bod3.type) === "TaggedTemplateExpression" && ((_path$scope$block$bod4 = path.scope.block.body) === null || _path$scope$block$bod4 === void 0 ? void 0 : (_path$scope$block$bod5 = _path$scope$block$bod4.body[0]) === null || _path$scope$block$bod5 === void 0 ? void 0 : (_path$scope$block$bod6 = _path$scope$block$bod5.argument) === null || _path$scope$block$bod6 === void 0 ? void 0 : (_path$scope$block$bod7 = _path$scope$block$bod6.tag) === null || _path$scope$block$bod7 === void 0 ? void 0 : _path$scope$block$bod7.name) === CSS_LOCAL_NAME) { | ||
var _path$parent$id2; | ||
var cssVarName = path === null || path === void 0 ? void 0 : (_path$parent$id2 = path.parent.id) === null || _path$parent$id2 === void 0 ? void 0 : _path$parent$id2.name; | ||
/** | ||
* Handle transpiled version of emotion css call... | ||
*/ | ||
var cssVarName = path === null || path === void 0 ? void 0 : (_path$parent$id2 = path.parent.id) === null || _path$parent$id2 === void 0 ? void 0 : _path$parent$id2.name; | ||
if (((_path$scope$block$bod = path.scope.block.body) === null || _path$scope$block$bod === void 0 ? void 0 : (_path$scope$block$bod2 = _path$scope$block$bod.body[0]) === null || _path$scope$block$bod2 === void 0 ? void 0 : (_path$scope$block$bod3 = _path$scope$block$bod2.argument) === null || _path$scope$block$bod3 === void 0 ? void 0 : (_path$scope$block$bod4 = _path$scope$block$bod3.callee) === null || _path$scope$block$bod4 === void 0 ? void 0 : _path$scope$block$bod4.name) === CSS_LOCAL_NAME) { | ||
MAP_CSS_LIST[cssVarName] = { | ||
@@ -159,2 +162,12 @@ path: path | ||
} | ||
/** | ||
* Handle normal css call with template expression | ||
*/ | ||
if (((_path$scope$block$bod5 = path.scope.block.body) === null || _path$scope$block$bod5 === void 0 ? void 0 : (_path$scope$block$bod6 = _path$scope$block$bod5.body[0]) === null || _path$scope$block$bod6 === void 0 ? void 0 : (_path$scope$block$bod7 = _path$scope$block$bod6.argument) === null || _path$scope$block$bod7 === void 0 ? void 0 : _path$scope$block$bod7.type) === "TaggedTemplateExpression" && ((_path$scope$block$bod8 = path.scope.block.body) === null || _path$scope$block$bod8 === void 0 ? void 0 : (_path$scope$block$bod9 = _path$scope$block$bod8.body[0]) === null || _path$scope$block$bod9 === void 0 ? void 0 : (_path$scope$block$bod10 = _path$scope$block$bod9.argument) === null || _path$scope$block$bod10 === void 0 ? void 0 : (_path$scope$block$bod11 = _path$scope$block$bod10.tag) === null || _path$scope$block$bod11 === void 0 ? void 0 : _path$scope$block$bod11.name) === CSS_LOCAL_NAME) { | ||
MAP_CSS_LIST[cssVarName] = { | ||
path: path | ||
}; | ||
} | ||
}, | ||
@@ -191,3 +204,3 @@ TaggedTemplateExpression: function TaggedTemplateExpression(path) { | ||
}); | ||
var styledLocalName = (_styledDefaultNode$lo = styledDefaultNode.local) === null || _styledDefaultNode$lo === void 0 ? void 0 : _styledDefaultNode$lo.name; | ||
var styledLocalName = styledDefaultNode === null || styledDefaultNode === void 0 ? void 0 : (_styledDefaultNode$lo = styledDefaultNode.local) === null || _styledDefaultNode$lo === void 0 ? void 0 : _styledDefaultNode$lo.name; | ||
/** | ||
@@ -216,3 +229,6 @@ * Anticipate custom local import name | ||
var a = 0; | ||
if (!nonStyled.length && hasStyled.length) { | ||
a = 1; | ||
path.node.source = t.stringLiteral("@emotion/styled"); | ||
@@ -223,2 +239,3 @@ return; | ||
if (hasStyled.length) { | ||
a = 2; | ||
insertEmotionStyled(); | ||
@@ -233,6 +250,34 @@ } | ||
_styledDefaultNode.local.name = STYLED_LOCAL_NAME; | ||
if (!_styledDefaultNode) { | ||
/** | ||
* Only happen on integration, default is empty! | ||
* need to insert default import manually | ||
*/ | ||
path.node.specifiers.push({ | ||
type: "ImportDefaultSpecifier", | ||
local: { | ||
type: "Identifier", | ||
name: STYLED_LOCAL_NAME | ||
} | ||
}); | ||
} else if (_styledDefaultNode.local) { | ||
_styledDefaultNode.local.name = STYLED_LOCAL_NAME; | ||
} | ||
} | ||
}, | ||
CallExpression: function CallExpression(path, state) { | ||
/** | ||
* Collect all styled's arguments with form of styled(a, b, c, ...) | ||
*/ | ||
if (path.node.callee.name === STYLED_LOCAL_NAME && path.node.arguments && path.node.arguments.length) { | ||
path.parent.arguments.filter(function (a) { | ||
return a.type === "Identifier"; | ||
}).map(function (a) { | ||
return a.name; | ||
}).forEach(function (expName) { | ||
MAP_STYLED_VARS[expName] = 1; | ||
}); | ||
return; | ||
} | ||
REP.forEach(function (_ref2) { | ||
@@ -248,4 +293,2 @@ var original = _ref2.original, | ||
*/ | ||
console.log("call-exp"); | ||
if (path.scope.bindings.styled && /(react-)?emotion/.test(node.arguments[0].value)) { | ||
@@ -252,0 +295,0 @@ path.node.arguments = [t.stringLiteral("@emotion/styled")]; |
{ | ||
"name": "babel-plugin-emotion-rename", | ||
"version": "1.0.0-beta.15", | ||
"version": "1.0.0-beta.17", | ||
"description": "Babel plugin to rename old Emotion 9 import to new Emotion 10+ import", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18698
290