You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.5 KiB

3 months ago
  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;