-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Remove completely from @wordpress/docgen
package
#43100
Conversation
Size Change: 0 B Total Size: 1.27 MB ℹ️ View Unchanged
|
9cd9025
to
c5c9cca
Compare
@@ -31,7 +26,7 @@ module.exports = ( token ) => { | |||
name = t.declaration.left.name; | |||
break; | |||
default: | |||
name = get( t.declaration, [ 'id', 'name' ], '*default*' ); | |||
name = t.declaration.id?.name ?? '*default*'; |
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.
Adding a note that ?.
+ ??
aren't strictly equivalent to get()
, in that the former check for a value being nullish (null
or undefined
), whereas the latter checks for it being undefined
only.
That said, this looks to still do the right thing in this case, as we wouldn't expect for null
to be a correct value.
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.
I confirm this is the intention. IIUC we can expect undefined
but not null
there.
description: doc?.description ?? UNDOCUMENTED, | ||
tags: doc?.tags ?? [], |
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.
Is null
a valid value that we want to preserve in either of these cases, or do we always want to replace it with the default value? The lack of types makes this a bit tricky to review without more context 😕
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.
I don't see how those could be null
TBH, so I'm not concerned about this.
@@ -14,7 +9,10 @@ const { last } = require( 'lodash' ); | |||
module.exports = ( declaration ) => { | |||
let comments; | |||
if ( declaration.leadingComments ) { | |||
const lastComment = last( declaration.leadingComments ); | |||
const lastComment = | |||
declaration.leadingComments[ |
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.
If declaration.leadingComments
is a plain array, then declaration.leadingComments.at(-1)
would also work, assuming that the transpilation infrastructure supports it. But it may be safer to leave it as-is, and it's perfectly readable this way as well.
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.
I previously tried it, and it broke 😉 Seems like it's not supported.
Thank you for working on this, @tyxla! 🙌 |
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.
Perfect, LGTM! Thanks again, @tyxla! 👍
Thanks for taking a look @sgomes 🙌 |
What?
This PR removes all of the Lodash from the
@wordpress/docgen
package, including thelodash
dependency altogether. There are just a few usages and conversion is pretty straightforward.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're dealing with straightforwardly replacing a few methods, namely:
get
We're using optional chaining and nullish coalescing.
last
Straightforward to replace with
x[ x.length - 1 ]
on the target array.Testing Instructions
npx docgen packages/block-library/src/index.js
ornpx docgen packages/block-editor/src/index.js
npm run test:unit packages/docgen