From 23d1d843c190988f6e7b2e7013026f64f2edd074 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Wed, 10 Aug 2022 13:00:19 +0300 Subject: [PATCH] Lodash: Remove completely from docgen package (#43100) --- package-lock.json | 1 - packages/docgen/lib/get-export-entries.js | 9 ++------- packages/docgen/lib/get-intermediate-representation.js | 9 ++------- packages/docgen/lib/get-leading-comments.js | 10 ++++------ packages/docgen/lib/index.js | 6 ++++-- packages/docgen/package.json | 1 - 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e5f202c7601a..3ab747322efb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16935,7 +16935,6 @@ "requires": { "@babel/core": "^7.16.0", "comment-parser": "^1.1.1", - "lodash": "^4.17.21", "mdast-util-inject": "1.1.0", "optionator": "0.8.2", "remark": "10.0.1", diff --git a/packages/docgen/lib/get-export-entries.js b/packages/docgen/lib/get-export-entries.js index fb697264d3162..dc4046b72fcc7 100644 --- a/packages/docgen/lib/get-export-entries.js +++ b/packages/docgen/lib/get-export-entries.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -const { get } = require( 'lodash' ); - /** * Returns the export entry records of the given export statement. * Unlike [the standard](http://www.ecma-international.org/ecma-262/9.0/#exportentry-record), @@ -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*'; } return name; }; @@ -64,7 +59,7 @@ module.exports = ( token ) => { name.push( { localName: specifier.local.name, exportName: specifier.exported.name, - module: get( token.source, [ 'value' ], null ), + module: token.source?.value ?? null, lineStart: specifier.loc.start.line, lineEnd: specifier.loc.end.line, } ) diff --git a/packages/docgen/lib/get-intermediate-representation.js b/packages/docgen/lib/get-intermediate-representation.js index 253283d74a27f..2f8e155c57565 100644 --- a/packages/docgen/lib/get-intermediate-representation.js +++ b/packages/docgen/lib/get-intermediate-representation.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -const { get } = require( 'lodash' ); - /** * Internal dependencies */ @@ -154,8 +149,8 @@ module.exports = ( ir.push( { path, name: entry.exportName, - description: get( doc, [ 'description' ], UNDOCUMENTED ), - tags: get( doc, [ 'tags' ], [] ), + description: doc?.description ?? UNDOCUMENTED, + tags: doc?.tags ?? [], lineStart: entry.lineStart, lineEnd: entry.lineEnd, } ); diff --git a/packages/docgen/lib/get-leading-comments.js b/packages/docgen/lib/get-leading-comments.js index 09911a995c064..ddc0261f368e6 100644 --- a/packages/docgen/lib/get-leading-comments.js +++ b/packages/docgen/lib/get-leading-comments.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -const { last } = require( 'lodash' ); - /** * Function that returns the leading comment * of a Espree node. @@ -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[ + declaration.leadingComments.length - 1 + ]; if ( lastComment ) { comments = lastComment.value; } diff --git a/packages/docgen/lib/index.js b/packages/docgen/lib/index.js index f21864d2f7411..42416d9b45238 100644 --- a/packages/docgen/lib/index.js +++ b/packages/docgen/lib/index.js @@ -3,7 +3,6 @@ */ const fs = require( 'fs' ); const path = require( 'path' ); -const { last } = require( 'lodash' ); /** * Internal dependencies @@ -60,7 +59,10 @@ const processFile = ( rootDir, inputFile ) => { const result = engine( relativePath, data, - getIRFromRelativePath( rootDir, last( currentFileStack ) ) + getIRFromRelativePath( + rootDir, + currentFileStack[ currentFileStack.length - 1 ] + ) ); currentFileStack.pop(); return result; diff --git a/packages/docgen/package.json b/packages/docgen/package.json index 2d3caaa27eab8..73844baa723c1 100644 --- a/packages/docgen/package.json +++ b/packages/docgen/package.json @@ -29,7 +29,6 @@ "dependencies": { "@babel/core": "^7.16.0", "comment-parser": "^1.1.1", - "lodash": "^4.17.21", "mdast-util-inject": "1.1.0", "optionator": "0.8.2", "remark": "10.0.1",