babel-plugin-emotion-rename
Advanced tools
Comparing version 1.0.0-beta.11 to 1.0.0-beta.12
@@ -63,17 +63,20 @@ "use strict"; | ||
var root; | ||
var imported = false; | ||
var emotionStyledImported = false; | ||
var emotionReactImported = false; | ||
var filterTags = []; | ||
var MAP_STYLED_VARS = {}; | ||
var cssList = []; | ||
var emotionReactImported = false; | ||
var importDeclaration = buildImport(); | ||
var emotionStyledImportDeclaration = buildImport(); | ||
var emotionReactImportDeclaration = buildImportEmotionReact(); | ||
function insertEmotionReact() { | ||
if (!emotionReactImported) { | ||
root.unshiftContainer("body", emotionReactImportDeclaration); | ||
emotionReactImported = true; | ||
} | ||
root.unshiftContainer("body", emotionReactImportDeclaration); | ||
emotionReactImported = true; | ||
} | ||
function insertEmotionStyled() { | ||
root.unshiftContainer("body", emotionStyledImportDeclaration); | ||
emotionStyledImported = true; | ||
} | ||
return { | ||
@@ -103,4 +106,3 @@ visitor: { | ||
} | ||
}); | ||
console.log(">>>123", filterTags, MAP_STYLED_VARS); | ||
}); // console.log(">>>123", filterTags, MAP_STYLED_VARS); | ||
@@ -139,7 +141,5 @@ if (filterTags.length) { | ||
}); | ||
console.log("tmplit...", MAP_STYLED_VARS); | ||
} | ||
}, | ||
ImportDeclaration: function ImportDeclaration(path, state) { | ||
console.log("imp-declare---", path.node.source.value); | ||
var isReactEmotionImport = path.node.source.value === "react-emotion"; | ||
@@ -159,2 +159,7 @@ | ||
var styledLocalName = (_styledDefaultNode$lo = styledDefaultNode.local) === null || _styledDefaultNode$lo === void 0 ? void 0 : _styledDefaultNode$lo.name; | ||
/** | ||
* Anticipate custom local import name | ||
* e.g import { css as csx } or import styledz from... | ||
*/ | ||
CSS_LOCAL_NAME = cssLocalName || "css"; | ||
@@ -183,5 +188,4 @@ STYLED_LOCAL_NAME = styledLocalName || "styled"; | ||
if (hasStyled.length && !imported) { | ||
imported = true; | ||
root.unshiftContainer("body", importDeclaration); | ||
if (hasStyled.length) { | ||
insertEmotionStyled(); | ||
} | ||
@@ -213,4 +217,2 @@ | ||
if (node.callee.name === "require" && node.arguments && node.arguments.length === 1 && t.isStringLiteral(node.arguments[0]) && isModule(node.arguments[0].value, original)) { | ||
console.log("require-declare---"); | ||
if (path.scope.bindings.styled && /(react-)?emotion/.test(node.arguments[0].value)) { | ||
@@ -217,0 +219,0 @@ path.node.arguments = [t.stringLiteral("@emotion/styled")]; |
{ | ||
"name": "babel-plugin-emotion-rename", | ||
"version": "1.0.0-beta.11", | ||
"version": "1.0.0-beta.12", | ||
"description": "Babel plugin to rename old Emotion 9 import to new Emotion 10+ import", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
15528
223