babel-plugin-emotion
Advanced tools
Comparing version 10.0.9 to 10.0.13
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function _interopDefault(ex) { | ||
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; | ||
} | ||
var nodePath = _interopDefault(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 serialize = require('@emotion/serialize'); | ||
var helperModuleImports = require('@babel/helper-module-imports'); | ||
var babelPluginMacros = require('babel-plugin-macros'); | ||
// babel-plugin-styled-components | ||
var babelPluginMacros = require('babel-plugin-macros'); // babel-plugin-styled-components | ||
// https://github.com/styled-components/babel-plugin-styled-components/blob/8d44acc36f067d60d4e09f9c22ff89695bc332d2/src/minify/index.js | ||
var multilineCommentRegex = /\/\*[^!](.|[\r\n])*?\*\//g; | ||
@@ -56,2 +69,3 @@ var lineCommentStart = /\/\//g; | ||
}; | ||
var compressSymbols = function compressSymbols(code) { | ||
@@ -73,2 +87,3 @@ return code.split(symbolRegex).reduce(function (str, fragment, index) { | ||
var isLineComment = function isLineComment(line) { | ||
@@ -79,2 +94,3 @@ return line.trim().startsWith('//'); | ||
var linebreakRegex = /[\r\n]\s*/g; | ||
var minify = function minify(code) { | ||
@@ -195,2 +211,3 @@ var newCode = code.replace(multilineCommentRegex, '\n') // Remove multiline comments | ||
} | ||
var pascalCaseRegex = /^[A-Z][A-Za-z]+/; | ||
@@ -201,3 +218,3 @@ | ||
var parent = path.findParent(function (p) { | ||
return p.isVariableDeclarator() || p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression(); | ||
return p.isVariableDeclarator() || p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression() || p.isObjectProperty(); | ||
}); | ||
@@ -207,7 +224,7 @@ | ||
return ''; | ||
} | ||
} // we probably have a css call assigned to a variable | ||
// so we'll just return the variable name | ||
if (parent.isVariableDeclarator()) { | ||
// we probably have a css call assigned to a variable | ||
// so we'll just return the variable name | ||
return parent.node.id.name; | ||
@@ -225,2 +242,7 @@ } // we probably have an inline css prop usage | ||
return ''; | ||
} // we could also have an object property | ||
if (parent.isObjectProperty()) { | ||
return parent.node.key.name; | ||
} | ||
@@ -292,2 +314,3 @@ | ||
} | ||
function getSourceMap(offset, state) { | ||
@@ -356,7 +379,6 @@ var generator = makeSourceMapGenerator(state.file); | ||
return stableClassName; | ||
} | ||
// it's meant to simplify the most common cases so i don't want to make it especially complex | ||
} // it's meant to simplify the most common cases so i don't want to make it especially complex | ||
// also, this will be unnecessary when prepack is ready | ||
function simplifyObject(node, t) { | ||
@@ -411,2 +433,3 @@ var finalString = ''; | ||
}; | ||
var joinStringLiterals = function joinStringLiterals(expressions, t) { | ||
@@ -436,3 +459,3 @@ return expressions.reduce(function (finalExpressions, currentExpression, i) { | ||
_ref$sourceMap = _ref.sourceMap, | ||
sourceMap$$1 = _ref$sourceMap === void 0 ? '' : _ref$sourceMap; | ||
sourceMap = _ref$sourceMap === void 0 ? '' : _ref$sourceMap; | ||
var t = babel.types; | ||
@@ -444,3 +467,3 @@ | ||
if (state.emotionSourceMap && path.node.quasi.loc !== undefined) { | ||
sourceMap$$1 = getSourceMap(path.node.quasi.loc.start, state); | ||
sourceMap = getSourceMap(path.node.quasi.loc.start, state); | ||
} | ||
@@ -476,4 +499,4 @@ | ||
if (canAppendStrings && state.emotionSourceMap && !sourceMap$$1 && path.node.loc !== undefined) { | ||
sourceMap$$1 = getSourceMap(path.node.loc.start, state); | ||
if (canAppendStrings && state.emotionSourceMap && !sourceMap && path.node.loc !== undefined) { | ||
sourceMap = getSourceMap(path.node.loc.start, state); | ||
} | ||
@@ -487,4 +510,4 @@ | ||
if (sourceMap$$1) { | ||
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$$1))]); | ||
if (sourceMap) { | ||
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))]); | ||
node = createSourceMapConditional(t, prodNode, devNode); | ||
@@ -499,6 +522,6 @@ } | ||
if (sourceMap$$1) { | ||
if (sourceMap) { | ||
var lastIndex = path.node.arguments.length - 1; | ||
var last = path.node.arguments[lastIndex]; | ||
var sourceMapConditional = createSourceMapConditional(t, t.stringLiteral(''), t.stringLiteral(sourceMap$$1)); | ||
var sourceMapConditional = createSourceMapConditional(t, t.stringLiteral(''), t.stringLiteral(sourceMap)); | ||
@@ -716,3 +739,3 @@ if (t.isStringLiteral(last)) { | ||
path = _ref.path, | ||
sourceMap$$1 = _ref.sourceMap; | ||
sourceMap = _ref.sourceMap; | ||
@@ -724,3 +747,3 @@ var _transformExpressionW = transformExpressionWithStyles({ | ||
shouldLabel: true, | ||
sourceMap: sourceMap$$1 | ||
sourceMap: sourceMap | ||
}), | ||
@@ -740,2 +763,3 @@ node = _transformExpressionW.node, | ||
}; | ||
var cssMacro = babelPluginMacros.createMacro(function (_ref2) { | ||
@@ -781,3 +805,2 @@ var references = _ref2.references, | ||
}); | ||
var webStyledMacro = createStyledMacro({ | ||
@@ -842,3 +865,3 @@ importPath: '@emotion/styled-base', | ||
function index (babel) { | ||
function index(babel) { | ||
var t = babel.types; | ||
@@ -970,3 +993,3 @@ return { | ||
var expressionPath = path.get('value.expression'); | ||
var sourceMap$$1 = state.emotionSourceMap && path.node.loc !== undefined ? getSourceMap(path.node.loc.start, state) : ''; | ||
var sourceMap = state.emotionSourceMap && path.node.loc !== undefined ? getSourceMap(path.node.loc.start, state) : ''; | ||
expressionPath.replaceWith(t.callExpression( // the name of this identifier doesn't really matter at all | ||
@@ -979,3 +1002,3 @@ // it'll never appear in generated code | ||
path: expressionPath, | ||
sourceMap: sourceMap$$1 | ||
sourceMap: sourceMap | ||
}); | ||
@@ -1015,3 +1038,3 @@ | ||
exports.default = index; | ||
exports.macros = macros; | ||
exports.default = index; |
"use strict"; | ||
function _interopDefault(ex) { | ||
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex; | ||
} | ||
Object.defineProperty(exports, "__esModule", { 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) { | ||
return str.split(substr).length - 1; | ||
}, | ||
reduceSubstr = function(substrs, join, predicate) { | ||
var length = substrs.length, | ||
res = substrs[0]; | ||
if (1 === length) return res; | ||
for (var i = 1; i < length && !predicate(res); i++) | ||
res += join + substrs[i]; | ||
return res; | ||
}, | ||
stripLineComment = function(line) { | ||
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 index % 2 == 0 | ||
? str + fragment | ||
: countOccurences(str, "'") % 2 == 0 && | ||
countOccurences(str, '"') % 2 == 0 | ||
? str + fragment.trim() | ||
: str + fragment; | ||
}, ""); | ||
}, | ||
isLineComment = function(line) { | ||
return line.trim().startsWith("//"); | ||
}, | ||
linebreakRegex = /[\r\n]\s*/g, | ||
minify = function(code) { | ||
var newCode = code | ||
.replace(multilineCommentRegex, "\n") | ||
.split(linebreakRegex) | ||
.filter(function(line) { | ||
return 0 < line.length && !isLineComment(line); | ||
}) | ||
.map(stripLineComment) | ||
.join(" "); | ||
return compressSymbols(newCode); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { | ||
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) { | ||
return str.split(substr).length - 1; | ||
}, reduceSubstr = function(substrs, join, predicate) { | ||
var length = substrs.length, res = substrs[0]; | ||
if (1 === length) return res; | ||
for (var i = 1; i < length && !predicate(res); i++) res += join + substrs[i]; | ||
return res; | ||
}, stripLineComment = function(line) { | ||
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 index % 2 == 0 ? str + fragment : countOccurences(str, "'") % 2 == 0 && countOccurences(str, '"') % 2 == 0 ? str + fragment.trim() : str + fragment; | ||
}, ""); | ||
}, isLineComment = function(line) { | ||
return line.trim().startsWith("//"); | ||
}, linebreakRegex = /[\r\n]\s*/g, minify = function(code) { | ||
var newCode = code.replace(multilineCommentRegex, "\n").split(linebreakRegex).filter(function(line) { | ||
return line.length > 0 && !isLineComment(line); | ||
}).map(stripLineComment).join(" "); | ||
return compressSymbols(newCode); | ||
}; | ||
function getExpressionsFromTemplateLiteral(node, t) { | ||
var raw = createRawStringFromTemplateLiteral(node); | ||
return replacePlaceholdersWithExpressions( | ||
minify(raw), | ||
node.expressions || [], | ||
t | ||
); | ||
return replacePlaceholdersWithExpressions(minify(raw), node.expressions || [], t); | ||
} | ||
var interleave = function(strings, interpolations) { | ||
return interpolations.reduce( | ||
function(array, interp, i) { | ||
return array.concat([interp], strings[i + 1]); | ||
}, | ||
[strings[0]] | ||
); | ||
return interpolations.reduce(function(array, interp, i) { | ||
return array.concat([ interp ], strings[i + 1]); | ||
}, [ strings[0] ]); | ||
}; | ||
function getDynamicMatches(str) { | ||
for ( | ||
var match, re = /xxx(\d+)xxx/gm, matches = []; | ||
null !== (match = re.exec(str)); | ||
) | ||
null !== match && | ||
matches.push({ | ||
value: match[0], | ||
p1: parseInt(match[1], 10), | ||
index: match.index | ||
}); | ||
for (var match, re = /xxx(\d+)xxx/gm, matches = []; null !== (match = re.exec(str)); ) null !== match && matches.push({ | ||
value: match[0], | ||
p1: parseInt(match[1], 10), | ||
index: match.index | ||
}); | ||
return matches; | ||
} | ||
function replacePlaceholdersWithExpressions(str, expressions, t) { | ||
var matches = getDynamicMatches(str); | ||
if (0 === matches.length) return "" === str ? [] : [t.stringLiteral(str)]; | ||
var strings = [], | ||
finalExpressions = [], | ||
cursor = 0; | ||
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) { | ||
return "" !== node.value; | ||
}) | ||
); | ||
if (0 === matches.length) return "" === str ? [] : [ t.stringLiteral(str) ]; | ||
var strings = [], finalExpressions = [], cursor = 0; | ||
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) { | ||
return "" !== node.value; | ||
}); | ||
} | ||
function createRawStringFromTemplateLiteral(quasi) { | ||
@@ -124,43 +72,24 @@ var strs = quasi.quasis.map(function(x) { | ||
}); | ||
return strs | ||
.reduce(function(arr, str, i) { | ||
return ( | ||
arr.push(str), i !== strs.length - 1 && arr.push("xxx" + i + "xxx"), arr | ||
); | ||
}, []) | ||
.join("") | ||
.trim(); | ||
return strs.reduce(function(arr, str, i) { | ||
return arr.push(str), i !== strs.length - 1 && arr.push("xxx" + i + "xxx"), arr; | ||
}, []).join("").trim(); | ||
} | ||
function getLabel(identifierName, autoLabel, labelFormat, filename) { | ||
if (!identifierName || !autoLabel) return null; | ||
if (!labelFormat) return identifierName.trim(); | ||
var parsedPath = nodePath.parse(filename), | ||
localDirname = nodePath.basename(parsedPath.dir), | ||
localFilename = parsedPath.name; | ||
return ( | ||
"index" === localFilename && (localFilename = localDirname), | ||
(localFilename = localFilename.replace(".", "-")), | ||
labelFormat | ||
.replace(/\[local\]/gi, identifierName.trim()) | ||
.replace(/\[filename\]/gi, localFilename) | ||
.replace(/\[dirname\]/gi, localDirname) | ||
); | ||
var parsedPath = nodePath.parse(filename), localDirname = nodePath.basename(parsedPath.dir), localFilename = parsedPath.name; | ||
return "index" === localFilename && (localFilename = localDirname), localFilename = localFilename.replace(".", "-"), | ||
labelFormat.replace(/\[local\]/gi, identifierName.trim()).replace(/\[filename\]/gi, localFilename).replace(/\[dirname\]/gi, localDirname); | ||
} | ||
function getLabelFromPath(path, state, t) { | ||
return getLabel( | ||
getIdentifierName(path, t), | ||
void 0 !== state.opts.autoLabel && state.opts.autoLabel, | ||
state.opts.labelFormat, | ||
state.file.opts.filename | ||
); | ||
return getLabel(getIdentifierName(path, t), void 0 !== state.opts.autoLabel && state.opts.autoLabel, state.opts.labelFormat, state.file.opts.filename); | ||
} | ||
var pascalCaseRegex = /^[A-Z][A-Za-z]+/; | ||
function getDeclaratorName(path, t) { | ||
var parent = path.findParent(function(p) { | ||
return ( | ||
p.isVariableDeclarator() || | ||
p.isFunctionDeclaration() || | ||
p.isFunctionExpression() || | ||
p.isArrowFunctionExpression() | ||
); | ||
return p.isVariableDeclarator() || p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression() || p.isObjectProperty(); | ||
}); | ||
@@ -173,2 +102,3 @@ if (!parent) return ""; | ||
} | ||
if (parent.isObjectProperty()) return parent.node.key.name; | ||
var variableDeclarator = path.findParent(function(p) { | ||
@@ -181,31 +111,11 @@ return p.isVariableDeclarator(); | ||
} | ||
function getIdentifierName(path, t) { | ||
var classOrClassPropertyParent; | ||
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) { | ||
return t.isClassProperty(p) || t.isClass(p); | ||
})), | ||
classOrClassPropertyParent) | ||
) { | ||
if ( | ||
t.isClassProperty(classOrClassPropertyParent) && | ||
!1 === classOrClassPropertyParent.node.computed && | ||
t.isIdentifier(classOrClassPropertyParent.node.key) | ||
) | ||
return classOrClassPropertyParent.node.key.name; | ||
if ( | ||
t.isClass(classOrClassPropertyParent) && | ||
classOrClassPropertyParent.node.id | ||
) | ||
return t.isIdentifier(classOrClassPropertyParent.node.id) | ||
? classOrClassPropertyParent.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) { | ||
return t.isClassProperty(p) || t.isClass(p); | ||
})), classOrClassPropertyParent) { | ||
if (t.isClassProperty(classOrClassPropertyParent) && !1 === classOrClassPropertyParent.node.computed && t.isIdentifier(classOrClassPropertyParent.node.key)) return classOrClassPropertyParent.node.key.name; | ||
if (t.isClass(classOrClassPropertyParent) && classOrClassPropertyParent.node.id) return t.isIdentifier(classOrClassPropertyParent.node.id) ? classOrClassPropertyParent.node.id.name : ""; | ||
} | ||
@@ -215,71 +125,52 @@ var declaratorName = getDeclaratorName(path, t); | ||
} | ||
function getGeneratorOpts(file) { | ||
return file.opts.generatorOpts ? file.opts.generatorOpts : file.opts; | ||
} | ||
function makeSourceMapGenerator(file) { | ||
var generatorOpts = getGeneratorOpts(file), | ||
filename = generatorOpts.sourceFileName, | ||
generator = new sourceMap.SourceMapGenerator({ | ||
file: filename, | ||
sourceRoot: generatorOpts.sourceRoot | ||
}); | ||
var generatorOpts = getGeneratorOpts(file), filename = generatorOpts.sourceFileName, generator = new sourceMap.SourceMapGenerator({ | ||
file: filename, | ||
sourceRoot: generatorOpts.sourceRoot | ||
}); | ||
return generator.setSourceContent(filename, file.code), generator; | ||
} | ||
function getSourceMap(offset, state) { | ||
var generator = makeSourceMapGenerator(state.file), | ||
generatorOpts = getGeneratorOpts(state.file); | ||
return generatorOpts.sourceFileName | ||
? (generator.addMapping({ | ||
generated: { line: 1, column: 0 }, | ||
source: generatorOpts.sourceFileName, | ||
original: offset | ||
}), | ||
convert.fromObject(generator).toComment({ multiline: !0 })) | ||
: ""; | ||
var generator = makeSourceMapGenerator(state.file), generatorOpts = getGeneratorOpts(state.file); | ||
return generatorOpts.sourceFileName ? (generator.addMapping({ | ||
generated: { | ||
line: 1, | ||
column: 0 | ||
}, | ||
source: generatorOpts.sourceFileName, | ||
original: offset | ||
}), convert.fromObject(generator).toComment({ | ||
multiline: !0 | ||
})) : ""; | ||
} | ||
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(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, "/"); | ||
}; | ||
function getTargetClassName(state, t) { | ||
void 0 === state.emotionTargetClassNameCount && | ||
(state.emotionTargetClassNameCount = 0); | ||
var filename = state.file.opts.filename, | ||
moduleName = "", | ||
rootPath = filename; | ||
void 0 === state.emotionTargetClassNameCount && (state.emotionTargetClassNameCount = 0); | ||
var filename = state.file.opts.filename, moduleName = "", rootPath = filename; | ||
try { | ||
(rootPath = getPackageRootPath(filename)), | ||
(moduleName = unsafeRequire(rootPath + "/package.json").name); | ||
rootPath = getPackageRootPath(filename), moduleName = unsafeRequire(rootPath + "/package.json").name; | ||
} catch (err) {} | ||
var finalPath = | ||
filename === rootPath ? "root" : filename.slice(rootPath.length), | ||
positionInFile = state.emotionTargetClassNameCount++, | ||
stuffToHash = [moduleName]; | ||
return ( | ||
finalPath | ||
? stuffToHash.push(normalizePath(finalPath)) | ||
: stuffToHash.push(state.file.code), | ||
"e" + hashArray(stuffToHash) + positionInFile | ||
); | ||
var finalPath = filename === rootPath ? "root" : filename.slice(rootPath.length), positionInFile = state.emotionTargetClassNameCount++, stuffToHash = [ moduleName ]; | ||
return finalPath ? stuffToHash.push(normalizePath(finalPath)) : stuffToHash.push(state.file.code), | ||
"e" + hashArray(stuffToHash) + positionInFile; | ||
} | ||
function simplifyObject(node, t) { | ||
for (var finalString = "", i = 0; i < node.properties.length; i++) { | ||
var _ref, | ||
property = node.properties[i]; | ||
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; | ||
var _ref, property = node.properties[i]; | ||
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; | ||
var key = property.key.name || property.key.value; | ||
@@ -293,5 +184,3 @@ if ("styles" === key) return node; | ||
var value = property.value.value; | ||
finalString += serialize.serializeStyles([ | ||
((_ref = {}), (_ref[key] = value), _ref) | ||
]).styles; | ||
finalString += serialize.serializeStyles([ (_ref = {}, _ref[key] = value, _ref) ]).styles; | ||
} | ||
@@ -301,384 +190,209 @@ } | ||
} | ||
var appendStringToExpressions = function(expressions, string, t) { | ||
return ( | ||
string && | ||
(t.isStringLiteral(expressions[expressions.length - 1]) | ||
? (expressions[expressions.length - 1].value += string) | ||
: expressions.push(t.stringLiteral(string))), | ||
expressions | ||
); | ||
}, | ||
joinStringLiterals = function(expressions, t) { | ||
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 | ||
); | ||
}, []); | ||
}; | ||
return string ? (t.isStringLiteral(expressions[expressions.length - 1]) ? expressions[expressions.length - 1].value += string : expressions.push(t.stringLiteral(string)), | ||
expressions) : expressions; | ||
}, joinStringLiterals = function(expressions, t) { | ||
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; | ||
}, []); | ||
}; | ||
function createSourceMapConditional(t, production, development) { | ||
return t.conditionalExpression( | ||
t.binaryExpression( | ||
"===", | ||
t.memberExpression( | ||
t.memberExpression(t.identifier("process"), t.identifier("env")), | ||
t.identifier("NODE_ENV") | ||
), | ||
t.stringLiteral("production") | ||
), | ||
production, | ||
development | ||
); | ||
return t.conditionalExpression(t.binaryExpression("===", t.memberExpression(t.memberExpression(t.identifier("process"), t.identifier("env")), t.identifier("NODE_ENV")), t.stringLiteral("production")), production, development); | ||
} | ||
var transformExpressionWithStyles = function(_ref) { | ||
var babel = _ref.babel, | ||
state = _ref.state, | ||
path = _ref.path, | ||
shouldLabel = _ref.shouldLabel, | ||
_ref$sourceMap = _ref.sourceMap, | ||
sourceMap$$1 = void 0 === _ref$sourceMap ? "" : _ref$sourceMap, | ||
t = babel.types; | ||
if (t.isTaggedTemplateExpression(path)) { | ||
var expressions = getExpressionsFromTemplateLiteral(path.node.quasi, t); | ||
state.emotionSourceMap && | ||
void 0 !== path.node.quasi.loc && | ||
(sourceMap$$1 = getSourceMap(path.node.quasi.loc.start, state)), | ||
path.replaceWith(t.callExpression(path.node.tag, expressions)); | ||
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; | ||
if (t.isTaggedTemplateExpression(path)) { | ||
var expressions = getExpressionsFromTemplateLiteral(path.node.quasi, t); | ||
state.emotionSourceMap && void 0 !== path.node.quasi.loc && (sourceMap = getSourceMap(path.node.quasi.loc.start, state)), | ||
path.replaceWith(t.callExpression(path.node.tag, expressions)); | ||
} | ||
if (t.isCallExpression(path)) { | ||
var canAppendStrings = path.node.arguments.every(function(arg) { | ||
return "SpreadElement" !== arg.type; | ||
}); | ||
if (canAppendStrings) { | ||
var label = getLabelFromPath(path, state, t); | ||
label && shouldLabel && appendStringToExpressions(path.node.arguments, "label:" + label + ";", t); | ||
} | ||
if (t.isCallExpression(path)) { | ||
var canAppendStrings = path.node.arguments.every(function(arg) { | ||
return "SpreadElement" !== arg.type; | ||
}); | ||
if (canAppendStrings) { | ||
var label = getLabelFromPath(path, state, t); | ||
label && | ||
shouldLabel && | ||
appendStringToExpressions( | ||
path.node.arguments, | ||
"label:" + label + ";", | ||
t | ||
); | ||
var isPure = !0; | ||
if (path.get("arguments").forEach(function(node) { | ||
node.isPure() || (isPure = !1), 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)), | ||
1 === path.node.arguments.length && t.isStringLiteral(path.node.arguments[0])) { | ||
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; | ||
if (sourceMap) { | ||
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)) ]); | ||
node = createSourceMapConditional(t, prodNode, devNode); | ||
} | ||
var isPure = !0; | ||
if ( | ||
(path.get("arguments").forEach(function(node) { | ||
node.isPure() || (isPure = !1), | ||
t.isObjectExpression(node) && | ||
node.replaceWith(simplifyObject(node.node, t)); | ||
}), | ||
(path.node.arguments = joinStringLiterals(path.node.arguments, t)), | ||
canAppendStrings && | ||
state.emotionSourceMap && | ||
!sourceMap$$1 && | ||
void 0 !== path.node.loc && | ||
(sourceMap$$1 = getSourceMap(path.node.loc.start, state)), | ||
1 === path.node.arguments.length && | ||
t.isStringLiteral(path.node.arguments[0])) | ||
) { | ||
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; | ||
if (sourceMap$$1) { | ||
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$$1)) | ||
]); | ||
node = createSourceMapConditional(t, prodNode, devNode); | ||
} | ||
return { node: node, isPure: !0 }; | ||
} | ||
if (sourceMap$$1) { | ||
var lastIndex = path.node.arguments.length - 1, | ||
last = path.node.arguments[lastIndex], | ||
sourceMapConditional = createSourceMapConditional( | ||
t, | ||
t.stringLiteral(""), | ||
t.stringLiteral(sourceMap$$1) | ||
); | ||
t.isStringLiteral(last) | ||
? (path.node.arguments[lastIndex] = t.binaryExpression( | ||
"+", | ||
last, | ||
sourceMapConditional | ||
)) | ||
: path.node.arguments.push(sourceMapConditional); | ||
} | ||
return { node: void 0, isPure: isPure }; | ||
return { | ||
node: node, | ||
isPure: !0 | ||
}; | ||
} | ||
return { node: void 0, isPure: !1 }; | ||
}, | ||
getStyledOptions = function(t, path, state) { | ||
var properties = [ | ||
t.objectProperty( | ||
t.identifier("target"), | ||
t.stringLiteral(getTargetClassName(state, t)) | ||
) | ||
], | ||
label = getLabelFromPath(path, state, t); | ||
label && | ||
properties.push( | ||
t.objectProperty(t.identifier("label"), t.stringLiteral(label)) | ||
); | ||
var args = path.node.arguments, | ||
optionsArgument = 2 <= args.length ? args[1] : null; | ||
if (optionsArgument) { | ||
if (!t.isObjectExpression(optionsArgument)) | ||
return t.callExpression(state.file.addHelper("extends"), [ | ||
t.objectExpression([]), | ||
t.objectExpression(properties), | ||
optionsArgument | ||
]); | ||
properties.unshift.apply(properties, optionsArgument.properties); | ||
if (sourceMap) { | ||
var lastIndex = path.node.arguments.length - 1, last = path.node.arguments[lastIndex], sourceMapConditional = createSourceMapConditional(t, t.stringLiteral(""), t.stringLiteral(sourceMap)); | ||
t.isStringLiteral(last) ? path.node.arguments[lastIndex] = t.binaryExpression("+", last, sourceMapConditional) : path.node.arguments.push(sourceMapConditional); | ||
} | ||
return t.objectExpression(properties); | ||
}, | ||
createEmotionMacro = function(instancePath) { | ||
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) { | ||
var isPure = !0, | ||
runtimeNode = helperModuleImports.addNamed( | ||
state.file.path, | ||
referenceKey, | ||
instancePath | ||
); | ||
switch (referenceKey) { | ||
case "injectGlobal": | ||
isPure = !1; | ||
case "css": | ||
case "keyframes": | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
var path = reference.parentPath; | ||
reference.replaceWith(t.cloneDeep(runtimeNode)), | ||
isPure && path.addComment("leading", "#__PURE__"); | ||
var node = transformExpressionWithStyles({ | ||
babel: babel, | ||
state: state, | ||
path: path, | ||
shouldLabel: !0 | ||
}).node; | ||
node && (path.node.arguments[0] = node); | ||
}); | ||
break; | ||
default: | ||
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) { | ||
var references = _ref2.references, | ||
state = _ref2.state, | ||
babel = _ref2.babel; | ||
_ref2.isEmotionCall || (state.emotionSourceMap = !0); | ||
var t = babel.types; | ||
if (references.default && references.default.length) { | ||
var _styledIdentifier, | ||
originalImportPathStyledIdentifier, | ||
getStyledIdentifier = function() { | ||
return ( | ||
void 0 === _styledIdentifier && | ||
(_styledIdentifier = helperModuleImports.addDefault( | ||
state.file.path, | ||
importPath, | ||
{ nameHint: "styled" } | ||
)), | ||
t.cloneDeep(_styledIdentifier) | ||
); | ||
}, | ||
getOriginalImportPathStyledIdentifier = function() { | ||
return ( | ||
void 0 === originalImportPathStyledIdentifier && | ||
(originalImportPathStyledIdentifier = helperModuleImports.addDefault( | ||
state.file.path, | ||
originalImportPath, | ||
{ nameHint: "styled" } | ||
)), | ||
t.cloneDeep(originalImportPathStyledIdentifier) | ||
); | ||
}; | ||
importPath === originalImportPath && | ||
(getOriginalImportPathStyledIdentifier = getStyledIdentifier), | ||
references.default.forEach(function(reference) { | ||
var isCall = !1; | ||
if ( | ||
(t.isMemberExpression(reference.parent) && | ||
!1 === reference.parent.computed | ||
? ((isCall = !0), | ||
96 < reference.parent.property.name.charCodeAt(0) | ||
? 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), | ||
reference.replaceWith(getStyledIdentifier())) | ||
: reference.replaceWith( | ||
getOriginalImportPathStyledIdentifier() | ||
), | ||
reference.parentPath && reference.parentPath.parentPath) | ||
) { | ||
var styledCallPath = reference.parentPath.parentPath, | ||
node = transformExpressionWithStyles({ | ||
path: styledCallPath, | ||
state: state, | ||
babel: babel, | ||
shouldLabel: !1 | ||
}).node; | ||
node && isWeb && (styledCallPath.node.arguments[0] = node); | ||
} | ||
isCall && | ||
(reference.addComment("leading", "#__PURE__"), | ||
isWeb && | ||
(reference.parentPath.node.arguments[1] = getStyledOptions( | ||
t, | ||
reference.parentPath, | ||
state | ||
))); | ||
}); | ||
return { | ||
node: void 0, | ||
isPure: isPure | ||
}; | ||
} | ||
return { | ||
node: void 0, | ||
isPure: !1 | ||
}; | ||
}, getStyledOptions = function(t, path, state) { | ||
var properties = [ t.objectProperty(t.identifier("target"), t.stringLiteral(getTargetClassName(state, t))) ], label = getLabelFromPath(path, state, t); | ||
label && properties.push(t.objectProperty(t.identifier("label"), t.stringLiteral(label))); | ||
var args = path.node.arguments, optionsArgument = args.length >= 2 ? args[1] : null; | ||
if (optionsArgument) { | ||
if (!t.isObjectExpression(optionsArgument)) return t.callExpression(state.file.addHelper("extends"), [ t.objectExpression([]), t.objectExpression(properties), optionsArgument ]); | ||
properties.unshift.apply(properties, optionsArgument.properties); | ||
} | ||
return t.objectExpression(properties); | ||
}, createEmotionMacro = function(instancePath) { | ||
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) { | ||
var isPure = !0, runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, instancePath); | ||
switch (referenceKey) { | ||
case "injectGlobal": | ||
isPure = !1; | ||
case "css": | ||
case "keyframes": | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
var path = reference.parentPath; | ||
reference.replaceWith(t.cloneDeep(runtimeNode)), isPure && path.addComment("leading", "#__PURE__"); | ||
var node = transformExpressionWithStyles({ | ||
babel: babel, | ||
state: state, | ||
path: path, | ||
shouldLabel: !0 | ||
}).node; | ||
node && (path.node.arguments[0] = node); | ||
}); | ||
break; | ||
default: | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
} | ||
Object.keys(references) | ||
.filter(function(x) { | ||
return "default" !== x; | ||
}) | ||
.forEach(function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed( | ||
state.file.path, | ||
referenceKey, | ||
importPath | ||
); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}); | ||
}, | ||
transformCssCallExpression = function(_ref) { | ||
var babel = _ref.babel, | ||
state = _ref.state, | ||
path = _ref.path, | ||
sourceMap$$1 = _ref.sourceMap, | ||
_transformExpressionW = transformExpressionWithStyles({ | ||
babel: babel, | ||
state: state, | ||
path: path, | ||
shouldLabel: !0, | ||
sourceMap: sourceMap$$1 | ||
}), | ||
node = _transformExpressionW.node, | ||
isPure = _transformExpressionW.isPure; | ||
node | ||
? (path.replaceWith(node), isPure && path.hoist()) | ||
: path.addComment("leading", "#__PURE__"); | ||
}, | ||
cssMacro = babelPluginMacros.createMacro(function(_ref2) { | ||
var references = _ref2.references, | ||
state = _ref2.state, | ||
babel = _ref2.babel; | ||
}); | ||
}, 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) { | ||
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) { | ||
state.cssIdentifier || | ||
(state.cssIdentifier = helperModuleImports.addDefault( | ||
reference, | ||
"@emotion/css", | ||
{ nameHint: "css" } | ||
)), | ||
reference.replaceWith(t.cloneDeep(state.cssIdentifier)), | ||
transformCssCallExpression({ | ||
babel: babel, | ||
if (references.default && references.default.length) { | ||
var _styledIdentifier, originalImportPathStyledIdentifier, getStyledIdentifier = function() { | ||
return void 0 === _styledIdentifier && (_styledIdentifier = helperModuleImports.addDefault(state.file.path, importPath, { | ||
nameHint: "styled" | ||
})), t.cloneDeep(_styledIdentifier); | ||
}, getOriginalImportPathStyledIdentifier = function() { | ||
return void 0 === originalImportPathStyledIdentifier && (originalImportPathStyledIdentifier = helperModuleImports.addDefault(state.file.path, originalImportPath, { | ||
nameHint: "styled" | ||
})), t.cloneDeep(originalImportPathStyledIdentifier); | ||
}; | ||
importPath === originalImportPath && (getOriginalImportPathStyledIdentifier = getStyledIdentifier), | ||
references.default.forEach(function(reference) { | ||
var isCall = !1; | ||
if (t.isMemberExpression(reference.parent) && !1 === reference.parent.computed ? (isCall = !0, | ||
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, | ||
reference.replaceWith(getStyledIdentifier())) : reference.replaceWith(getOriginalImportPathStyledIdentifier()), | ||
reference.parentPath && reference.parentPath.parentPath) { | ||
var styledCallPath = reference.parentPath.parentPath, node = transformExpressionWithStyles({ | ||
path: styledCallPath, | ||
state: state, | ||
path: reference.parentPath | ||
}); | ||
}), | ||
Object.keys(references) | ||
.filter(function(x) { | ||
return "default" !== x; | ||
}) | ||
.forEach(function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed( | ||
state.file.path, | ||
referenceKey, | ||
"@emotion/css", | ||
{ nameHint: referenceKey } | ||
); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}), | ||
webStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/styled-base", | ||
originalImportPath: "@emotion/styled", | ||
isWeb: !0 | ||
}), | ||
nativeStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/native", | ||
originalImportPath: "@emotion/native", | ||
isWeb: !1 | ||
}), | ||
primitivesStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/primitives", | ||
originalImportPath: "@emotion/primitives", | ||
isWeb: !1 | ||
}), | ||
macros = { | ||
createEmotionMacro: createEmotionMacro, | ||
css: cssMacro, | ||
createStyledMacro: createStyledMacro | ||
}, | ||
emotionCoreMacroThatsNotARealMacro = function(_ref) { | ||
var references = _ref.references, | ||
state = _ref.state, | ||
babel = _ref.babel; | ||
Object.keys(references).forEach(function(refKey) { | ||
"css" === refKey && | ||
references[refKey].forEach(function(path) { | ||
transformCssCallExpression({ | ||
babel: babel, | ||
state: state, | ||
path: path.parentPath | ||
}); | ||
}); | ||
shouldLabel: !1 | ||
}).node; | ||
node && isWeb && (styledCallPath.node.arguments[0] = node); | ||
} | ||
isCall && (reference.addComment("leading", "#__PURE__"), isWeb && (reference.parentPath.node.arguments[1] = getStyledOptions(t, reference.parentPath, state))); | ||
}); | ||
} | ||
Object.keys(references).filter(function(x) { | ||
return "default" !== x; | ||
}).forEach(function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, importPath); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}; | ||
}); | ||
}, transformCssCallExpression = function(_ref) { | ||
var babel = _ref.babel, state = _ref.state, path = _ref.path, sourceMap = _ref.sourceMap, _transformExpressionW = transformExpressionWithStyles({ | ||
babel: babel, | ||
state: state, | ||
path: path, | ||
shouldLabel: !0, | ||
sourceMap: sourceMap | ||
}), node = _transformExpressionW.node, isPure = _transformExpressionW.isPure; | ||
node ? (path.replaceWith(node), isPure && path.hoist()) : path.addComment("leading", "#__PURE__"); | ||
}, 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) { | ||
state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(reference, "@emotion/css", { | ||
nameHint: "css" | ||
})), reference.replaceWith(t.cloneDeep(state.cssIdentifier)), transformCssCallExpression({ | ||
babel: babel, | ||
state: state, | ||
path: reference.parentPath | ||
}); | ||
}), Object.keys(references).filter(function(x) { | ||
return "default" !== x; | ||
}).forEach(function(referenceKey) { | ||
var runtimeNode = helperModuleImports.addNamed(state.file.path, referenceKey, "@emotion/css", { | ||
nameHint: referenceKey | ||
}); | ||
references[referenceKey].reverse().forEach(function(reference) { | ||
reference.replaceWith(t.cloneDeep(runtimeNode)); | ||
}); | ||
}); | ||
}), webStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/styled-base", | ||
originalImportPath: "@emotion/styled", | ||
isWeb: !0 | ||
}), nativeStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/native", | ||
originalImportPath: "@emotion/native", | ||
isWeb: !1 | ||
}), primitivesStyledMacro = createStyledMacro({ | ||
importPath: "@emotion/primitives", | ||
originalImportPath: "@emotion/primitives", | ||
isWeb: !1 | ||
}), macros = { | ||
createEmotionMacro: createEmotionMacro, | ||
css: cssMacro, | ||
createStyledMacro: createStyledMacro | ||
}, emotionCoreMacroThatsNotARealMacro = function(_ref) { | ||
var references = _ref.references, state = _ref.state, babel = _ref.babel; | ||
Object.keys(references).forEach(function(refKey) { | ||
"css" === refKey && references[refKey].forEach(function(path) { | ||
transformCssCallExpression({ | ||
babel: babel, | ||
state: state, | ||
path: path.parentPath | ||
}); | ||
}); | ||
}); | ||
}; | ||
function getAbsolutePath(instancePath, rootPath) { | ||
return ( | ||
"." === instancePath.charAt(0) && nodePath.resolve(rootPath, instancePath) | ||
); | ||
return "." === instancePath.charAt(0) && nodePath.resolve(rootPath, instancePath); | ||
} | ||
function getInstancePathToCompare(instancePath, rootPath) { | ||
@@ -688,2 +402,3 @@ var absolutePath = getAbsolutePath(instancePath, rootPath); | ||
} | ||
function index(babel) { | ||
@@ -696,86 +411,40 @@ var t = babel.types; | ||
ImportDeclaration: function(path, state) { | ||
var dirname = | ||
path.hub.file.opts.filename && | ||
"unknown" !== path.hub.file.opts.filename | ||
? nodePath.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 dirname = path.hub.file.opts.filename && "unknown" !== path.hub.file.opts.filename ? nodePath.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]) | ||
) { | ||
if (void 0 !== pluginMacros[path.node.source.value] && !t.isImportNamespaceSpecifier(path.node.specifiers[0])) { | ||
var imports = path.node.specifiers.map(function(s) { | ||
return { | ||
localName: s.local.name, | ||
importedName: | ||
"ImportDefaultSpecifier" === s.type | ||
? "default" | ||
: s.imported.name | ||
}; | ||
}), | ||
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))) | ||
: (shouldExit = !0), | ||
byName | ||
); | ||
}, | ||
{}); | ||
hasReferences && | ||
!shouldExit && | ||
(state.file.scope.path.traverse({ Identifier: function() {} }), | ||
pluginMacros[path.node.source.value]({ | ||
references: referencePathsByImportName, | ||
state: state, | ||
babel: babel, | ||
isBabelMacrosCall: !0, | ||
isEmotionCall: !0 | ||
}), | ||
pluginMacros[path.node.source.value].keepImport || path.remove()); | ||
return { | ||
localName: s.local.name, | ||
importedName: "ImportDefaultSpecifier" === s.type ? "default" : s.imported.name | ||
}; | ||
}), 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({ | ||
Identifier: function() {} | ||
}), pluginMacros[path.node.source.value]({ | ||
references: referencePathsByImportName, | ||
state: state, | ||
babel: babel, | ||
isBabelMacrosCall: !0, | ||
isEmotionCall: !0 | ||
}), pluginMacros[path.node.source.value].keepImport || path.remove()); | ||
} | ||
}, | ||
Program: function(path, state) { | ||
if ( | ||
((state.emotionInstancePaths = (state.opts.instances || []).map( | ||
function(instancePath) { | ||
return getInstancePathToCompare(instancePath, process.cwd()); | ||
} | ||
)), | ||
(state.pluginMacros = { | ||
"@emotion/css": cssMacro, | ||
"@emotion/styled": webStyledMacro, | ||
"@emotion/core": emotionCoreMacroThatsNotARealMacro, | ||
"@emotion/primitives": primitivesStyledMacro, | ||
"@emotion/native": nativeStyledMacro, | ||
emotion: createEmotionMacro("emotion") | ||
}), | ||
void 0 === state.opts.cssPropOptimization) | ||
) { | ||
var _iterator = path.node.body, | ||
_isArray = Array.isArray(_iterator), | ||
_i = 0; | ||
for ( | ||
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator](); | ||
; | ||
) { | ||
if (state.emotionInstancePaths = (state.opts.instances || []).map(function(instancePath) { | ||
return getInstancePathToCompare(instancePath, process.cwd()); | ||
}), state.pluginMacros = { | ||
"@emotion/css": cssMacro, | ||
"@emotion/styled": webStyledMacro, | ||
"@emotion/core": emotionCoreMacroThatsNotARealMacro, | ||
"@emotion/primitives": primitivesStyledMacro, | ||
"@emotion/native": nativeStyledMacro, | ||
emotion: createEmotionMacro("emotion") | ||
}, void 0 === state.opts.cssPropOptimization) { | ||
var _iterator = path.node.body, _isArray = Array.isArray(_iterator), _i = 0; | ||
for (_iterator = _isArray ? _iterator : _iterator[Symbol.iterator](); ;) { | ||
var _ref3; | ||
@@ -790,9 +459,5 @@ if (_isArray) { | ||
var node = _ref3; | ||
if ( | ||
t.isImportDeclaration(node) && | ||
"@emotion/core" === node.source.value && | ||
node.specifiers.some(function(x) { | ||
return t.isImportSpecifier(x) && "jsx" === x.imported.name; | ||
}) | ||
) { | ||
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; | ||
@@ -803,40 +468,16 @@ break; | ||
} else state.transformCssProp = state.opts.cssPropOptimization; | ||
!1 === state.opts.sourceMap | ||
? (state.emotionSourceMap = !1) | ||
: (state.emotionSourceMap = !0); | ||
!1 === state.opts.sourceMap ? state.emotionSourceMap = !1 : state.emotionSourceMap = !0; | ||
}, | ||
JSXAttribute: function(path, state) { | ||
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)) | ||
) { | ||
var expressionPath = path.get("value.expression"), | ||
sourceMap$$1 = | ||
state.emotionSourceMap && void 0 !== path.node.loc | ||
? getSourceMap(path.node.loc.start, state) | ||
: ""; | ||
expressionPath.replaceWith( | ||
t.callExpression(t.identifier("___shouldNeverAppearCSS"), [ | ||
path.node.value.expression | ||
]) | ||
), | ||
transformCssCallExpression({ | ||
babel: babel, | ||
state: state, | ||
path: expressionPath, | ||
sourceMap: sourceMap$$1 | ||
}), | ||
t.isCallExpression(expressionPath) && | ||
(state.cssIdentifier || | ||
(state.cssIdentifier = helperModuleImports.addDefault( | ||
path, | ||
"@emotion/css", | ||
{ nameHint: "css" } | ||
)), | ||
expressionPath | ||
.get("callee") | ||
.replaceWith(t.cloneDeep(state.cssIdentifier))); | ||
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))) { | ||
var expressionPath = path.get("value.expression"), sourceMap = state.emotionSourceMap && void 0 !== path.node.loc ? getSourceMap(path.node.loc.start, state) : ""; | ||
expressionPath.replaceWith(t.callExpression(t.identifier("___shouldNeverAppearCSS"), [ path.node.value.expression ])), | ||
transformCssCallExpression({ | ||
babel: babel, | ||
state: state, | ||
path: expressionPath, | ||
sourceMap: sourceMap | ||
}), t.isCallExpression(expressionPath) && (state.cssIdentifier || (state.cssIdentifier = helperModuleImports.addDefault(path, "@emotion/css", { | ||
nameHint: "css" | ||
})), expressionPath.get("callee").replaceWith(t.cloneDeep(state.cssIdentifier))); | ||
} | ||
@@ -847,12 +488,7 @@ }, | ||
try { | ||
if ( | ||
path.node.callee && | ||
path.node.callee.property && | ||
"withComponent" === path.node.callee.property.name | ||
) | ||
switch (path.node.arguments.length) { | ||
case 1: | ||
case 2: | ||
path.node.arguments[1] = getStyledOptions(t, path, state); | ||
} | ||
if (path.node.callee && path.node.callee.property && "withComponent" === path.node.callee.property.name) switch (path.node.arguments.length) { | ||
case 1: | ||
case 2: | ||
path.node.arguments[1] = getStyledOptions(t, path, state); | ||
} | ||
} catch (e) { | ||
@@ -866,4 +502,3 @@ throw path.buildCodeFrameError(e); | ||
} | ||
(emotionCoreMacroThatsNotARealMacro.keepImport = !0), | ||
(exports.macros = macros), | ||
(exports.default = index); | ||
emotionCoreMacroThatsNotARealMacro.keepImport = !0, exports.default = index, exports.macros = macros; |
{ | ||
"name": "babel-plugin-emotion", | ||
"version": "10.0.9", | ||
"version": "10.0.13", | ||
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.", | ||
@@ -41,2 +41,2 @@ "main": "dist/babel-plugin-emotion.cjs.js", | ||
} | ||
} | ||
} |
@@ -47,3 +47,4 @@ // @flow | ||
p.isFunctionExpression() || | ||
p.isArrowFunctionExpression() | ||
p.isArrowFunctionExpression() || | ||
p.isObjectProperty() | ||
) | ||
@@ -54,5 +55,5 @@ if (!parent) { | ||
// we probably have a css call assigned to a variable | ||
// so we'll just return the variable name | ||
if (parent.isVariableDeclarator()) { | ||
// we probably have a css call assigned to a variable | ||
// so we'll just return the variable name | ||
return parent.node.id.name | ||
@@ -70,2 +71,7 @@ } | ||
// we could also have an object property | ||
if (parent.isObjectProperty()) { | ||
return parent.node.key.name | ||
} | ||
let variableDeclarator = path.findParent(p => p.isVariableDeclarator()) | ||
@@ -72,0 +78,0 @@ if (!variableDeclarator) { |
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
21
98300
2288