Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

babel-plugin-emotion.cjs.prod.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. "use strict";
  2. function _interopDefault(ex) {
  3. return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
  4. }
  5. Object.defineProperty(exports, "__esModule", {
  6. value: !0
  7. });
  8. 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) {
  9. return str.split(substr).length - 1;
  10. }, reduceSubstr = function(substrs, join, predicate) {
  11. var length = substrs.length, res = substrs[0];
  12. if (1 === length) return res;
  13. for (var i = 1; i < length && !predicate(res); i++) res += join + substrs[i];
  14. return res;
  15. }, stripLineComment = function(line) {
  16. return reduceSubstr(line.split(lineCommentStart), "//", function(str) {
  17. return !str.endsWith(":") && countOccurences(str, "'") % 2 == 0 && countOccurences(str, '"') % 2 == 0 && countOccurences(str, "(") === countOccurences(str, ")");
  18. });
  19. }, compressSymbols = function(code) {
  20. return code.split(symbolRegex).reduce(function(str, fragment, index) {
  21. return index % 2 == 0 ? str + fragment : countOccurences(str, "'") % 2 == 0 && countOccurences(str, '"') % 2 == 0 ? str + fragment.trim() : str + fragment;
  22. }, "");
  23. }, isLineComment = function(line) {
  24. return line.trim().startsWith("//");
  25. }, linebreakRegex = /[\r\n]\s*/g, spacesAndLinebreakRegex = /\s+|\n+/g;
  26. function multilineReplacer(match) {
  27. return match.indexOf("@") > -1 ? match.replace(spacesAndLinebreakRegex, " ").trim() : "\n";
  28. }
  29. var minify = function(code) {
  30. var newCode = code.replace(multilineCommentRegex, multilineReplacer).split(linebreakRegex).filter(function(line) {
  31. return line.length > 0 && !isLineComment(line);
  32. }).map(stripLineComment).join(" ");
  33. return compressSymbols(newCode);
  34. };
  35. function getExpressionsFromTemplateLiteral(node, t) {
  36. var raw = createRawStringFromTemplateLiteral(node);
  37. return replacePlaceholdersWithExpressions(minify(raw), node.expressions || [], t);
  38. }
  39. var interleave = function(strings, interpolations) {
  40. return interpolations.reduce(function(array, interp, i) {
  41. return array.concat([ interp ], strings[i + 1]);
  42. }, [ strings[0] ]);
  43. };
  44. function getDynamicMatches(str) {
  45. for (var match, re = /xxx(\d+)xxx/gm, matches = []; null !== (match = re.exec(str)); ) null !== match && matches.push({
  46. value: match[0],
  47. p1: parseInt(match[1], 10),
  48. index: match.index
  49. });
  50. return matches;
  51. }
  52. function replacePlaceholdersWithExpressions(str, expressions, t) {
  53. var matches = getDynamicMatches(str);
  54. if (0 === matches.length) return "" === str ? [] : [ t.stringLiteral(str) ];
  55. var strings = [], finalExpressions = [], cursor = 0;
  56. return matches.forEach(function(_ref, i) {
  57. var value = _ref.value, p1 = _ref.p1, index = _ref.index, preMatch = str.substring(cursor, index);
  58. cursor = cursor + preMatch.length + value.length, preMatch ? strings.push(t.stringLiteral(preMatch)) : 0 === i && strings.push(t.stringLiteral("")),
  59. finalExpressions.push(expressions[p1]), i === matches.length - 1 && strings.push(t.stringLiteral(str.substring(index + value.length)));
  60. }), interleave(strings, finalExpressions).filter(function(node) {
  61. return "" !== node.value;
  62. });
  63. }
  64. function createRawStringFromTemplateLiteral(quasi) {
  65. var strs = quasi.quasis.map(function(x) {
  66. return x.value.cooked;
  67. });
  68. return strs.reduce(function(arr, str, i) {
  69. return arr.push(str), i !== strs.length - 1 && arr.push("xxx" + i + "xxx"), arr;
  70. }, []).join("").trim();
  71. }
  72. var invalidClassNameCharacters = /[!"#$%&'()*+,.\/:;<=>?@[\]^`|}~{]/g, sanitizeLabelPart = function(labelPart) {
  73. return labelPart.trim().replace(invalidClassNameCharacters, "-");
  74. };
  75. function getLabel(identifierName, autoLabel, labelFormat, filename) {
  76. if (!identifierName || !autoLabel) return null;
  77. if (!labelFormat) return sanitizeLabelPart(identifierName);
  78. var parsedPath = nodePath.parse(filename), localDirname = nodePath.basename(parsedPath.dir), localFilename = parsedPath.name;
  79. return "index" === localFilename && (localFilename = localDirname), labelFormat.replace(/\[local\]/gi, sanitizeLabelPart(identifierName)).replace(/\[filename\]/gi, sanitizeLabelPart(localFilename)).replace(/\[dirname\]/gi, sanitizeLabelPart(localDirname));
  80. }
  81. function getLabelFromPath(path, state, t) {
  82. return getLabel(getIdentifierName(path, t), void 0 !== state.opts.autoLabel && state.opts.autoLabel, state.opts.labelFormat, state.file.opts.filename);
  83. }
  84. var pascalCaseRegex = /^[A-Z][A-Za-z]+/;
  85. function getDeclaratorName(path, t) {
  86. var parent = path.findParent(function(p) {
  87. return p.isVariableDeclarator() || p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression() || p.isObjectProperty();
  88. });
  89. if (!parent) return "";
  90. if (parent.isVariableDeclarator()) return t.isIdentifier(parent.node.id) ? parent.node.id.name : "";
  91. if (parent.isFunctionDeclaration()) {
  92. var _name = parent.node.id.name;
  93. return pascalCaseRegex.test(_name) ? _name : "";
  94. }
  95. if (parent.isObjectProperty() && !parent.node.computed) return parent.node.key.name;
  96. var variableDeclarator = path.findParent(function(p) {
  97. return p.isVariableDeclarator();
  98. });
  99. if (!variableDeclarator) return "";
  100. var name = variableDeclarator.node.id.name;
  101. return pascalCaseRegex.test(name) ? name : "";
  102. }
  103. function getIdentifierName(path, t) {
  104. var classOrClassPropertyParent;
  105. 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;
  106. if (path && (classOrClassPropertyParent = path.findParent(function(p) {
  107. return t.isClassProperty(p) || t.isClass(p);
  108. })), classOrClassPropertyParent) {
  109. if (t.isClassProperty(classOrClassPropertyParent) && !1 === classOrClassPropertyParent.node.computed && t.isIdentifier(classOrClassPropertyParent.node.key)) return classOrClassPropertyParent.node.key.name;
  110. if (t.isClass(classOrClassPropertyParent) && classOrClassPropertyParent.node.id) return t.isIdentifier(classOrClassPropertyParent.node.id) ? classOrClassPropertyParent.node.id.name : "";
  111. }
  112. var declaratorName = getDeclaratorName(path, t);
  113. return "_" === declaratorName.charAt(0) ? "" : declaratorName;
  114. }
  115. function getGeneratorOpts(file) {
  116. return file.opts.generatorOpts ? file.opts.generatorOpts : file.opts;
  117. }
  118. function makeSourceMapGenerator(file) {
  119. var generatorOpts = getGeneratorOpts(file), filename = generatorOpts.sourceFileName, generator = new sourceMap.SourceMapGenerator({
  120. file: filename,
  121. sourceRoot: generatorOpts.sourceRoot
  122. });
  123. return generator.setSourceContent(filename, file.code), generator;
  124. }
  125. function getSourceMap(offset, state) {
  126. var generator = makeSourceMapGenerator(state.file), generatorOpts = getGeneratorOpts(state.file);
  127. return generatorOpts.sourceFileName && "unknown" !== generatorOpts.sourceFileName ? (generator.addMapping({
  128. generated: {
  129. line: 1,
  130. column: 0
  131. },
  132. source: generatorOpts.sourceFileName,
  133. original: offset
  134. }), convert.fromObject(generator).toComment({
  135. multiline: !0
  136. })) : "";
  137. }
  138. var hashArray = function(arr) {
  139. return hashString(arr.join(""));
  140. }, unsafeRequire = require, getPackageRootPath = memoize(function(filename) {
  141. return findRoot(filename);
  142. }), separator = new RegExp(escapeRegexp(nodePath.sep), "g"), normalizePath = function(path) {
  143. return nodePath.normalize(path).replace(separator, "/");
  144. };
  145. function getTargetClassName(state, t) {
  146. void 0 === state.emotionTargetClassNameCount && (state.emotionTargetClassNameCount = 0);
  147. var filename = state.file.opts.filename && "unknown" !== state.file.opts.filename ? state.file.opts.filename : "", moduleName = "", rootPath = filename;
  148. try {
  149. rootPath = getPackageRootPath(filename), moduleName = unsafeRequire(rootPath + "/package.json").name;
  150. } catch (err) {}
  151. var finalPath = filename === rootPath ? "root" : filename.slice(rootPath.length), positionInFile = state.emotionTargetClassNameCount++, stuffToHash = [ moduleName ];
  152. return finalPath ? stuffToHash.push(normalizePath(finalPath)) : stuffToHash.push(state.file.code),
  153. "e" + hashArray(stuffToHash) + positionInFile;
  154. }
  155. function simplifyObject(node, t) {
  156. for (var finalString = "", i = 0; i < node.properties.length; i++) {
  157. var _ref, property = node.properties[i];
  158. if (!t.isObjectProperty(property) || property.computed || !t.isIdentifier(property.key) && !t.isStringLiteral(property.key) || !t.isStringLiteral(property.value) && !t.isNumericLiteral(property.value) && !t.isObjectExpression(property.value)) return node;
  159. var key = property.key.name || property.key.value;
  160. if ("styles" === key) return node;
  161. if (t.isObjectExpression(property.value)) {
  162. var simplifiedChild = simplifyObject(property.value, t);
  163. if (!t.isStringLiteral(simplifiedChild)) return node;
  164. finalString += key + "{" + simplifiedChild.value + "}";
  165. } else {
  166. var value = property.value.value;
  167. finalString += serialize.serializeStyles([ (_ref = {}, _ref[key] = value, _ref) ]).styles;
  168. }
  169. }
  170. return t.stringLiteral(finalString);
  171. }
  172. function isTaggedTemplateExpressionTranspiledByTypeScript(path) {
  173. if (1 !== path.node.arguments.length) return !1;
  174. var argPath = path.get("arguments")[0];
  175. return argPath.isLogicalExpression() && argPath.get("left").isIdentifier() && argPath.node.left.name.includes("templateObject") && argPath.get("right").isAssignmentExpression() && argPath.get("right").get("right").isCallExpression() && argPath.get("right").get("right").get("callee").isIdentifier() && argPath.node.right.right.callee.name.includes("makeTemplateObject") && 2 === argPath.node.right.right.arguments.length;
  176. }
  177. var appendStringToArguments = function(path, string, t) {
  178. if (string) {
  179. var args = path.node.arguments;
  180. if (t.isStringLiteral(args[args.length - 1])) args[args.length - 1].value += string; else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
  181. path.get("arguments")[0].get("right").get("right").get("arguments").forEach(function(argPath) {
  182. var elements = argPath.get("elements"), lastElement = elements[elements.length - 1];
  183. lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string));
  184. });
  185. } else args.push(t.stringLiteral(string));
  186. }
  187. }, joinStringLiterals = function(expressions, t) {
  188. return expressions.reduce(function(finalExpressions, currentExpression, i) {
  189. return t.isStringLiteral(currentExpression) && t.isStringLiteral(finalExpressions[finalExpressions.length - 1]) ? finalExpressions[finalExpressions.length - 1].value += currentExpression.value : finalExpressions.push(currentExpression),
  190. finalExpressions;
  191. }, []);
  192. }, 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) {
  193. return "function" == typeof t.cloneNode ? t.cloneNode(node) : t.cloneDeep(node);
  194. };
  195. function createSourceMapConditional(t, production, development) {
  196. return t.conditionalExpression(t.binaryExpression("===", t.memberExpression(t.memberExpression(t.identifier("process"), t.identifier("env")), t.identifier("NODE_ENV")), t.stringLiteral("production")), production, development);
  197. }
  198. var transformExpressionWithStyles = function(_ref) {
  199. var babel = _ref.babel, state = _ref.state, path = _ref.path, shouldLabel = _ref.shouldLabel, _ref$sourceMap = _ref.sourceMap, sourceMap = void 0 === _ref$sourceMap ? "" : _ref$sourceMap, t = babel.types;
  200. if (t.isTaggedTemplateExpression(path)) {
  201. var expressions = getExpressionsFromTemplateLiteral(path.node.quasi, t);
  202. state.emotionSourceMap && void 0 !== path.node.quasi.loc && (sourceMap = getSourceMap(path.node.quasi.loc.start, state)),
  203. path.replaceWith(t.callExpression(path.node.tag, expressions));
  204. }
  205. if (t.isCallExpression(path)) {
  206. var canAppendStrings = path.node.arguments.every(function(arg) {
  207. return "SpreadElement" !== arg.type;
  208. });
  209. if (canAppendStrings && shouldLabel) {
  210. var label = getLabelFromPath(path, state, t);
  211. label && appendStringToArguments(path, ";label:" + label + ";", t);
  212. }
  213. var isPure = !0;
  214. if (path.get("arguments").forEach(function(node) {
  215. node.isPure() || (isPure = !1), t.isObjectExpression(node) && node.replaceWith(simplifyObject(node.node, t));
  216. }), path.node.arguments = joinStringLiterals(path.node.arguments, t), canAppendStrings && state.emotionSourceMap && !sourceMap && void 0 !== path.node.loc && (sourceMap = getSourceMap(path.node.loc.start, state)),
  217. 1 === path.node.arguments.length && t.isStringLiteral(path.node.arguments[0])) {
  218. 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;
  219. if (sourceMap) {
  220. if (!state.emotionStringifiedCssId) {
  221. var uid = state.file.scope.generateUidIdentifier("__EMOTION_STRINGIFIED_CSS_ERROR__");
  222. state.emotionStringifiedCssId = uid;
  223. var cssObjectToString = t.functionDeclaration(uid, [], t.blockStatement([ t.returnStatement(t.stringLiteral(CSS_OBJECT_STRINGIFIED_ERROR)) ]));
  224. cssObjectToString._compact = !0, state.file.path.unshiftContainer("body", [ cssObjectToString ]);
  225. }
  226. var devNode = t.objectExpression([ t.objectProperty(t.identifier("name"), t.stringLiteral(res.name)), t.objectProperty(t.identifier("styles"), t.stringLiteral(res.styles)), t.objectProperty(t.identifier("map"), t.stringLiteral(sourceMap)), t.objectProperty(t.identifier("toString"), cloneNode(t, state.emotionStringifiedCssId)) ]);
  227. node = createSourceMapConditional(t, prodNode, devNode);
  228. }
  229. return {
  230. node: node,
  231. isPure: !0
  232. };
  233. }
  234. if (sourceMap) {
  235. var lastIndex = path.node.arguments.length - 1, last = path.node.arguments[lastIndex], sourceMapConditional = createSourceMapConditional(t, t.stringLiteral(""), t.stringLiteral(sourceMap));
  236. if (t.isStringLiteral(last)) path.node.arguments[lastIndex] = t.binaryExpression("+", last, sourceMapConditional); else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
  237. path.get("arguments")[0].get("right").get("right").get("arguments").forEach(function(argPath) {
  238. var elements = argPath.get("elements"), lastElement = elements[elements.length - 1];
  239. lastElement.replaceWith(t.binaryExpression("+", lastElement.node, cloneNode(t, sourceMapConditional)));
  240. });
  241. } else path.node.arguments.push(sourceMapConditional);
  242. }
  243. return {
  244. node: void 0,
  245. isPure: isPure
  246. };
  247. }
  248. return {
  249. node: void 0,
  250. isPure: !1
  251. };
  252. }, getStyledOptions = function(t, path, state) {
  253. var properties = [ t.objectProperty(t.identifier("target"), t.stringLiteral(getTargetClassName(state))) ], label = getLabelFromPath(path, state, t);
  254. label && properties.push(t.objectProperty(t.identifier("label"), t.stringLiteral(label)));
  255. var args = path.node.arguments, optionsArgument = args.length >= 2 ? args[1] : null;
  256. if (optionsArgument) {
  257. if (!t.isObjectExpression(optionsArgument)) return t.callExpression(state.file.addHelper("extends"), [ t.objectExpression([]), t.objectExpression(properties), optionsArgument ]);
  258. properties.unshift.apply(properties, optionsArgument.properties);
  259. }
  260. return t.objectExpression(properties);
  261. }, createEmotionMacro = function(instancePath) {
  262. return babelPluginMacros.createMacro(function(_ref) {
  263. var references = _ref.references, state = _ref.state, babel = _ref.babel;
  264. _ref.isEmotionCall || (state.emotionSourceMap = !0);
  265. var t = babel.types;
  266. Object.keys(references).forEach(function(referenceKey) {
  267. var isPure = !0, runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, instancePath);
  268. switch (referenceKey) {
  269. case "injectGlobal":
  270. isPure = !1;
  271. case "css":
  272. case "keyframes":
  273. references[referenceKey].reverse().forEach(function(reference) {
  274. var path = reference.parentPath;
  275. reference.replaceWith(t.cloneDeep(runtimeNode)), isPure && path.addComment("leading", "#__PURE__");
  276. var node = transformExpressionWithStyles({
  277. babel: babel,
  278. state: state,
  279. path: path,
  280. shouldLabel: !0
  281. }).node;
  282. node && (path.node.arguments[0] = node);
  283. });
  284. break;
  285. default:
  286. references[referenceKey].reverse().forEach(function(reference) {
  287. reference.replaceWith(t.cloneDeep(runtimeNode));
  288. });
  289. }
  290. });
  291. });
  292. }, createStyledMacro = function(_ref) {
  293. var importPath = _ref.importPath, _ref$originalImportPa = _ref.originalImportPath, originalImportPath = void 0 === _ref$originalImportPa ? importPath : _ref$originalImportPa, isWeb = _ref.isWeb;
  294. return babelPluginMacros.createMacro(function(_ref2) {
  295. var references = _ref2.references, state = _ref2.state, babel = _ref2.babel;
  296. _ref2.isEmotionCall || (state.emotionSourceMap = !0);
  297. var t = babel.types;
  298. if (references.default && references.default.length) {
  299. var _styledIdentifier, originalImportPathStyledIdentifier, getStyledIdentifier = function() {
  300. return void 0 === _styledIdentifier && (_styledIdentifier = helperModuleImports.addDefault(state.file.path, importPath, {
  301. nameHint: "styled"
  302. })), t.cloneDeep(_styledIdentifier);
  303. }, getOriginalImportPathStyledIdentifier = function() {
  304. return void 0 === originalImportPathStyledIdentifier && (originalImportPathStyledIdentifier = helperModuleImports.addDefault(state.file.path, originalImportPath, {
  305. nameHint: "styled"
  306. })), t.cloneDeep(originalImportPathStyledIdentifier);
  307. };
  308. importPath === originalImportPath && (getOriginalImportPathStyledIdentifier = getStyledIdentifier),
  309. references.default.forEach(function(reference) {
  310. var isCall = !1;
  311. if (t.isMemberExpression(reference.parent) && !1 === reference.parent.computed ? (isCall = !0,
  312. reference.parent.property.name.charCodeAt(0) > 96 ? reference.parentPath.replaceWith(t.callExpression(getStyledIdentifier(), [ t.stringLiteral(reference.parent.property.name) ])) : reference.replaceWith(getStyledIdentifier())) : reference.parentPath && reference.parentPath.parentPath && t.isCallExpression(reference.parentPath) && reference.parent.callee === reference.node ? (isCall = !0,
  313. reference.replaceWith(getStyledIdentifier())) : reference.replaceWith(getOriginalImportPathStyledIdentifier()),
  314. reference.parentPath && reference.parentPath.parentPath) {
  315. var styledCallPath = reference.parentPath.parentPath, node = transformExpressionWithStyles({
  316. path: styledCallPath,
  317. state: state,
  318. babel: babel,
  319. shouldLabel: !1
  320. }).node;
  321. node && isWeb && (styledCallPath.node.arguments[0] = node);
  322. }
  323. isCall && (reference.addComment("leading", "#__PURE__"), isWeb && (reference.parentPath.node.arguments[1] = getStyledOptions(t, reference.parentPath, state)));
  324. });
  325. }
  326. Object.keys(references).filter(function(x) {
  327. return "default" !== x;
  328. }).forEach(function(referenceKey) {
  329. var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, importPath);
  330. references[referenceKey].reverse().forEach(function(reference) {
  331. reference.replaceWith(t.cloneDeep(runtimeNode));
  332. });
  333. });
  334. });
  335. }, transformCssCallExpression = function(_ref) {
  336. var babel = _ref.babel, state = _ref.state, path = _ref.path, sourceMap = _ref.sourceMap, _transformExpressionW = transformExpressionWithStyles({
  337. babel: babel,
  338. state: state,
  339. path: path,
  340. shouldLabel: !0,
  341. sourceMap: sourceMap
  342. }), node = _transformExpressionW.node, isPure = _transformExpressionW.isPure;
  343. node ? (path.replaceWith(node), isPure && path.hoist()) : path.addComment("leading", "#__PURE__");
  344. }, cssMacro = babelPluginMacros.createMacro(function(_ref2) {
  345. var references = _ref2.references, state = _ref2.state, babel = _ref2.babel;
  346. _ref2.isEmotionCall || (state.emotionSourceMap = !0);
  347. var t = babel.types;
  348. references.default && references.default.length && references.default.reverse().forEach(function(reference) {
  349. state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(reference, "@emotion/css", {
  350. nameHint: "css"
  351. })), reference.replaceWith(t.cloneDeep(state.cssIdentifier)), transformCssCallExpression({
  352. babel: babel,
  353. state: state,
  354. path: reference.parentPath
  355. });
  356. }), Object.keys(references).filter(function(x) {
  357. return "default" !== x;
  358. }).forEach(function(referenceKey) {
  359. var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, "@emotion/css", {
  360. nameHint: referenceKey
  361. });
  362. references[referenceKey].reverse().forEach(function(reference) {
  363. reference.replaceWith(t.cloneDeep(runtimeNode));
  364. });
  365. });
  366. }), webStyledMacro = createStyledMacro({
  367. importPath: "@emotion/styled-base",
  368. originalImportPath: "@emotion/styled",
  369. isWeb: !0
  370. }), nativeStyledMacro = createStyledMacro({
  371. importPath: "@emotion/native",
  372. originalImportPath: "@emotion/native",
  373. isWeb: !1
  374. }), primitivesStyledMacro = createStyledMacro({
  375. importPath: "@emotion/primitives",
  376. originalImportPath: "@emotion/primitives",
  377. isWeb: !1
  378. }), macros = {
  379. createEmotionMacro: createEmotionMacro,
  380. css: cssMacro,
  381. createStyledMacro: createStyledMacro
  382. }, emotionCoreMacroThatsNotARealMacro = function(_ref) {
  383. var references = _ref.references, state = _ref.state, babel = _ref.babel;
  384. Object.keys(references).forEach(function(refKey) {
  385. "css" === refKey && references[refKey].forEach(function(path) {
  386. transformCssCallExpression({
  387. babel: babel,
  388. state: state,
  389. path: path.parentPath
  390. });
  391. });
  392. });
  393. };
  394. function getAbsolutePath(instancePath, rootPath) {
  395. return "." === instancePath.charAt(0) && nodePath.resolve(rootPath, instancePath);
  396. }
  397. function getInstancePathToCompare(instancePath, rootPath) {
  398. var absolutePath = getAbsolutePath(instancePath, rootPath);
  399. return !1 === absolutePath ? instancePath : absolutePath;
  400. }
  401. function index(babel) {
  402. var t = babel.types;
  403. return {
  404. name: "emotion",
  405. inherits: require("babel-plugin-syntax-jsx"),
  406. visitor: {
  407. ImportDeclaration: function(path, state) {
  408. var dirname = path.hub.file.opts.filename && "unknown" !== path.hub.file.opts.filename ? nodePath.dirname(path.hub.file.opts.filename) : "";
  409. 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));
  410. var pluginMacros = state.pluginMacros;
  411. if (void 0 !== pluginMacros[path.node.source.value] && !t.isImportNamespaceSpecifier(path.node.specifiers[0])) {
  412. var imports = path.node.specifiers.map(function(s) {
  413. return {
  414. localName: s.local.name,
  415. importedName: "ImportDefaultSpecifier" === s.type ? "default" : s.imported.name
  416. };
  417. }), shouldExit = !1, hasReferences = !1, referencePathsByImportName = imports.reduce(function(byName, _ref2) {
  418. var importedName = _ref2.importedName, localName = _ref2.localName, binding = path.scope.getBinding(localName);
  419. return binding ? (byName[importedName] = binding.referencePaths, hasReferences = hasReferences || Boolean(byName[importedName].length),
  420. byName) : (shouldExit = !0, byName);
  421. }, {});
  422. hasReferences && !shouldExit && (state.file.scope.path.traverse({
  423. Identifier: function() {}
  424. }), pluginMacros[path.node.source.value]({
  425. references: referencePathsByImportName,
  426. state: state,
  427. babel: babel,
  428. isBabelMacrosCall: !0,
  429. isEmotionCall: !0
  430. }), pluginMacros[path.node.source.value].keepImport || path.remove());
  431. }
  432. },
  433. Program: function(path, state) {
  434. if (state.emotionInstancePaths = (state.opts.instances || []).map(function(instancePath) {
  435. return getInstancePathToCompare(instancePath, process.cwd());
  436. }), state.pluginMacros = {
  437. "@emotion/css": cssMacro,
  438. "@emotion/styled": webStyledMacro,
  439. "@emotion/core": emotionCoreMacroThatsNotARealMacro,
  440. "@emotion/primitives": primitivesStyledMacro,
  441. "@emotion/native": nativeStyledMacro,
  442. emotion: createEmotionMacro("emotion")
  443. }, void 0 === state.opts.cssPropOptimization) {
  444. var _iterator = path.node.body, _isArray = Array.isArray(_iterator), _i = 0;
  445. for (_iterator = _isArray ? _iterator : _iterator[Symbol.iterator](); ;) {
  446. var _ref3;
  447. if (_isArray) {
  448. if (_i >= _iterator.length) break;
  449. _ref3 = _iterator[_i++];
  450. } else {
  451. if ((_i = _iterator.next()).done) break;
  452. _ref3 = _i.value;
  453. }
  454. var node = _ref3;
  455. if (t.isImportDeclaration(node) && "@emotion/core" === node.source.value && node.specifiers.some(function(x) {
  456. return t.isImportSpecifier(x) && "jsx" === x.imported.name;
  457. })) {
  458. state.transformCssProp = !0;
  459. break;
  460. }
  461. }
  462. } else state.transformCssProp = state.opts.cssPropOptimization;
  463. !1 === state.opts.sourceMap ? state.emotionSourceMap = !1 : state.emotionSourceMap = !0;
  464. },
  465. JSXAttribute: function(path, state) {
  466. if ("css" === path.node.name.name && state.transformCssProp && t.isJSXExpressionContainer(path.node.value) && (t.isObjectExpression(path.node.value.expression) || t.isArrayExpression(path.node.value.expression))) {
  467. var expressionPath = path.get("value.expression"), sourceMap = state.emotionSourceMap && void 0 !== path.node.loc ? getSourceMap(path.node.loc.start, state) : "";
  468. expressionPath.replaceWith(t.callExpression(t.identifier("___shouldNeverAppearCSS"), [ path.node.value.expression ])),
  469. transformCssCallExpression({
  470. babel: babel,
  471. state: state,
  472. path: expressionPath,
  473. sourceMap: sourceMap
  474. }), t.isCallExpression(expressionPath) && (state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(path, "@emotion/css", {
  475. nameHint: "css"
  476. })), expressionPath.get("callee").replaceWith(t.cloneDeep(state.cssIdentifier)));
  477. }
  478. },
  479. CallExpression: {
  480. exit: function(path, state) {
  481. try {
  482. if (path.node.callee && path.node.callee.property && "withComponent" === path.node.callee.property.name) switch (path.node.arguments.length) {
  483. case 1:
  484. case 2:
  485. path.node.arguments[1] = getStyledOptions(t, path, state);
  486. }
  487. } catch (e) {
  488. throw path.buildCodeFrameError(e);
  489. }
  490. }
  491. }
  492. }
  493. };
  494. }
  495. emotionCoreMacroThatsNotARealMacro.keepImport = !0, exports.default = index, exports.macros = macros;