babel-plugin-emotion
Advanced tools
Comparing version 10.0.33 to 10.2.2
# babel-plugin-emotion | ||
## 10.2.2 | ||
### Patch Changes | ||
- [`ed47786b`](https://github.com/emotion-js/emotion/commit/ed47786b084384ac8fa5f88f0a3b50f4f3026a78) [#2248](https://github.com/emotion-js/emotion/pull/2248) Thanks [@xanido](https://github.com/xanido)! - optimiseCssProp results in `css` being imported from @emotion/core rather than @emotion/css | ||
## 10.0.33 | ||
@@ -4,0 +10,0 @@ |
@@ -5,11 +5,9 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var nodePath = _interopDefault(require('path')); | ||
var nodePath = require('path'); | ||
var sourceMap = require('source-map'); | ||
var convert = _interopDefault(require('convert-source-map')); | ||
var findRoot = _interopDefault(require('find-root')); | ||
var memoize = _interopDefault(require('@emotion/memoize')); | ||
var hashString = _interopDefault(require('@emotion/hash')); | ||
var escapeRegexp = _interopDefault(require('escape-string-regexp')); | ||
var convert = require('convert-source-map'); | ||
var findRoot = require('find-root'); | ||
var memoize = require('@emotion/memoize'); | ||
var hashString = require('@emotion/hash'); | ||
var escapeRegexp = require('escape-string-regexp'); | ||
var serialize = require('@emotion/serialize'); | ||
@@ -19,2 +17,11 @@ var helperModuleImports = require('@babel/helper-module-imports'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
var nodePath__default = /*#__PURE__*/_interopDefault(nodePath); | ||
var convert__default = /*#__PURE__*/_interopDefault(convert); | ||
var findRoot__default = /*#__PURE__*/_interopDefault(findRoot); | ||
var memoize__default = /*#__PURE__*/_interopDefault(memoize); | ||
var hashString__default = /*#__PURE__*/_interopDefault(hashString); | ||
var escapeRegexp__default = /*#__PURE__*/_interopDefault(escapeRegexp); | ||
// babel-plugin-styled-components | ||
@@ -205,4 +212,4 @@ // https://github.com/styled-components/babel-plugin-styled-components/blob/8d44acc36f067d60d4e09f9c22ff89695bc332d2/src/minify/index.js | ||
if (!labelFormat) return sanitizeLabelPart(identifierName); | ||
var parsedPath = nodePath.parse(filename); | ||
var localDirname = nodePath.basename(parsedPath.dir); | ||
var parsedPath = nodePath__default['default'].parse(filename); | ||
var localDirname = nodePath__default['default'].basename(parsedPath.dir); | ||
var localFilename = parsedPath.name; | ||
@@ -335,3 +342,3 @@ | ||
}); | ||
return convert.fromObject(generator).toComment({ | ||
return convert__default['default'].fromObject(generator).toComment({ | ||
multiline: true | ||
@@ -345,13 +352,13 @@ }); | ||
var hashArray = function hashArray(arr) { | ||
return hashString(arr.join('')); | ||
return hashString__default['default'](arr.join('')); | ||
}; | ||
var unsafeRequire = require; | ||
var getPackageRootPath = memoize(function (filename) { | ||
return findRoot(filename); | ||
var getPackageRootPath = memoize__default['default'](function (filename) { | ||
return findRoot__default['default'](filename); | ||
}); | ||
var separator = new RegExp(escapeRegexp(nodePath.sep), 'g'); | ||
var separator = new RegExp(escapeRegexp__default['default'](nodePath__default['default'].sep), 'g'); | ||
var normalizePath = function normalizePath(path) { | ||
return nodePath.normalize(path).replace(separator, '/'); | ||
return nodePath__default['default'].normalize(path).replace(separator, '/'); | ||
}; | ||
@@ -935,3 +942,3 @@ | ||
if (instancePath.charAt(0) === '.') { | ||
var absoluteInstancePath = nodePath.resolve(rootPath, instancePath); | ||
var absoluteInstancePath = nodePath__default['default'].resolve(rootPath, instancePath); | ||
return absoluteInstancePath; | ||
@@ -961,3 +968,3 @@ } | ||
var hasFilepath = path.hub.file.opts.filename && path.hub.file.opts.filename !== 'unknown'; | ||
var dirname = hasFilepath ? nodePath.dirname(path.hub.file.opts.filename) : ''; | ||
var dirname = hasFilepath ? nodePath__default['default'].dirname(path.hub.file.opts.filename) : ''; | ||
@@ -1094,3 +1101,3 @@ if (!state.pluginMacros[path.node.source.value] && state.emotionInstancePaths.indexOf(getInstancePathToCompare(path.node.source.value, dirname)) !== -1) { | ||
if (!state.cssIdentifier) { | ||
state.cssIdentifier = helperModuleImports.addDefault(path, '@emotion/css', { | ||
state.cssIdentifier = helperModuleImports.addNamed(path, 'css', '@emotion/core', { | ||
nameHint: 'css' | ||
@@ -1097,0 +1104,0 @@ }); |
"use strict"; | ||
function _interopDefault(ex) { | ||
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,3 +7,11 @@ value: !0 | ||
var nodePath = _interopDefault(require("path")), sourceMap = require("source-map"), convert = _interopDefault(require("convert-source-map")), findRoot = _interopDefault(require("find-root")), memoize = _interopDefault(require("@emotion/memoize")), hashString = _interopDefault(require("@emotion/hash")), escapeRegexp = _interopDefault(require("escape-string-regexp")), serialize = require("@emotion/serialize"), helperModuleImports = require("@babel/helper-module-imports"), babelPluginMacros = require("babel-plugin-macros"), multilineCommentRegex = /\/\*[^!](.|[\r\n])*?\*\//g, lineCommentStart = /\/\//g, symbolRegex = /(\s*[;:{},]\s*)/g, countOccurences = function(str, substr) { | ||
var nodePath = require("path"), sourceMap = require("source-map"), convert = require("convert-source-map"), findRoot = require("find-root"), memoize = require("@emotion/memoize"), hashString = require("@emotion/hash"), escapeRegexp = require("escape-string-regexp"), serialize = require("@emotion/serialize"), helperModuleImports = require("@babel/helper-module-imports"), babelPluginMacros = require("babel-plugin-macros"); | ||
function _interopDefault(e) { | ||
return e && e.__esModule ? e : { | ||
default: e | ||
}; | ||
} | ||
var nodePath__default = _interopDefault(nodePath), convert__default = _interopDefault(convert), findRoot__default = _interopDefault(findRoot), memoize__default = _interopDefault(memoize), hashString__default = _interopDefault(hashString), escapeRegexp__default = _interopDefault(escapeRegexp), multilineCommentRegex = /\/\*[^!](.|[\r\n])*?\*\//g, lineCommentStart = /\/\//g, symbolRegex = /(\s*[;:{},]\s*)/g, countOccurences = function(str, substr) { | ||
return str.split(substr).length - 1; | ||
@@ -20,9 +24,9 @@ }, reduceSubstr = function(substrs, join, predicate) { | ||
}, stripLineComment = function(line) { | ||
return reduceSubstr(line.split(lineCommentStart), "//", function(str) { | ||
return reduceSubstr(line.split(lineCommentStart), "//", (function(str) { | ||
return !str.endsWith(":") && countOccurences(str, "'") % 2 == 0 && countOccurences(str, '"') % 2 == 0 && countOccurences(str, "(") === countOccurences(str, ")"); | ||
}); | ||
})); | ||
}, compressSymbols = function(code) { | ||
return code.split(symbolRegex).reduce(function(str, fragment, index) { | ||
return code.split(symbolRegex).reduce((function(str, fragment, index) { | ||
return index % 2 == 0 ? str + fragment : countOccurences(str, "'") % 2 == 0 && countOccurences(str, '"') % 2 == 0 ? str + fragment.trim() : str + fragment; | ||
}, ""); | ||
}), ""); | ||
}, isLineComment = function(line) { | ||
@@ -37,5 +41,5 @@ return line.trim().startsWith("//"); | ||
var minify = function(code) { | ||
var newCode = code.replace(multilineCommentRegex, multilineReplacer).split(linebreakRegex).filter(function(line) { | ||
var newCode = code.replace(multilineCommentRegex, multilineReplacer).split(linebreakRegex).filter((function(line) { | ||
return line.length > 0 && !isLineComment(line); | ||
}).map(stripLineComment).join(" "); | ||
})).map(stripLineComment).join(" "); | ||
return compressSymbols(newCode); | ||
@@ -50,5 +54,5 @@ }; | ||
var interleave = function(strings, interpolations) { | ||
return interpolations.reduce(function(array, interp, i) { | ||
return interpolations.reduce((function(array, interp, i) { | ||
return array.concat([ interp ], strings[i + 1]); | ||
}, [ strings[0] ]); | ||
}), [ strings[0] ]); | ||
}; | ||
@@ -69,21 +73,21 @@ | ||
var strings = [], finalExpressions = [], cursor = 0; | ||
return matches.forEach(function(_ref, i) { | ||
return matches.forEach((function(_ref, i) { | ||
var value = _ref.value, p1 = _ref.p1, index = _ref.index, preMatch = str.substring(cursor, index); | ||
cursor = cursor + preMatch.length + value.length, preMatch ? strings.push(t.stringLiteral(preMatch)) : 0 === i && strings.push(t.stringLiteral("")), | ||
finalExpressions.push(expressions[p1]), i === matches.length - 1 && strings.push(t.stringLiteral(str.substring(index + value.length))); | ||
}), interleave(strings, finalExpressions).filter(function(node) { | ||
})), interleave(strings, finalExpressions).filter((function(node) { | ||
return "" !== node.value; | ||
}); | ||
})); | ||
} | ||
function createRawStringFromTemplateLiteral(quasi) { | ||
var strs = quasi.quasis.map(function(x) { | ||
var strs = quasi.quasis.map((function(x) { | ||
return x.value.cooked; | ||
}); | ||
return strs.reduce(function(arr, str, i) { | ||
})); | ||
return strs.reduce((function(arr, str, i) { | ||
return arr.push(str), i !== strs.length - 1 && arr.push("xxx" + i + "xxx"), arr; | ||
}, []).join("").trim(); | ||
}), []).join("").trim(); | ||
} | ||
var invalidClassNameCharacters = /[!"#$%&'()*+,.\/:;<=>?@[\]^`|}~{]/g, sanitizeLabelPart = function(labelPart) { | ||
var invalidClassNameCharacters = /[!"#$%&'()*+,./:;<=>?@[\]^`|}~{]/g, sanitizeLabelPart = function(labelPart) { | ||
return labelPart.trim().replace(invalidClassNameCharacters, "-"); | ||
@@ -95,3 +99,3 @@ }; | ||
if (!labelFormat) return sanitizeLabelPart(identifierName); | ||
var parsedPath = nodePath.parse(filename), localDirname = nodePath.basename(parsedPath.dir), localFilename = parsedPath.name; | ||
var parsedPath = nodePath__default.default.parse(filename), localDirname = nodePath__default.default.basename(parsedPath.dir), localFilename = parsedPath.name; | ||
return "index" === localFilename && (localFilename = localDirname), labelFormat.replace(/\[local\]/gi, sanitizeLabelPart(identifierName)).replace(/\[filename\]/gi, sanitizeLabelPart(localFilename)).replace(/\[dirname\]/gi, sanitizeLabelPart(localDirname)); | ||
@@ -107,5 +111,5 @@ } | ||
function getDeclaratorName(path, t) { | ||
var parent = path.findParent(function(p) { | ||
var parent = path.findParent((function(p) { | ||
return p.isVariableDeclarator() || p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression() || p.isObjectProperty(); | ||
}); | ||
})); | ||
if (!parent) return ""; | ||
@@ -118,5 +122,5 @@ if (parent.isVariableDeclarator()) return t.isIdentifier(parent.node.id) ? parent.node.id.name : ""; | ||
if (parent.isObjectProperty() && !parent.node.computed) return parent.node.key.name; | ||
var variableDeclarator = path.findParent(function(p) { | ||
var variableDeclarator = path.findParent((function(p) { | ||
return p.isVariableDeclarator(); | ||
}); | ||
})); | ||
if (!variableDeclarator) return ""; | ||
@@ -130,5 +134,5 @@ var name = variableDeclarator.node.id.name; | ||
if (t.isObjectProperty(path.parentPath) && !1 === path.parentPath.node.computed && (t.isIdentifier(path.parentPath.node.key) || t.isStringLiteral(path.parentPath.node.key))) return path.parentPath.node.key.name || path.parentPath.node.key.value; | ||
if (path && (classOrClassPropertyParent = path.findParent(function(p) { | ||
if (path && (classOrClassPropertyParent = path.findParent((function(p) { | ||
return t.isClassProperty(p) || t.isClass(p); | ||
})), classOrClassPropertyParent) { | ||
}))), classOrClassPropertyParent) { | ||
if (t.isClassProperty(classOrClassPropertyParent) && !1 === classOrClassPropertyParent.node.computed && t.isIdentifier(classOrClassPropertyParent.node.key)) return classOrClassPropertyParent.node.key.name; | ||
@@ -162,3 +166,3 @@ if (t.isClass(classOrClassPropertyParent) && classOrClassPropertyParent.node.id) return t.isIdentifier(classOrClassPropertyParent.node.id) ? classOrClassPropertyParent.node.id.name : ""; | ||
original: offset | ||
}), convert.fromObject(generator).toComment({ | ||
}), convert__default.default.fromObject(generator).toComment({ | ||
multiline: !0 | ||
@@ -169,7 +173,7 @@ })) : ""; | ||
var hashArray = function(arr) { | ||
return hashString(arr.join("")); | ||
}, unsafeRequire = require, getPackageRootPath = memoize(function(filename) { | ||
return findRoot(filename); | ||
}), separator = new RegExp(escapeRegexp(nodePath.sep), "g"), normalizePath = function(path) { | ||
return nodePath.normalize(path).replace(separator, "/"); | ||
return hashString__default.default(arr.join("")); | ||
}, unsafeRequire = require, getPackageRootPath = memoize__default.default((function(filename) { | ||
return findRoot__default.default(filename); | ||
})), separator = new RegExp(escapeRegexp__default.default(nodePath__default.default.sep), "g"), normalizePath = function(path) { | ||
return nodePath__default.default.normalize(path).replace(separator, "/"); | ||
}; | ||
@@ -225,5 +229,5 @@ | ||
var declarationInitArguments = declarationInit.get("arguments"); | ||
return !(0 === declarationInitArguments.length || declarationInitArguments.length > 2 || declarationInitArguments.some(function(argPath) { | ||
return !(0 === declarationInitArguments.length || declarationInitArguments.length > 2 || declarationInitArguments.some((function(argPath) { | ||
return !argPath.isArrayExpression(); | ||
})); | ||
}))); | ||
} | ||
@@ -236,13 +240,13 @@ | ||
var makeTemplateObjectCallPath = getTypeScriptMakeTemplateObjectPath(path); | ||
makeTemplateObjectCallPath ? makeTemplateObjectCallPath.get("arguments").forEach(function(argPath) { | ||
makeTemplateObjectCallPath ? makeTemplateObjectCallPath.get("arguments").forEach((function(argPath) { | ||
var elements = argPath.get("elements"), lastElement = elements[elements.length - 1]; | ||
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string)); | ||
}) : isTaggedTemplateTranspiledByBabel(path) || args.push(t.stringLiteral(string)); | ||
})) : isTaggedTemplateTranspiledByBabel(path) || args.push(t.stringLiteral(string)); | ||
} | ||
} | ||
}, joinStringLiterals = function(expressions, t) { | ||
return expressions.reduce(function(finalExpressions, currentExpression, i) { | ||
return expressions.reduce((function(finalExpressions, currentExpression, i) { | ||
return t.isStringLiteral(currentExpression) && t.isStringLiteral(finalExpressions[finalExpressions.length - 1]) ? finalExpressions[finalExpressions.length - 1].value += currentExpression.value : finalExpressions.push(currentExpression), | ||
finalExpressions; | ||
}, []); | ||
}), []); | ||
}, CSS_OBJECT_STRINGIFIED_ERROR = "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop).", cloneNode = function(t, node) { | ||
@@ -264,5 +268,5 @@ return "function" == typeof t.cloneNode ? t.cloneNode(node) : t.cloneDeep(node); | ||
if (t.isCallExpression(path)) { | ||
var canAppendStrings = path.node.arguments.every(function(arg) { | ||
var canAppendStrings = path.node.arguments.every((function(arg) { | ||
return "SpreadElement" !== arg.type; | ||
}); | ||
})); | ||
if (canAppendStrings && shouldLabel) { | ||
@@ -272,5 +276,5 @@ var label = getLabelFromPath(path, state, t); | ||
} | ||
if (path.get("arguments").forEach(function(node) { | ||
if (path.get("arguments").forEach((function(node) { | ||
t.isObjectExpression(node) && node.replaceWith(simplifyObject(node.node, t)); | ||
}), path.node.arguments = joinStringLiterals(path.node.arguments, t), canAppendStrings && state.emotionSourceMap && !sourceMap && void 0 !== path.node.loc && (sourceMap = getSourceMap(path.node.loc.start, state)), | ||
})), path.node.arguments = joinStringLiterals(path.node.arguments, t), canAppendStrings && state.emotionSourceMap && !sourceMap && void 0 !== path.node.loc && (sourceMap = getSourceMap(path.node.loc.start, state)), | ||
1 === path.node.arguments.length && t.isStringLiteral(path.node.arguments[0])) { | ||
@@ -297,6 +301,6 @@ var cssString = path.node.arguments[0].value, res = serialize.serializeStyles([ cssString ]), prodNode = t.objectExpression([ t.objectProperty(t.identifier("name"), t.stringLiteral(res.name)), t.objectProperty(t.identifier("styles"), t.stringLiteral(res.styles)) ]), node = prodNode; | ||
sourceMapDeclaration._compact = !0, state.file.path.unshiftContainer("body", [ sourceMapDeclaration ]), | ||
makeTemplateObjectCallPath.get("arguments").forEach(function(argPath) { | ||
makeTemplateObjectCallPath.get("arguments").forEach((function(argPath) { | ||
var elements = argPath.get("elements"), lastElement = elements[elements.length - 1]; | ||
lastElement.replaceWith(t.binaryExpression("+", lastElement.node, cloneNode(t, sourceMapId))); | ||
}); | ||
})); | ||
} else isTaggedTemplateTranspiledByBabel(path) || path.node.arguments.push(sourceMapConditional); | ||
@@ -307,9 +311,9 @@ } | ||
}, getKnownProperties = function(t, node) { | ||
return new Set(node.properties.filter(function(n) { | ||
return new Set(node.properties.filter((function(n) { | ||
return t.isObjectProperty(n) && !n.computed; | ||
}).map(function(n) { | ||
})).map((function(n) { | ||
return t.isIdentifier(n.key) ? n.key.name : n.key.value; | ||
})); | ||
}))); | ||
}, getStyledOptions = function(t, path, state) { | ||
var args = path.node.arguments, optionsArgument = args.length >= 2 ? args[1] : null, properties = [], knownProperties = optionsArgument && t.isObjectExpression(optionsArgument) ? getKnownProperties(t, optionsArgument) : new Set(); | ||
var args = path.node.arguments, optionsArgument = args.length >= 2 ? args[1] : null, properties = [], knownProperties = optionsArgument && t.isObjectExpression(optionsArgument) ? getKnownProperties(t, optionsArgument) : new Set; | ||
knownProperties.has("target") || properties.push(t.objectProperty(t.identifier("target"), t.stringLiteral(getTargetClassName(state)))); | ||
@@ -324,7 +328,7 @@ var label = getLabelFromPath(path, state, t); | ||
}, createEmotionMacro = function(instancePath) { | ||
return babelPluginMacros.createMacro(function(_ref) { | ||
return babelPluginMacros.createMacro((function(_ref) { | ||
var references = _ref.references, state = _ref.state, babel = _ref.babel; | ||
_ref.isEmotionCall || (state.emotionSourceMap = !0); | ||
var t = babel.types; | ||
Object.keys(references).forEach(function(referenceKey) { | ||
Object.keys(references).forEach((function(referenceKey) { | ||
var isPure = !0, runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, instancePath); | ||
@@ -337,3 +341,3 @@ switch (referenceKey) { | ||
case "keyframes": | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
references[referenceKey].reverse().forEach((function(reference) { | ||
var path = reference.parentPath; | ||
@@ -348,15 +352,15 @@ reference.replaceWith(t.cloneDeep(runtimeNode)), isPure && path.addComment("leading", "#__PURE__"); | ||
node && (path.node.arguments[0] = node); | ||
}); | ||
})); | ||
break; | ||
default: | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
references[referenceKey].reverse().forEach((function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
})); | ||
} | ||
}); | ||
}); | ||
})); | ||
})); | ||
}, createStyledMacro = function(_ref) { | ||
var importPath = _ref.importPath, _ref$originalImportPa = _ref.originalImportPath, originalImportPath = void 0 === _ref$originalImportPa ? importPath : _ref$originalImportPa, isWeb = _ref.isWeb; | ||
return babelPluginMacros.createMacro(function(_ref2) { | ||
return babelPluginMacros.createMacro((function(_ref2) { | ||
var references = _ref2.references, state = _ref2.state, babel = _ref2.babel; | ||
@@ -376,3 +380,3 @@ _ref2.isEmotionCall || (state.emotionSourceMap = !0); | ||
importPath === originalImportPath && (getOriginalImportPathStyledIdentifier = getStyledIdentifier), | ||
references.default.forEach(function(reference) { | ||
references.default.forEach((function(reference) { | ||
var isCall = !1; | ||
@@ -392,13 +396,13 @@ if (t.isMemberExpression(reference.parent) && !1 === reference.parent.computed ? (isCall = !0, | ||
isCall && (reference.addComment("leading", "#__PURE__"), isWeb && (reference.parentPath.node.arguments[1] = getStyledOptions(t, reference.parentPath, state))); | ||
}); | ||
})); | ||
} | ||
Object.keys(references).filter(function(x) { | ||
Object.keys(references).filter((function(x) { | ||
return "default" !== x; | ||
}).forEach(function(referenceKey) { | ||
})).forEach((function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, importPath); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
references[referenceKey].reverse().forEach((function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}); | ||
})); | ||
})); | ||
})); | ||
}, transformCssCallExpression = function(_ref) { | ||
@@ -413,7 +417,7 @@ var babel = _ref.babel, state = _ref.state, path = _ref.path, sourceMap = _ref.sourceMap, node = transformExpressionWithStyles({ | ||
node ? (path.replaceWith(node), path.hoist()) : path.isCallExpression() && path.addComment("leading", "#__PURE__"); | ||
}, cssMacro = babelPluginMacros.createMacro(function(_ref2) { | ||
}, cssMacro = babelPluginMacros.createMacro((function(_ref2) { | ||
var references = _ref2.references, state = _ref2.state, babel = _ref2.babel; | ||
_ref2.isEmotionCall || (state.emotionSourceMap = !0); | ||
var t = babel.types; | ||
references.default && references.default.length && references.default.reverse().forEach(function(reference) { | ||
references.default && references.default.length && references.default.reverse().forEach((function(reference) { | ||
state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(reference, "@emotion/css", { | ||
@@ -426,13 +430,13 @@ nameHint: "css" | ||
}); | ||
}), Object.keys(references).filter(function(x) { | ||
})), Object.keys(references).filter((function(x) { | ||
return "default" !== x; | ||
}).forEach(function(referenceKey) { | ||
})).forEach((function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, "@emotion/css", { | ||
nameHint: referenceKey | ||
}); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
references[referenceKey].reverse().forEach((function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}), webStyledMacro = createStyledMacro({ | ||
})); | ||
})); | ||
})), webStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/styled-base", | ||
@@ -455,4 +459,4 @@ originalImportPath: "@emotion/styled", | ||
var references = _ref.references, state = _ref.state, babel = _ref.babel; | ||
Object.keys(references).forEach(function(refKey) { | ||
"css" === refKey && references[refKey].forEach(function(path) { | ||
Object.keys(references).forEach((function(refKey) { | ||
"css" === refKey && references[refKey].forEach((function(path) { | ||
transformCssCallExpression({ | ||
@@ -463,8 +467,8 @@ babel: babel, | ||
}); | ||
}); | ||
}); | ||
})); | ||
})); | ||
}; | ||
function getAbsolutePath(instancePath, rootPath) { | ||
return "." === instancePath.charAt(0) && nodePath.resolve(rootPath, instancePath); | ||
return "." === instancePath.charAt(0) && nodePath__default.default.resolve(rootPath, instancePath); | ||
} | ||
@@ -484,7 +488,7 @@ | ||
ImportDeclaration: function(path, state) { | ||
var dirname = path.hub.file.opts.filename && "unknown" !== path.hub.file.opts.filename ? nodePath.dirname(path.hub.file.opts.filename) : ""; | ||
var dirname = path.hub.file.opts.filename && "unknown" !== path.hub.file.opts.filename ? nodePath__default.default.dirname(path.hub.file.opts.filename) : ""; | ||
state.pluginMacros[path.node.source.value] || -1 === state.emotionInstancePaths.indexOf(getInstancePathToCompare(path.node.source.value, dirname)) || (state.pluginMacros[path.node.source.value] = createEmotionMacro(path.node.source.value)); | ||
var pluginMacros = state.pluginMacros; | ||
if (void 0 !== pluginMacros[path.node.source.value] && !t.isImportNamespaceSpecifier(path.node.specifiers[0])) { | ||
var imports = path.node.specifiers.map(function(s) { | ||
var imports = path.node.specifiers.map((function(s) { | ||
return { | ||
@@ -494,7 +498,7 @@ localName: s.local.name, | ||
}; | ||
}), shouldExit = !1, hasReferences = !1, referencePathsByImportName = imports.reduce(function(byName, _ref2) { | ||
})), shouldExit = !1, hasReferences = !1, referencePathsByImportName = imports.reduce((function(byName, _ref2) { | ||
var importedName = _ref2.importedName, localName = _ref2.localName, binding = path.scope.getBinding(localName); | ||
return binding ? (byName[importedName] = binding.referencePaths, hasReferences = hasReferences || Boolean(byName[importedName].length), | ||
byName) : (shouldExit = !0, byName); | ||
}, {}); | ||
}), {}); | ||
hasReferences && !shouldExit && (state.file.scope.path.traverse({ | ||
@@ -512,5 +516,5 @@ Identifier: function() {} | ||
Program: function(path, state) { | ||
if (state.emotionInstancePaths = (state.opts.instances || []).map(function(instancePath) { | ||
if (state.emotionInstancePaths = (state.opts.instances || []).map((function(instancePath) { | ||
return getInstancePathToCompare(instancePath, process.cwd()); | ||
}), state.pluginMacros = { | ||
})), state.pluginMacros = { | ||
"@emotion/css": cssMacro, | ||
@@ -534,5 +538,5 @@ "@emotion/styled": webStyledMacro, | ||
var node = _ref3; | ||
if (t.isImportDeclaration(node) && "@emotion/core" === node.source.value && node.specifiers.some(function(x) { | ||
if (t.isImportDeclaration(node) && "@emotion/core" === node.source.value && node.specifiers.some((function(x) { | ||
return t.isImportSpecifier(x) && "jsx" === x.imported.name; | ||
})) { | ||
}))) { | ||
state.transformCssProp = !0; | ||
@@ -554,3 +558,3 @@ break; | ||
sourceMap: sourceMap | ||
}), t.isCallExpression(expressionPath) && (state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(path, "@emotion/css", { | ||
}), t.isCallExpression(expressionPath) && (state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addNamed(path, "css", "@emotion/core", { | ||
nameHint: "css" | ||
@@ -557,0 +561,0 @@ })), expressionPath.get("callee").replaceWith(t.cloneDeep(state.cssIdentifier))); |
@@ -1081,3 +1081,3 @@ import nodePath from 'path'; | ||
if (!state.cssIdentifier) { | ||
state.cssIdentifier = addDefault(path, '@emotion/css', { | ||
state.cssIdentifier = addNamed(path, 'css', '@emotion/core', { | ||
nameHint: 'css' | ||
@@ -1084,0 +1084,0 @@ }); |
{ | ||
"name": "babel-plugin-emotion", | ||
"version": "10.0.33", | ||
"version": "10.2.2", | ||
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.", | ||
@@ -5,0 +5,0 @@ "main": "dist/babel-plugin-emotion.cjs.js", |
@@ -306,3 +306,3 @@ # babel-plugin-emotion | ||
`boolean`, defaults to `true`. | ||
`boolean`, defaults to `true` if an import from `@emotion/core` is found in a file. | ||
@@ -309,0 +309,0 @@ This option assumes that you are using something to make `@emotion/core`'s `jsx` function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option. |
@@ -5,3 +5,3 @@ // @flow | ||
import cssMacro, { transformCssCallExpression } from './css-macro' | ||
import { addDefault } from '@babel/helper-module-imports' | ||
import { addNamed } from '@babel/helper-module-imports' | ||
import nodePath from 'path' | ||
@@ -210,6 +210,7 @@ import { getSourceMap, getStyledOptions } from './utils' | ||
if (!state.cssIdentifier) { | ||
state.cssIdentifier = addDefault(path, '@emotion/css', { | ||
state.cssIdentifier = addNamed(path, 'css', '@emotion/core', { | ||
nameHint: 'css' | ||
}) | ||
} | ||
expressionPath | ||
@@ -216,0 +217,0 @@ .get('callee') |
160511
3509