isGeneratorLowered.js 981 B

1234567891011121314151617181920212223242526
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @import Module from "../Module" */
  6. /** @import ModuleGraph from "../ModuleGraph" */
  7. /** @import RuntimeTemplate from "../RuntimeTemplate" */
  8. /**
  9. * Whether an async module is lowered to a generator: the target has no
  10. * `async`/`await` but supports generators, and the module contains no
  11. * top-level `for await…of` or `await using` (which generators can't express).
  12. * @param {Module} module module
  13. * @param {ModuleGraph} moduleGraph module graph
  14. * @param {RuntimeTemplate} runtimeTemplate runtime template
  15. * @returns {boolean} true when the module should be emitted as a generator
  16. */
  17. const isGeneratorLowered = (module, moduleGraph, runtimeTemplate) =>
  18. moduleGraph.isAsync(module) &&
  19. !runtimeTemplate.supportsAsyncFunction() &&
  20. Boolean(runtimeTemplate.supportsGenerator()) &&
  21. !(module.buildInfo && module.buildInfo.usesTopLevelAwaitForOf);
  22. module.exports = isGeneratorLowered;