AsyncWebAssemblyGenerator.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. class AsyncWebAssemblyGenerator extends Generator {
  12. constructor(options) {
  13. super();
  14. this.options = options;
  15. }
  16. /**
  17. * @param {NormalModule} module fresh module
  18. * @returns {Set<string>} available types (do not mutate)
  19. */
  20. getTypes(module) {
  21. return TYPES;
  22. }
  23. /**
  24. * @param {NormalModule} module the module
  25. * @param {string=} type source type
  26. * @returns {number} estimate size of the module
  27. */
  28. getSize(module, type) {
  29. const originalSource = module.originalSource();
  30. if (!originalSource) {
  31. return 0;
  32. }
  33. return originalSource.size();
  34. }
  35. /**
  36. * @param {NormalModule} module module for which the code should be generated
  37. * @param {GenerateContext} generateContext context for generate
  38. * @returns {Source} generated code
  39. */
  40. generate(module, generateContext) {
  41. return module.originalSource();
  42. }
  43. }
  44. module.exports = AsyncWebAssemblyGenerator;