From e1440e9032107ff122ec950f95823ff21408fbbb Mon Sep 17 00:00:00 2001 From: Jithya Nanayakkara1 Date: Sun, 21 Jul 2024 09:52:46 +0530 Subject: [PATCH] chore: refactor util from js to ts --- packages/rspack/src/util/cleverMerge.ts | 4 ---- packages/rspack/src/util/createHash.ts | 30 ++++++++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/rspack/src/util/cleverMerge.ts b/packages/rspack/src/util/cleverMerge.ts index b47a494f4854..fd414e7cd360 100644 --- a/packages/rspack/src/util/cleverMerge.ts +++ b/packages/rspack/src/util/cleverMerge.ts @@ -170,15 +170,11 @@ const parseObject = (obj: Obj): ParsedObject => { const entry = getInfo(key); if (entry.byProperty === undefined) { entry.byProperty = byProperty; - entry.byValues = new Map(); } else if (entry.byProperty !== byProperty) { throw new Error( `${byProperty} and ${entry.byProperty} for a single property is not supported` ); } - if (entry.byValues == undefined) { - throw new Error(`unexpected "undefined" for byValue`); - } entry.byValues.set(byValue, obj[key]); if (byValue === "default") { for (const otherByValue of Object.keys(byObj)) { diff --git a/packages/rspack/src/util/createHash.ts b/packages/rspack/src/util/createHash.ts index 7e7aa984ffa0..0559b3601128 100644 --- a/packages/rspack/src/util/createHash.ts +++ b/packages/rspack/src/util/createHash.ts @@ -27,8 +27,8 @@ class BulkUpdateDecorator extends Hash { buffer: string; /** - * @param {Hash | function(): Hash} hashOrFactory function to create a hash - * @param {string=} hashKey key for caching + * @param hashOrFactory function to create a hash + * @param hashKey key for caching */ constructor(hashOrFactory: Hash | (() => Hash), hashKey?: string) { super(); @@ -45,9 +45,9 @@ class BulkUpdateDecorator extends Hash { /** * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding} - * @param {string|Buffer} data data - * @param {string=} inputEncoding data encoding - * @returns {this} updated hash + * @param data data + * @param inputEncoding data encoding + * @returns updated hash */ update(data: string | Buffer, inputEncoding?: string): this { if ( @@ -74,8 +74,8 @@ class BulkUpdateDecorator extends Hash { /** * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding} - * @param {string=} encoding encoding of the return value - * @returns {string|Buffer} digest + * @param encoding encoding of the return value + * @returns digest */ digest(encoding?: string): string | Buffer { let digestCache: Map | undefined; @@ -115,11 +115,11 @@ class DebugHash extends Hash { /** * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding} - * @param {string|Buffer} data data - * @param {string=} inputEncoding data encoding - * @returns {this} updated hash + * @param data data + * @param _inputEncoding data encoding + * @returns updated hash */ - update(data: string | Buffer, inputEncoding?: string) { + update(data: string | Buffer, _inputEncoding?: string): this { if (typeof data !== "string") data = data.toString("utf-8"); if (data.startsWith("debug-digest-")) { data = Buffer.from(data.slice("debug-digest-".length), "hex").toString(); @@ -130,8 +130,8 @@ class DebugHash extends Hash { /** * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding} - * @param {string=} encoding encoding of the return value - * @returns {string|Buffer} digest + * @param encoding encoding of the return value + * @returns digest */ digest(encoding?: BufferEncoding) { return ( @@ -142,8 +142,8 @@ class DebugHash extends Hash { /** * Creates a hash by name or function - * @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash - * @returns {Hash} the hash + * @param algorithm the algorithm name or a constructor creating a hash + * @returns the hash */ export const createHash = ( algorithm: