WebAssemblyExportImportedDependency.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Dependency = require("../Dependency");
  7. const makeSerializable = require("../util/makeSerializable");
  8. const ModuleDependency = require("./ModuleDependency");
  9. /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
  10. /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
  11. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  12. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  13. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  14. /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
  15. class WebAssemblyExportImportedDependency extends ModuleDependency {
  16. /**
  17. * @param {string} exportName export name
  18. * @param {string} request request
  19. * @param {string} name name
  20. * @param {TODO} valueType value type
  21. */
  22. constructor(exportName, request, name, valueType) {
  23. super(request);
  24. /** @type {string} */
  25. this.exportName = exportName;
  26. /** @type {string} */
  27. this.name = name;
  28. /** @type {string} */
  29. this.valueType = valueType;
  30. }
  31. /**
  32. * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
  33. */
  34. couldAffectReferencingModule() {
  35. return Dependency.TRANSITIVE;
  36. }
  37. /**
  38. * Returns list of exports referenced by this dependency
  39. * @param {ModuleGraph} moduleGraph module graph
  40. * @param {RuntimeSpec} runtime the runtime for which the module is analysed
  41. * @returns {(string[] | ReferencedExport)[]} referenced exports
  42. */
  43. getReferencedExports(moduleGraph, runtime) {
  44. return [[this.name]];
  45. }
  46. get type() {
  47. return "wasm export import";
  48. }
  49. get category() {
  50. return "wasm";
  51. }
  52. /**
  53. * @param {ObjectSerializerContext} context context
  54. */
  55. serialize(context) {
  56. const { write } = context;
  57. write(this.exportName);
  58. write(this.name);
  59. write(this.valueType);
  60. super.serialize(context);
  61. }
  62. /**
  63. * @param {ObjectDeserializerContext} context context
  64. */
  65. deserialize(context) {
  66. const { read } = context;
  67. this.exportName = read();
  68. this.name = read();
  69. this.valueType = read();
  70. super.deserialize(context);
  71. }
  72. }
  73. makeSerializable(
  74. WebAssemblyExportImportedDependency,
  75. "webpack/lib/dependencies/WebAssemblyExportImportedDependency"
  76. );
  77. module.exports = WebAssemblyExportImportedDependency;