-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some tricks for shave bytes (-11B for esm) #421
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,21 +40,28 @@ export let hash = (compiled, sheet, global, append, keyframes) => { | |
let className = | ||
cache[stringifiedCompiled] || (cache[stringifiedCompiled] = toHash(stringifiedCompiled)); | ||
|
||
// If there's no entry for the current className | ||
if (!cache[className]) { | ||
// Build the _ast_-ish structure if needed | ||
let ast = stringifiedCompiled !== compiled ? compiled : astish(compiled); | ||
|
||
// Parse it | ||
cache[className] = parse( | ||
// For keyframes | ||
keyframes ? { ['@keyframes ' + className]: ast } : ast, | ||
global ? '' : '.' + className | ||
); | ||
} | ||
|
||
// add or update | ||
update(cache[className], sheet, append); | ||
update( | ||
(cache[className] = | ||
cache[className] || | ||
// If there's no entry for the current className | ||
// Parse it | ||
parse( | ||
// For keyframes | ||
keyframes | ||
? // Build the _ast_-ish structure if needed | ||
{ | ||
['@keyframes ' + className]: | ||
stringifiedCompiled !== compiled ? compiled : astish(compiled) | ||
} | ||
: stringifiedCompiled !== compiled | ||
? compiled | ||
: astish(compiled), | ||
global ? '' : '.' + className | ||
)), | ||
sheet, | ||
append | ||
); | ||
Comment on lines
+44
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is where the shaves are huge. The large downside though is the readability and maintenance effort if we keep it in this form. I would rather see this as a last resort. |
||
|
||
// return hash | ||
return className; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ export let extractCss = (target) => { | |
* @param {Boolean} append | ||
*/ | ||
export let update = (css, sheet, append) => { | ||
sheet.data.indexOf(css) == -1 && (sheet.data = append ? css + sheet.data : sheet.data + css); | ||
~sheet.data.indexOf(css) || (sheet.data = append ? css + sheet.data : sheet.data + css); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙌 this one shaves around 4B |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,15 +48,11 @@ function styled(tag, forwardRef) { | |
} | ||
|
||
// Assign the _as with the provided `tag` value | ||
let _as = tag; | ||
|
||
// If this is a string -- checking that is has a first valid char | ||
if (tag[0]) { | ||
// Try to assign the _as with the given _as value if any | ||
_as = _props.as || tag; | ||
// And remove it | ||
delete _props.as; | ||
} | ||
// Try to assign the _as with the given _as value if any | ||
let _as = (tag[0] && _props.as) || tag; | ||
// And remove it | ||
tag[0] && delete _props.as; | ||
Comment on lines
-51
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried this one locally and increases the overall size 😵💫 |
||
|
||
// Handle the forward props filter if defined and _as is a string | ||
if (fwdProp && _as[0]) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason this also increases the size.