WebAssemblyExportImportedDependency.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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").ReferencedExports} ReferencedExports */
  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. * Creates an instance of WebAssemblyExportImportedDependency.
  18. * @param {string} exportName export name
  19. * @param {string} request request
  20. * @param {string} name name
  21. * @param {string} valueType value type
  22. */
  23. constructor(exportName, request, name, valueType) {
  24. super(request);
  25. /** @type {string} */
  26. this.exportName = exportName;
  27. /** @type {string} */
  28. this.name = name;
  29. /** @type {string} */
  30. this.valueType = valueType;
  31. }
  32. /**
  33. * Could affect referencing module.
  34. * @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
  35. */
  36. couldAffectReferencingModule() {
  37. return Dependency.TRANSITIVE;
  38. }
  39. /**
  40. * Returns list of exports referenced by this dependency
  41. * @param {ModuleGraph} moduleGraph module graph
  42. * @param {RuntimeSpec} runtime the runtime for which the module is analysed
  43. * @returns {ReferencedExports} referenced exports
  44. */
  45. getReferencedExports(moduleGraph, runtime) {
  46. return [[this.name]];
  47. }
  48. get type() {
  49. return "wasm export import";
  50. }
  51. get category() {
  52. return "wasm";
  53. }
  54. /**
  55. * Serializes this instance into the provided serializer context.
  56. * @param {ObjectSerializerContext} context context
  57. */
  58. serialize(context) {
  59. const { write } = context;
  60. write(this.exportName);
  61. write(this.name);
  62. write(this.valueType);
  63. super.serialize(context);
  64. }
  65. /**
  66. * Restores this instance from the provided deserializer context.
  67. * @param {ObjectDeserializerContext} context context
  68. */
  69. deserialize(context) {
  70. const { read } = context;
  71. this.exportName = read();
  72. this.name = read();
  73. this.valueType = read();
  74. super.deserialize(context);
  75. }
  76. }
  77. makeSerializable(
  78. WebAssemblyExportImportedDependency,
  79. "webpack/lib/dependencies/WebAssemblyExportImportedDependency"
  80. );
  81. module.exports = WebAssemblyExportImportedDependency;