pretty-lights
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -6,5 +6,3 @@ "use strict"; | ||
}); | ||
exports.getName = getName; | ||
exports.getLabel = getLabel; | ||
exports.createRawStringFromTemplateLiteral = createRawStringFromTemplateLiteral; | ||
exports.omit = omit; | ||
@@ -26,4 +24,2 @@ Object.defineProperty(exports, "getIdentifierName", { | ||
var _index = require("./index"); | ||
var _babelUtils = require("@emotion/babel-utils"); | ||
@@ -36,17 +32,2 @@ | ||
// import type { Types, Identifier } from 'babel-flow-types' | ||
function cloneNode(t, node) { | ||
return (typeof t.cloneNode === 'function' ? t.cloneNode : t.cloneDeep)(node); | ||
} | ||
function getName(identifierName, prefix) { | ||
const parts = []; | ||
parts.push(prefix); | ||
if (identifierName) { | ||
parts.push(identifierName); | ||
} | ||
return parts.join('-'); | ||
} | ||
function getLabel(identifierName, autoLabel, labelFormat, filename) { | ||
@@ -65,27 +46,11 @@ if (!identifierName || !autoLabel) return null; // Valid Characters in CSS Class Names Selecter | ||
function createRawStringFromTemplateLiteral(quasi) { | ||
let strs = quasi.quasis.map(x => x.value.cooked); | ||
let hash = (0, _index.hashArray)([...strs]); | ||
const src = strs.reduce((arr, str, i) => { | ||
arr.push(str); | ||
function omit(obj, testFn) { | ||
const target = {}; | ||
let i; // eslint-disable-next-line no-restricted-syntax | ||
if (i !== strs.length - 1) { | ||
arr.push(`xxx${i}xxx`); | ||
} | ||
for (i in obj) { | ||
if (!testFn(i, obj)) continue; // eslint-disable-line no-continue | ||
return arr; | ||
}, []).join('').trim(); | ||
return { | ||
src, | ||
hash | ||
}; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; // eslint-disable-line no-continue | ||
function omit(obj, testFn) { | ||
let target = {}; | ||
let i; | ||
for (i in obj) { | ||
if (!testFn(i, obj)) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
@@ -92,0 +57,0 @@ } |
@@ -6,3 +6,2 @@ "use strict"; | ||
}); | ||
exports.hashArray = hashArray; | ||
exports.hoistPureArgs = hoistPureArgs; | ||
@@ -14,4 +13,2 @@ exports.replaceCssWithCallExpression = replaceCssWithCallExpression; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _path = _interopRequireDefault(require("path")); | ||
@@ -21,10 +18,4 @@ | ||
var _mkdirp = _interopRequireDefault(require("mkdirp")); | ||
var _touch = require("touch"); | ||
var _hash = _interopRequireDefault(require("@emotion/hash")); | ||
var _stylis = _interopRequireDefault(require("@emotion/stylis")); | ||
var _memoize = _interopRequireDefault(require("@emotion/memoize")); | ||
@@ -46,6 +37,2 @@ | ||
const staticStylis = new _stylis.default({ | ||
keyframe: false | ||
}); | ||
function hoistPureArgs(path) { | ||
@@ -80,8 +67,3 @@ const args = path.get('arguments'); | ||
try { | ||
let { | ||
hash, | ||
src | ||
} = (0, _babelUtils2.createRawStringFromTemplateLiteral)(path.node.quasi); | ||
const identifierName = (0, _babelUtils2.getIdentifierName)(path, t); | ||
const name = (0, _babelUtils2.getName)(identifierName, 'css'); | ||
@@ -128,3 +110,5 @@ if (!removePath) { | ||
const filename = state.file.opts.filename; // normalize the file path to ignore folder structure | ||
const { | ||
filename | ||
} = state.file.opts; // normalize the file path to ignore folder structure | ||
// outside the current node project and arch-specific delimiters | ||
@@ -137,7 +121,9 @@ | ||
rootPath = getPackageRootPath(filename); | ||
moduleName = unsafeRequire(rootPath + '/package.json').name; | ||
} catch (err) {} | ||
moduleName = unsafeRequire(`${rootPath}/package.json`).name; | ||
} catch (err) {// shhh | ||
} | ||
const finalPath = filename === rootPath ? '' : filename.slice(rootPath.length); | ||
const positionInFile = state.count++; | ||
const positionInFile = state.count; | ||
state.count += 1; | ||
const stuffToHash = [moduleName]; | ||
@@ -189,3 +175,3 @@ | ||
const finalOptions = buildFinalOptions(t, options, labelProperty, targetProperty); | ||
let styledCall = t.isStringLiteral(tag) && !isCallExpression && tag.value[0] !== tag.value[0].toLowerCase() ? t.memberExpression(identifier, t.identifier(tag.value)) : t.callExpression(identifier, [tag, finalOptions, ...restArgs]); | ||
const styledCall = t.isStringLiteral(tag) && !isCallExpression && tag.value[0] !== tag.value[0].toLowerCase() ? t.memberExpression(identifier, t.identifier(tag.value)) : t.callExpression(identifier, [tag, finalOptions, ...restArgs]); | ||
return t.callExpression(styledCall, (0, _babelUtils2.appendStringToExpressions)((0, _babelUtils.getExpressionsFromTemplateLiteral)(path.node.quasi, t), stringToAppend, t)); | ||
@@ -198,3 +184,3 @@ } | ||
const tag = t.isCallExpression(path.node.callee) ? path.node.callee.arguments[0] : t.stringLiteral(path.node.callee.property.name); | ||
let isCallExpression = t.isCallExpression(path.node.callee); | ||
const isCallExpression = t.isCallExpression(path.node.callee); | ||
let styledOptions = null; | ||
@@ -207,3 +193,3 @@ let restStyledArgs = []; | ||
if (styledArgs.length >= 2) { | ||
styledOptions = styledArgs[1]; | ||
[, styledOptions] = styledArgs; | ||
} | ||
@@ -214,3 +200,3 @@ | ||
let args = path.node.arguments; | ||
const args = path.node.arguments; | ||
@@ -224,3 +210,3 @@ if (state.opts.sourceMap === true && path.node.loc !== undefined) { | ||
path.addComment('leading', '#__PURE__'); | ||
let styledCall = t.isStringLiteral(tag) && !isCallExpression && tag.value[0] !== tag.value[0].toLowerCase() ? t.memberExpression(identifier, t.identifier(tag.value)) : t.callExpression(identifier, [tag, buildFinalOptions(t, styledOptions, targetProperty, labelProperty), ...restStyledArgs]); | ||
const styledCall = t.isStringLiteral(tag) && !isCallExpression && tag.value[0] !== tag.value[0].toLowerCase() ? t.memberExpression(identifier, t.identifier(tag.value)) : t.callExpression(identifier, [tag, buildFinalOptions(t, styledOptions, targetProperty, labelProperty), ...restStyledArgs]); | ||
return t.callExpression(styledCall, args); | ||
@@ -241,3 +227,3 @@ } | ||
function getRelativePath(filepath, absoluteInstancePath) { | ||
let relativePath = _path.default.relative(_path.default.dirname(filepath), absoluteInstancePath); | ||
const relativePath = _path.default.relative(_path.default.dirname(filepath), absoluteInstancePath); | ||
@@ -249,3 +235,3 @@ return relativePath.charAt(0) === '.' ? relativePath : `./${relativePath}`; | ||
if (instancePath.charAt(0) === '.') { | ||
let absoluteInstancePath = _path.default.resolve(rootPath, instancePath); | ||
const absoluteInstancePath = _path.default.resolve(rootPath, instancePath); | ||
@@ -259,3 +245,3 @@ return absoluteInstancePath; | ||
function getInstancePathToImport(instancePath, filepath) { | ||
let absolutePath = getAbsolutePath(instancePath, process.cwd()); | ||
const absolutePath = getAbsolutePath(instancePath, process.cwd()); | ||
@@ -270,3 +256,3 @@ if (absolutePath === false) { | ||
function getInstancePathToCompare(instancePath, rootPath) { | ||
let absolutePath = getAbsolutePath(instancePath, rootPath); | ||
const absolutePath = getAbsolutePath(instancePath, rootPath); | ||
@@ -287,2 +273,3 @@ if (absolutePath === false) { | ||
// not required | ||
// eslint-disable-next-line | ||
inherits: require('@babel/plugin-syntax-jsx').default, | ||
@@ -303,3 +290,3 @@ visitor: { | ||
const imports = []; | ||
let isModule = false; | ||
let isModule = false; // eslint-disable-next-line no-restricted-syntax | ||
@@ -316,6 +303,6 @@ for (const node of path.node.body) { | ||
ImportDeclaration: { | ||
exit(path) { | ||
exit(p) { | ||
const { | ||
node | ||
} = path; | ||
} = p; | ||
const imported = []; | ||
@@ -327,5 +314,5 @@ const specifiers = []; | ||
specifiers | ||
}); | ||
}); // eslint-disable-next-line no-restricted-syntax | ||
for (const specifier of path.get('specifiers')) { | ||
for (const specifier of p.get('specifiers')) { | ||
const local = specifier.node.local.name; | ||
@@ -359,6 +346,5 @@ | ||
const emotionPaths = defaultEmotionPaths.concat((state.opts.instances || []).map(instancePath => getInstancePathToCompare(instancePath, process.cwd()))); | ||
let dirname = hasFilepath ? _path.default.dirname(path.hub.file.opts.filename) : ''; | ||
const dirname = hasFilepath ? _path.default.dirname(path.hub.file.opts.filename) : ''; | ||
imports.forEach(({ | ||
source, | ||
imported, | ||
specifiers | ||
@@ -422,2 +408,6 @@ }) => { | ||
break; | ||
default: | ||
break; | ||
} | ||
@@ -424,0 +414,0 @@ } |
@@ -29,3 +29,4 @@ "use strict"; | ||
if (node.children) { | ||
for (let child of node.children) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const child of node.children) { | ||
getNodes(child, nodes); | ||
@@ -56,15 +57,2 @@ } | ||
} = {}) { | ||
function print(val, printer) { | ||
const nodes = getNodes(val); | ||
markNodes(nodes); | ||
const classNames = (0, _utils.getClassNamesFromNodes)(nodes); | ||
const styles = getStylesFromClassNames(classNames); | ||
const printedVal = printer(val); | ||
return (0, _replaceClassNames.replaceClassNames)(classNames, styles, printedVal, emotion.caches.key, classNameReplacer); | ||
} | ||
function test(val) { | ||
return val && !val.withEmotionStyles && (DOMElements ? (0, _utils.isReactElement)(val) || (0, _utils.isDOMElement)(val) : (0, _utils.isReactElement)(val)); | ||
} | ||
function markNodes(nodes) { | ||
@@ -82,6 +70,6 @@ nodes.forEach(node => { | ||
Object.keys(emotion.caches.registered).forEach(className => { | ||
let indexOfClassName = classNames.indexOf(className); | ||
const indexOfClassName = classNames.indexOf(className); | ||
if (indexOfClassName !== -1) { | ||
let nameWithoutKey = classNames[indexOfClassName].substring(emotion.caches.key.length + 1); | ||
const nameWithoutKey = classNames[indexOfClassName].substring(emotion.caches.key.length + 1); | ||
styles += emotion.caches.inserted[nameWithoutKey]; | ||
@@ -102,2 +90,15 @@ } | ||
function print(val, printer) { | ||
const nodes = getNodes(val); | ||
markNodes(nodes); | ||
const classNames = (0, _utils.getClassNamesFromNodes)(nodes); | ||
const styles = getStylesFromClassNames(classNames); | ||
const printedVal = printer(val); | ||
return (0, _replaceClassNames.replaceClassNames)(classNames, styles, printedVal, emotion.caches.key, classNameReplacer); | ||
} | ||
function test(val) { | ||
return val && !val.withEmotionStyles && (DOMElements ? (0, _utils.isReactElement)(val) || (0, _utils.isDOMElement)(val) : (0, _utils.isReactElement)(val)); | ||
} | ||
return { | ||
@@ -104,0 +105,0 @@ test, |
@@ -51,6 +51,6 @@ "use strict"; | ||
return Object.keys(emotion.caches.registered).reduce((styles, className) => { | ||
let indexOfClassName = classNames.indexOf(className); | ||
const indexOfClassName = classNames.indexOf(className); | ||
if (indexOfClassName !== -1) { | ||
let nameWithoutKey = classNames[indexOfClassName].substring(emotion.caches.key.length + 1); | ||
const nameWithoutKey = classNames[indexOfClassName].substring(emotion.caches.key.length + 1); | ||
styles += emotion.caches.inserted[nameWithoutKey]; | ||
@@ -61,4 +61,5 @@ } | ||
}, ''); | ||
} | ||
} // eslint-disable-next-line import/prefer-default-export | ||
function createMatchers(emotion) { | ||
@@ -65,0 +66,0 @@ function toHaveStyleRule(received, property, value) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
const componentSelectorClassNamePattern = /^e[a-zA-Z0-9]+[0-9]+$/; | ||
const componentSelectorClassNamePattern = /^e[a-zA-Z0-9]+[0-9]+$/; // eslint-disable-next-line import/prefer-default-export | ||
@@ -20,3 +20,5 @@ const replaceClassNames = (classNames, styles, code, key, replacer = defaultClassNameReplacer) => { | ||
const escapedRegex = new RegExp(className.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'g'); | ||
return acc.replace(escapedRegex, replacer(className, index++)); | ||
const returnVal = acc.replace(escapedRegex, replacer(className, index)); | ||
index += 1; | ||
return returnVal; | ||
} | ||
@@ -23,0 +25,0 @@ |
@@ -5,6 +5,6 @@ "use strict"; | ||
createSerializer | ||
} = require('./'); | ||
} = require('./'); // eslint-disable-next-line | ||
const emotion = require('../src'); | ||
const emotion = process.env.NODE_ENV === 'test' ? require('../src') : require('../lib'); | ||
module.exports = createSerializer(emotion); |
@@ -68,5 +68,9 @@ "use strict"; | ||
return getClassNamesFromTestRenderer(selectors, node); | ||
} else if (isEnzymeElement(node)) { | ||
} | ||
if (isEnzymeElement(node)) { | ||
return getClassNamesFromEnzyme(selectors, node); | ||
} else if (isCheerioElement(node)) { | ||
} | ||
if (isCheerioElement(node)) { | ||
return getClassNamesFromCheerio(selectors, node); | ||
@@ -73,0 +77,0 @@ } |
{ | ||
"name": "pretty-lights", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "CSS-in-JS with a reliable API", | ||
@@ -31,2 +31,3 @@ "main": "lib/pretty-lights.js", | ||
"dependencies": { | ||
"@emotion/babel-utils": "0.6.10", | ||
"@emotion/hash": "0.7.3", | ||
@@ -38,2 +39,3 @@ "@emotion/is-prop-valid": "0.8.3", | ||
"@emotion/weak-memoize": "0.2.4", | ||
"find-root": "1.1.0", | ||
"hoist-non-react-statics": "3.3.0", | ||
@@ -54,3 +56,2 @@ "stylis": "^3.5.4", | ||
"@babel/preset-react": "7.6.3", | ||
"@emotion/babel-utils": "0.6.10", | ||
"babel-check-duplicated-nodes": "1.0.0", | ||
@@ -77,3 +78,2 @@ "babel-eslint": "10.0.1", | ||
"eslint-plugin-react-hooks": "1.6.0", | ||
"find-root": "1.1.0", | ||
"jest": "24.9.0", | ||
@@ -80,0 +80,0 @@ "jest-in-case": "1.0.2", |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
41
182036
14
813
+ Added@emotion/babel-utils@0.6.10
+ Addedfind-root@1.1.0
+ Added@emotion/babel-utils@0.6.10(transitive)
+ Added@emotion/hash@0.6.6(transitive)
+ Added@emotion/memoize@0.6.6(transitive)
+ Added@emotion/serialize@0.9.1(transitive)
+ Added@emotion/unitless@0.6.7(transitive)
+ Added@emotion/utils@0.8.2(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedfind-root@1.1.0(transitive)
+ Addedsource-map@0.7.4(transitive)