AsyncWebAssemblyGenerator.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Generator = require("../Generator");
  7. /** @typedef {import("webpack-sources").Source} Source */
  8. /** @typedef {import("../Generator").GenerateContext} GenerateContext */
  9. /** @typedef {import("../NormalModule")} NormalModule */
  10. const TYPES = new Set(["webassembly"]);
  11. /**
  12. * @typedef {object} AsyncWebAssemblyGeneratorOptions
  13. * @property {boolean} [mangleImports] mangle imports
  14. */
  15. class AsyncWebAssemblyGenerator extends Generator {
  16. /**
  17. * @param {AsyncWebAssemblyGeneratorOptions} options options
  18. */
  19. constructor(options) {
  20. super();
  21. this.options = options;
  22. }
  23. /**
  24. * @param {NormalModule} module fresh module
  25. * @returns {Set<string>} available types (do not mutate)
  26. */
  27. getTypes(module) {
  28. return TYPES;
  29. }
  30. /**
  31. * @param {NormalModule} module the module
  32. * @param {string=} type source type
  33. * @returns {number} estimate size of the module
  34. */
  35. getSize(module, type) {
  36. const originalSource = module.originalSource();
  37. if (!originalSource) {
  38. return 0;
  39. }
  40. return originalSource.size();
  41. }
  42. /**
  43. * @param {NormalModule} module module for which the code should be generated
  44. * @param {GenerateContext} generateContext context for generate
  45. * @returns {Source} generated code
  46. */
  47. generate(module, generateContext) {
  48. return /** @type {Source} */ (module.originalSource());
  49. }
  50. }
  51. module.exports = AsyncWebAssemblyGenerator;