GetFullHashRuntimeModule.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const RuntimeModule = require("../RuntimeModule");
  7. /** @import Compilation from "../Compilation" */
  8. class GetFullHashRuntimeModule extends RuntimeModule {
  9. constructor() {
  10. super("getFullHash");
  11. /** @type {boolean} */
  12. this.fullHash = true;
  13. }
  14. /**
  15. * Returns true, if the runtime module should get it's own scope.
  16. * When false, `generate()` must emit complete statements ending with `;`
  17. * so a following runtime IIFE is not parsed as a call (ASI).
  18. * @returns {boolean} true, if the runtime module should get it's own scope
  19. */
  20. shouldIsolate() {
  21. return false;
  22. }
  23. /**
  24. * Generates runtime code for this runtime module.
  25. * @returns {string | null} runtime code
  26. */
  27. generate() {
  28. const compilation = /** @type {Compilation} */ (this.compilation);
  29. const { runtimeTemplate } = compilation;
  30. return `${RuntimeGlobals.getFullHash} = ${runtimeTemplate.returningFunction(
  31. JSON.stringify(compilation.hash || "XXXX")
  32. )};`;
  33. }
  34. }
  35. module.exports = GetFullHashRuntimeModule;