EnvironmentNotSupportAsyncWarning.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Gengkun He @ahabhgk
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. const makeSerializable = require("./util/makeSerializable");
  8. /** @typedef {import("./Module")} Module */
  9. /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
  10. /** @typedef {"asyncWebAssembly" | "topLevelAwait" | "external promise" | "external script" | "external import" | "external module"} Feature */
  11. class EnvironmentNotSupportAsyncWarning extends WebpackError {
  12. /**
  13. * Creates an instance of EnvironmentNotSupportAsyncWarning.
  14. * @param {Module} module module
  15. * @param {Feature} feature feature
  16. */
  17. constructor(module, feature) {
  18. const message = `The generated code contains 'async/await' because this module is using "${feature}".
  19. However, your target environment does not appear to support 'async/await'.
  20. As a result, the code may not run as expected or may cause runtime errors.`;
  21. super(message);
  22. /** @type {string} */
  23. this.name = "EnvironmentNotSupportAsyncWarning";
  24. /** @type {Module} */
  25. this.module = module;
  26. }
  27. /**
  28. * Creates an instance of EnvironmentNotSupportAsyncWarning.
  29. * @param {Module} module module
  30. * @param {RuntimeTemplate} runtimeTemplate compilation
  31. * @param {Feature} feature feature
  32. */
  33. static check(module, runtimeTemplate, feature) {
  34. if (!runtimeTemplate.supportsAsyncFunction()) {
  35. module.addWarning(new EnvironmentNotSupportAsyncWarning(module, feature));
  36. }
  37. }
  38. }
  39. makeSerializable(
  40. EnvironmentNotSupportAsyncWarning,
  41. "webpack/lib/EnvironmentNotSupportAsyncWarning"
  42. );
  43. module.exports = EnvironmentNotSupportAsyncWarning;