WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/util/hash/BatchedHash.js
@@ -6,18 +6,24 @@
"use strict";
const Hash = require("../Hash");
const { digest, update } = require("./hash-digest");
/** @type {number} */
const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
class BatchedHash extends Hash {
   /**
    * Creates an instance of BatchedHash.
    * @param {Hash} hash hash
    */
   constructor(hash) {
      super();
      /** @type {undefined | string} */
      this.string = undefined;
      /** @type {undefined | Encoding} */
      this.encoding = undefined;
      /** @type {Hash} */
      this.hash = hash;
   }
@@ -51,9 +57,9 @@
            return this;
         }
         if (this.encoding) {
            this.hash.update(this.string, this.encoding);
            update(this.hash, this.string, this.encoding);
         } else {
            this.hash.update(this.string);
            update(this.hash, this.string);
         }
         this.string = undefined;
      }
@@ -66,12 +72,12 @@
            this.string = data;
            this.encoding = inputEncoding;
         } else if (inputEncoding) {
            this.hash.update(data, inputEncoding);
            update(this.hash, data, inputEncoding);
         } else {
            this.hash.update(data);
            update(this.hash, data);
         }
      } else {
         this.hash.update(data);
         update(this.hash, data);
      }
      return this;
   }
@@ -95,15 +101,15 @@
   digest(encoding) {
      if (this.string !== undefined) {
         if (this.encoding) {
            this.hash.update(this.string, this.encoding);
            update(this.hash, this.string, this.encoding);
         } else {
            this.hash.update(this.string);
            update(this.hash, this.string);
         }
      }
      if (!encoding) {
         return this.hash.digest();
         return digest(this.hash);
      }
      return this.hash.digest(encoding);
      return digest(this.hash, encoding);
   }
}