Spaces:
Sleeping
Sleeping
pythonic-rag-FastAPIReact / frontend /node_modules /@emotion /babel-plugin /src /utils /object-to-string.js
Download frontend/node_modules/@emotion/babel-plugin/src/utils/object-to-string.js from sepidnes/pythonic-rag-FastAPIReact: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/sepidnes/pythonic-rag-FastAPIReact/resolve/94e32638a275d46bc1ba62feac204fcaaf313da4/frontend/node_modules/%40emotion/babel-plugin/src/utils/object-to-string.js
- Command line
-
hf download hf://spaces/sepidnes/pythonic-rag-FastAPIReact@94e32638a275d46bc1ba62feac204fcaaf313da4/frontend/node_modules/@emotion/babel-plugin/src/utils/object-to-string.js
-
curl -L -o object-to-string.js https://huggingface.co/spaces/sepidnes/pythonic-rag-FastAPIReact/resolve/94e32638a275d46bc1ba62feac204fcaaf313da4/frontend/node_modules/%40emotion/babel-plugin/src/utils/object-to-string.js
1.29 kB
| import { serializeStyles } from '@emotion/serialize' | |
| // to anyone looking at this, this isn't intended to simplify every single case | |
| // 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 | |
| export function simplifyObject(node, t /*: Object */) { | |
| let finalString = '' | |
| for (let i = 0; i < node.properties.length; i++) { | |
| let 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 | |
| } | |
| let key = property.key.name || property.key.value | |
| if (key === 'styles') { | |
| return node | |
| } | |
| if (t.isObjectExpression(property.value)) { | |
| let simplifiedChild = simplifyObject(property.value, t) | |
| if (!t.isStringLiteral(simplifiedChild)) { | |
| return node | |
| } | |
| finalString += `${key}{${simplifiedChild.value}}` | |
| continue | |
| } | |
| let value = property.value.value | |
| finalString += serializeStyles([{ [key]: value }]).styles | |
| } | |
| return t.stringLiteral(finalString) | |
| } | |