WebAssemblyExportImportedDependency.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /** @import { ReferencedExports, TRANSITIVE } from "../Dependency" */
  10. /** @import ModuleGraph from "../ModuleGraph" */
  11. /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, string, string]>} ObjectDeserializerContext */
  12. /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, string, string]>} ObjectSerializerContext */
  13. /** @import { RuntimeSpec } from "../util/runtime" */
  14. class WebAssemblyExportImportedDependency extends ModuleDependency {
  15. /**
  16. * Creates an instance of WebAssemblyExportImportedDependency.
  17. * @param {string} exportName export name
  18. * @param {string} request request
  19. * @param {string} name name
  20. * @param {string} 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. * Could affect referencing module.
  33. * @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
  34. */
  35. couldAffectReferencingModule() {
  36. return Dependency.TRANSITIVE;
  37. }
  38. /**
  39. * Returns list of exports referenced by this dependency
  40. * @param {ModuleGraph} moduleGraph module graph
  41. * @param {RuntimeSpec} runtime the runtime for which the module is analysed
  42. * @returns {ReferencedExports} referenced exports
  43. */
  44. getReferencedExports(moduleGraph, runtime) {
  45. // re-exporting wasm glue needs the real binding, never an inlined literal
  46. return [{ name: [this.name], canInline: false }];
  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. context.write(this.exportName).write(this.name).write(this.valueType);
  60. super.serialize(context);
  61. }
  62. /**
  63. * Restores this instance from the provided deserializer context.
  64. * @param {ObjectDeserializerContext} context context
  65. */
  66. deserialize(context) {
  67. this.exportName = context.read();
  68. const c1 = context.rest;
  69. this.name = c1.read();
  70. const c2 = c1.rest;
  71. this.valueType = c2.read();
  72. super.deserialize(c2.rest);
  73. }
  74. }
  75. makeSerializable(
  76. WebAssemblyExportImportedDependency,
  77. "webpack/lib/dependencies/WebAssemblyExportImportedDependency"
  78. );
  79. module.exports = WebAssemblyExportImportedDependency;