WebAssemblyImportDependency.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DependencyReference = require("./DependencyReference");
  7. const ModuleDependency = require("./ModuleDependency");
  8. const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError");
  9. class WebAssemblyImportDependency extends ModuleDependency {
  10. constructor(request, name, description, onlyDirectImport) {
  11. super(request);
  12. /** @type {string} */
  13. this.name = name;
  14. /** @type {TODO} */
  15. this.description = description;
  16. /** @type {false | string} */
  17. this.onlyDirectImport = onlyDirectImport;
  18. }
  19. getReference() {
  20. if (!this.module) return null;
  21. return new DependencyReference(this.module, [this.name], false);
  22. }
  23. getErrors() {
  24. if (
  25. this.onlyDirectImport &&
  26. this.module &&
  27. !this.module.type.startsWith("webassembly")
  28. ) {
  29. return [
  30. new UnsupportedWebAssemblyFeatureError(
  31. `Import "${this.name}" from "${this.request}" with ${
  32. this.onlyDirectImport
  33. } can only be used for direct wasm to wasm dependencies`
  34. )
  35. ];
  36. }
  37. }
  38. get type() {
  39. return "wasm import";
  40. }
  41. }
  42. module.exports = WebAssemblyImportDependency;